1

I'm trying to figure out how to use an RTC to send interrupts to my arduino. I'm using a DS3232. I can get an 'edge' interrupt, with the following toy code (I know the code is silly, it's just a short example to test if I have actually set the RTC to send the interrupt, and that the Arduino receives it):

/*----------------------------------------------------------------------*
 * Minimal example of setting a recurring alarm with the DS3232 RTC     *
 * Attach an LED to pin 7, which will flash when the alarm fires.       *
 *                                                                      * 
 * Attach the RTC SQ/INT pin to Uno pin 2, with a 10K pull-up to VCC.   *
 * Ard pin A4 -> RTC SDA, Ard A5 -> RTC SCL, 5v -> vcc, GND -> GND      *
 *----------------------------------------------------------------------*/ 

#include <DS3232RTC.h>        //http://github.com/JChristensen/DS3232RTC
#include <Time.h>             //http://playground.arduino.cc/Code/Time
#include <Wire.h>             //http://arduino.cc/en/Reference/Wire

#define WAKE_PIN 2
#define LED_PIN 7

void setup(void)
{
    pinMode(LED_PIN, OUTPUT);

    // RTC config:
    RTC.squareWave(SQWAVE_NONE);
    pinMode(WAKE_PIN, INPUT_PULLUP);
    attachInterrupt(INT0, wakeUp, FALLING);
    RTC.setAlarm(ALM2_EVERY_MINUTE, 0, 0, 0, 1);
    RTC.alarm(ALARM_2);
    RTC.alarmInterrupt(ALARM_2, true);
}

void loop(void)
{
  if(RTC.alarm(ALARM_2)){
    digitalWrite(LED_PIN, HIGH);
    delay(5000);
    digitalWrite(LED_PIN, LOW);
  }

}

void wakeUp (){
// no-op, just checking if the interrupt fired
}

Why doesn't this work if I set the interupt to "LOW", ie., attachInterrupt(INT0, wakeUp, LOW);?

The reason I ask is I'm trying to use an RTC to wake from low power mode, and I think this doesn't work with a 'falling' interrupt.

  • 1
    So when you use LOW, the LED doesn't blink at all? Have u tried detaching the interrupt in the ISR and re-attaching in the IF block, to prevent multiple firings while the pin is low? Do you have any idea how long the pin remains low before going high again? Perhaps the arduino is too slow to respond – SoreDakeNoKoto Jan 17 '16 at 23:10
  • Yes, with LOW the LED does not blink ever. I have tried detaching the ISR and reattaching it without success. However, I've determined that the problem I have been fighting the last hour was due to placing the ISR definition after the loop function - which isn't supposed to matter. I'll update to the latest IDE and see how much of my problem is due to using an old and buggy IDE :/ – Tyler Jan 18 '16 at 2:48
2

That page is incorrect, although it reflects what the datasheet says.

The processor can be woken from RISING/FALLING/CHANGE/LOW. I queried this with Atmel and got this response:

Commented by Manoraj Gnanadhas (Atmel)

2015-01-20 06:23:36 GMT

[Recipients: Nick Gammon]

Hello Nick,

Our design team has confirmed that “Note-3 mentioned under Table 10-1” is a datasheet bug. So you can use any type of interrupt (Rising edge/ Falling edge / Low level / Any logical change) to wake up from sleep mode. Sorry for the inconvenience caused.

Best Regards,

Manoraj Gnanadhas

This is mentioned on my page about interrupts.


Why does LOW hang the processor? The LOW interrupt is not an edge interrupt but a continuous one. Thus, while the signal is LOW the interrupt is being continually called, with only one processor instruction being executed after each call to the ISR (which itself takes around 5.125 µs). So, the ISR is not being interrupted, but effectively only one instruction of your code is being executed every 5.125 µs (probably about 1/40th of the usual speed).


and see how much of my problem is due to using an old and buggy IDE

It's nothing to do with the IDE. Change to a FALLING interrupt and your problems should go away. You may also want to clear the interrupt flag (as documented on my page) in case the interrupt event has already happened before you go to sleep. Specifically:

EIFR = bit (INTF0);  // clear flag for interrupt 0
| improve this answer | |
  • Thanks Nick. I have managed to get a cut-down excerpt of your data logger code working, using the WDT interrupt. I'm going to need to study this further - I have a few different sources like yours that I can get running as-is, but any modifications I try break them quickly! Clearly more study on my part is needed. – Tyler Jan 20 '16 at 2:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.