Detecting/Understanding interrupts

On to the next step, interrupts. So I'm using a DS3231M which will pull its interrupt pin low when an alarm triggers. It requires an external pull-up to VCC to work properly. So in my code, I have this:

void setup() {
  attachInterrupt(0, alarm, FALLING);
}

void alarm() {
  digitalWrite(ledPin, HIGH);
  delay(50);
  digitalWrite(ledPin, LOW);
}

Yes, I know I should not be using a delay, but this is just for testing purposes. Eventually it will get removed once I figure out why this is failing. Basically I get one single blink, and that's it. I have the RTC set to trigger its alarm every second, and I can verify that it's pulling that interrupt pin low each time. So why do I only get one blink upon powerup and nothing else after that?

If I change the attachInterrupt to trigger on CHANGE instead, same thing: one single blink.

Ok this will not go to your function until your add () to alarm. Also I think the interupt pins to use are 2 and 3, not 0.

No, that's int.0. I've taken the code straight from here http://arduino.cc/en/Reference/AttachInterrupt

And I can read the trigger, it just seems to only do it once though. Even though the module itself is pulling its pin low with every alarm. So my guess is it's in the code.

Mr Interrupt and Miss Delay are not best friends.

This is also straight from the reference page you quoted

Note
Inside the attached function, delay() won't work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function.

it just seems to only do it once though.

Did you try to put it in loop(), where it will continuously loop and not setup(), where it will only happen once?

KirAsh4:
No, that's int.0. I've taken the code straight from here http://arduino.cc/en/Reference/AttachInterrupt

And I can read the trigger, it just seems to only do it once though. Even though the module itself is pulling its pin low with every alarm. So my guess is it's in the code.

On a 328p based arduino board, user interrupt 0 is wired to arduino pin 2 and user interrupt 1 is wired to arduino pin 3. So is your clock alarm wired to pin 2? You state the need to pull-up the alarm signal, so are you doing that with an external resistor, as there is no code in the setup to enable the internal pull-up for pin 2?

Lefty

Figured it out. There was an errand 'turnOffAlarm()' in my code that I had forgotten about. So even though the RTC is set to trigger every second, if the alarm itself got shut off, it will continue to fire the alarm bits, but it won't trigger it's interrupt.

retrolefty:
On a 328p based arduino board, user interrupt 0 is wired to arduino pin 2 and user interrupt 1 is wired to arduino pin 3. So is your clock alarm wired to pin 2?

Yessir, otherwise I would never see the initial blink to begin with.

retrolefty:
You state the need to pull-up the alarm signal, so are you doing that with an external resistor, as there is no code in the setup to enable the internal pull-up for pin 2?

Pull-up on the interrupt, yes. And the resistor is there, yep.

This was all in the code Hardware was fine. Got it sorted out. Sometimes it helps to walk away, have a shot of whiskey, then look over the code again. I don't know if the walking away or the whiskey shot is what made it happen. :slight_smile:

Now I have to try using both alarms and see if I can make Alarm 1 turn it on, and Alarm 2 turn it off.

Change your alarm() to this:

void alarm(void) {
  digitalWrite(ledPin, !digitalRead(ledPin)); //flip led pin
}