Standalone 328p and watchdog reset


Hi have a standalone 328p running at 8Mhz that i program with arduino as ISP
I set a watchdog interrupt each second, and after 10 seconds it resets the device.
The problem is after reset, it enters a infinite loop.

I already put wdt_disable(); at setup() to give time to start, but didn’t solve.

I read about a bug on bootloader, but i’m using a bare 328p, not a board

Below is code i use. Any ideas?

void watchdogEnable() {
 cli();                              // disable interrupts
 MCUSR = 0;                          // reset status register flags                                                                         
 WDTCSR |= 0b00011000;               // Set WDCE and WDE:                                 
 WDTCSR =  0b01000000 | 0b000110;    // set WDIE, clr WDE, set delay to 1 sec
 sei(); 			     // re-enable interrupts

ISR(WDT_vect) {

 if (wdt_count < MaxHangs) {
	wdt_reset(); // start timer again (still in interrupt-only mode)
 } else {
   MCUSR = 0;                          // reset flags
   WDTCSR |= 0b00011000;               // Put timer in reset-only mode:
   WDTCSR =  0b00001000 | 0b000101;    // clr WDIE, set WDE, reset interval to 1s
  1. Post all your code.
  2. Don't do this in an ISR: Serial.println("Reseting...");
  3. Look at for some examples.

Well, according to this post, i have to clear WDRF bit at setup, doing wdt_disable(); is not enough:

this way it is working:

void setup() {
  MCUSR = MCUSR & B11110111;     // with this line it works