Hello, I have been struggling for 2 days to understand how my external PCINTs on port B and port C do work when the WDT is initialized and running, but NOT when the WDT is not initialized at all or stopped?
- I have an ATtiny1634 chip, tried already 3 of them and the same issue happens every time the WDT is switched off (so my initial suspicions that I somehow burnt the inputs @ the PCINT pins were discarded)
- I tried to use different pins (combinations of pins as I currently need 2 out of 3 which are free) on port B and port C: PB3 (pin 16 with PCINT11), PC0 (pin 15 with PCINT12), and PC2 (pin 13 with PCINT14) - the issue appears no matter the pins chosen
- @ the start of my code I define my inputs as usually, e.g.
#define INPUT_PIN_FROM_MC5_IMOB_SCK PINB3 #define INPUT_PIN_FROM_MC5_IMOB_RESTART PINC0
In the main()-function I enable the PCINTs; then if I initialize the WDT, my program later works as expected (PCINTs on port B or C react and the corresponding ISRs are executed); if I don't initialize the WDT, then PCINTs on port B or C do not react later and the ISRs are not executed ?? Before the endless while-loop I enable timer0 for CTC mode on pin PA5 (OC0B) to generate a square wave signal for my antenna to energize and read an RFID tag whose bits are received and read in @ pin PA6 where PCINT6 (PCINT0 group) is activated. In the endless loop I wait for a flag to be set, which happens within the PCINT0-ISR (this one always works, no matter the WDT is on or off !!)
int main ( void ) { <uart is initialized ...> <output pins are set ...> enablePCINTinterrupts (); initWDT (); // !! if WDT is on, PCINTs on port B and C work; if WDT is off, they don't ?? initTagSearching (); while ( 1 ) { if ( tagReadingComplete ) { tagReadingComplete = FALSE; <code to display tag ID ..., then program waits for inputs (HIGH level) on PCINT pins which is handled in the respective ISRs > } wdt_reset(); }
The functions look as follows:
void initWDT ( void ) { cli(); wdt_reset(); WDTCSR = ( 1 << WDE ) | ( 1 << WDP2 ) | ( 1 << WDP1 ) | ( 1 << WDP0 ); sei(); } void enablePCINTinterrupts ( void ) { cli(); GIMSK = ( 1 << PCIE2 ) | ( 1 << PCIE1 ); // enable PCINT group interrupts ( PCINT[17:12] && PCINT[11:8] ) PCMSK2 = ( 1 << PCINT12 ); // enable PCINT on pin 15/PC0 PCMSK1 = ( 1 << PCINT11 ); // enable PCINT on pin 16/PB3 sei(); }
So, basically if I initialize the WDT with my function
initWDT ();
PCINT1-ISR and PCINT2-ISR get executed; otherwise not.
Also, if I switch off the WDT with timed sequence after I have enabled it, then PCINT1-ISR and PCINT2-ISR do not work either.
int main ( void ) { ... initWDT (); initTagSearching (); stopWDT (); while ( 1 ) { ...
void stopWDT ( void ) { wdt_reset(); MCUSR &= ~ ( 1 << WDRF ); CCP = 0xd8; WDTCSR &= ~ ( ( 1 << WDE ) | ( 1 << WDP2 ) | ( 1 << WDP1 ) | ( 1 << WDP0 ) ) ; }
The fuses of ATtiny are set as follows:
- extended: 0xf5
- high: 0xdd
- low: 0xef
Could anybody help ? I still don't manage. Thanks in advance.