c - ATTiny20 Stuck in Reset Loop after Watchdog Reset -
i using interrupt reset attiny20. here relevant code:
int main(void) { ... // set interrupt reset button (pcint5) sreg |= 1<<7; // enable global interrupts gimsk |= 1<<pcie0; // enable pin change interrupt 0 (enables interrupts on pcint[7:0] pcmsk0 |= 1<<pcint5; // enable pcint5 (physical pin 8) interrupt ... } the interrupt-handling function:
isr(pcint0_vect) { if (!(button_1_port & 1<<button_1_pin)) // reset if button pushed { wdt_enable(wdto_2s); while(1){}; } } this works quite - when button pushed system freezes 2 seconds , resets... , promptly gets stuck in reset loop. bit of googling uncovered culprit: on newer chips watchdog timer left enabled (at shortest delay setting) after watchdog reset. following code meant remedy issue:
// disable watchdog on reset void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3"))); void wdt_init(void) { // mcusr = 0; // see below reason commenting line wdt_disable(); return; } *n.b. mcusr = 0 commented out because mcusr not exist on attiny20. have tried replacing sreg = 0 no avail.
even code in place, should disable watchdog timer, issue persists. flashing leds on device indicate program running through part of main() function before resets, putting wdt_disable(); @ top of main() has not helped either.
is there critical i'm missing re: attiny20? i've missed in datasheet? problem - , solution - seem obvious, i'm stumped. i'm using atmel studio 6.1.
// disable watchdog on reset void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3"))); void wdt_init(void) { // flag must cleared on attiny20 before wdt can disabled /***************/ /* rstflr = 0; */ /***************? wdt_disable(); return; }
Comments
Post a Comment