Everything works with my seeduino Stalker board but I can’t seem to wake up from an Interrupt. I have soldered the bottom of the stalker board (INT to PD2) but the library I have found does not seem to trigger the wakeup signal I need.
Here is the .h file:
* Sleep for <tt>seconds</tt> seconds for <tt>RTC.now()</tt>.
void sleepFor(int seconds);
* Sleep every <tt>seconds</tt> seconds since last wake up.
* This is most likely the methods you'll use if you need to wake up precisely every <tt>seconds</tt> seconds.
void sleepEvery(int seconds);
* Sleep until the specified <tt>date</tt> DateTime.
void sleepUntil(DateTime date);
//The following code is taken from sleep.h as Arduino Software v22 (avrgcc), in w32 does not have the latest sleep.h file
#define sleep_bod_disable() \
uint8_t tempreg; \
__asm__ __volatile__("in %[tempreg], %[mcucr]" "\n\t" \
"ori %[tempreg], %[bods_bodse]" "\n\t" \
"out %[mcucr], %[tempreg]" "\n\t" \
"andi %[tempreg], %[not_bodse]" "\n\t" \
"out %[mcucr], %[tempreg]" \
: [tempreg] "=&d" (tempreg) \
: [mcucr] "I" _SFR_IO_ADDR(MCUCR), \
[bods_bodse] "i" (_BV(BODS) | _BV(BODSE)), \
[not_bodse] "i" (~_BV(BODSE))); \
And here is the .cpp file:
// Interrupt service routine for external interrupt on INT0 pin conntected to DS3231 /INT
//Keep this as short as possible. Possibly avoid using function calls
// Initialize INT0 pin for accepting interrupts
PORTD |= 0x04;
DDRD &=~ 0x04;
lastWakeup = RTC.now();
void Power::sleepFor(int seconds)
sleepUntil(DateTime(RTC.now().get() + seconds));
void Power::sleepEvery(int seconds)
sleepUntil(DateTime(lastWakeup.get() + seconds));
void Power::sleepUntil(DateTime wakeupTime)
RTC.clearINTStatus(); //This function call is a must to bring /INT pin HIGH after an interrupt.
RTC.enableInterrupts(wakeupTime.hour(), wakeupTime.minute(), wakeupTime.second()); // set the interrupt at (h,m,s)
attachInterrupt(0, INT0_ISR, LOW); //Enable INT0 interrupt (as ISR disables interrupt). This strategy is required to handle LEVEL triggered interrupt
// Power Down routines
sleep_enable(); // Set sleep enable bit
sleep_bod_disable(); // Disable brown out detection during sleep. Saves more power
delay(10); // This delay is required to allow print to complete
// Shut down all peripherals like ADC before sleep. Refer Atmega328 manual
power_all_disable(); // This shuts down ADC, TWI, SPI, Timers and USART
sleep_cpu(); // Sleep the CPU as per the mode set earlier(power down)
sleep_disable(); // Wakes up sleep and clears enable bit. Before this ISR would have executed
power_all_enable(); // This shuts enables ADC, TWI, SPI, Timers and USART
lastWakeup = RTC.now();
delay(10); // This delay is required to allow CPU to stabilize
I am trying to use a command “power.sleepFor(5);” so that the board sleeps for 5 seconds and then wakes up. The board sleeps but never wakes up. Has anyone had any luck using the RTC on a stalker board to wake it up from an interrupt?