Arduino wakeup WDT interrupt

How do you go about setting a WDT interrupt that will wake up an arduino from power down?

Can find an example of setting an pin level/change interrupt to wake up an arduino.

Can find an example of setting a WDT timer so that it will reset the Arduino.

But no examples of setting up the WDT to trigger an interrupt.

How do you go about setting a WDT interrupt that will wake up an arduino from power down?

I'd be surprised if you could.

To enable the watchdog timer to wake up an ATmega328 from POWER_SAVE sleep mode, I use the following initialization sequence. You will also need an empty interrupt routine to process the interrupt.

set_sleep_mode(SLEEP_MODE_PWR_SAVE);

 // clear various "reset" flags
 MCUSR = 0;
 // allow changes, disable reset
 WDTCSR = (1<<WDCE) | (1<<WDE);
 // set interrupt mode and an interval
 WDTCSR = (1<<WDIE) | (1<<WDP2) | (1<<WDP0); // set WDIE, and 1/2 second timeout
 wdt_reset(); // reset it

The main loop has this code:

		sleep_enable();
		cli(); //time critical steps follow
		MCUCR = (1<<BODS) | (1<<BODSE);	// turn on brown-out enable select
		MCUCR = (1<<BODS);        		//Brown out off. This must be done within 4 clock cycles of above
		sei();
		sleep_cpu();

jremington:
To enable the watchdog timer to wake up an ATmega328 from POWER_SAVE sleep mode, I use the following initialization sequence. You will also need an empty interrupt routine to process the interrupt.

set_sleep_mode(SLEEP_MODE_PWR_SAVE);

// clear various “reset” flags
MCUSR = 0;
// allow changes, disable reset
WDTCSR = (1<<WDCE) | (1<<WDE);
// set interrupt mode and an interval
WDTCSR = (1<<WDIE) | (1<<WDP2) | (1<<WDP0); // set WDIE, and 1/2 second timeout
wdt_reset(); // reset it




The main loop has this code:


  sleep_enable();
	cli(); //time critical steps follow
	MCUCR = (1<<BODS) | (1<<BODSE);	// turn on brown-out enable select
	MCUCR = (1<<BODS);        		//Brown out off. This must be done within 4 clock cycles of above
	sei();
	sleep_cpu();

Does this code also work for and ATmega1280?

I tried this code to put the mega to sleep and it works nicely - my loop() function stops running.

void CPowerManager::powerDown()
{
	for (uint8_t nI = 0; nI < m_nNumDevices; nI++)
		m_arrayDevices[nI]->turnOff();

	// Sleep mode is set here
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);

	// Enables the sleep bit in the mcucr register so sleep is possible - just a safety pin 
	sleep_enable();

	pinMode(m_nTimerWakeupPin, INPUT_PULLUP);
	attachInterrupt(digitalPinToInterrupt(m_nTimerWakeupPin), m_pTimerWakeupISR, CHANGE);
	pinMode(m_nManualWakeupPin, INPUT_PULLUP);
	attachInterrupt(digitalPinToInterrupt(m_nManualWakeupPin), m_pManualWakeupISR, CHANGE);
	
	// Here the device is actually put to sleep!!
	sleep_mode();
	
	// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
	
	// First thing after waking from sleep:
	sleep_disable();
	detachInterrupt(digitalPinToInterrupt(m_nTimerWakeupPin));
	detachInterrupt(digitalPinToInterrupt(m_nManualWakeupPin));

	// WAKEUP CODE HERE
	if (m_eWakeupType == eAutoWakeup)
	{
    debug.log(F("********** AUTO WAKEUP **********"));
	}
	else if (m_eWakeupType == eManualWakeup)
	{
    debug.log(F("********** MANUAL WAKEUP **********"));
		for (uint8_t nI = 0; nI < m_nNumDevices; nI++)
			m_arrayDevices[nI]->turnOn();
	}
}

But why doesn’t touching either pin 2 or 3 with GND wake the mega up?
It just remains inactive until I reset it.

If I were in your shoes, I would study the ATmega1280 data sheet.