AVR stops responding after Watchdog Timer Reset

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have an atMega1281 configured with a watchdog timer.  The AVR starts up fine and runs all code perfectly from a power up.  However, when I force a WDT Reset to initiate a software reset, the AVR resets  but randomly stops responding after the first few lines of code. It will never fully run after a reset. Can anyone point me in the right direction to correct the issue? Thanks

 

int main()
{
    wdt_init();
    sei();

 

    // initialization code here...This is where it hangs after a Reset but runs fine after power-up

 

    for(;;){
        if (flag==1)
        {
            my_wdt_reset();
            flag = 0;
        }
    }

}

 

void wdt_init() {
    MCUSR &= ~(1<<WDRF);
    WDTCSR = (1<<WDCE) | (1<<WDE);
    WDTCSR = 0x00;
    WDTCSR = (1<<WDIE) | (1<<WDP2) | (1<<WDP0);
}

ISR(WDT_vect)
{    

    wdt_counter++;
    if (wdt_counter > 255)
    {
        wdt_reset();
    } else {
        // Reset Dvice
        WDTCSR = (1<<WDCE) | (1<<WDE);
        WDTCSR = (1<<WDE) | (1<<WDP0);
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As you appear to be using avr-gcc have you considered:

 

http://www.nongnu.org/avr-libc/u...

 

If you do use that note in particular the paragraph that starts "Note that for newer...", the 1281 fits into the "newer" category here (because those words were written a long time ago!).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for the feedback. Yes I looked at the solution as well but I needed to handle the WDT a little different.  I started breaking down my code and isolated the issue to another routine that was causing the hang up. The WDT is actually working exactly like it should. When I removed the troublesome routine, the WDT reset every time as expected.

 

To be more specific, I had an modem that was not resetting properly when the AVR reset so the code was basically waiting on a response from the modem. The solution was to rewrite the routine to ensure the modem would reset and/or re-initialize on a system reset.