Go Down

Topic: Detecting/Understanding interrupts (Read 446 times) previous topic - next topic

KirAsh4

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:
Code: [Select]
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.

HazardsMind

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.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

KirAsh4

#2
Jan 14, 2013, 10:01 pm Last Edit: Jan 14, 2013, 10:06 pm by KirAsh4 Reason: 1
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.

AWOL

#3
Jan 14, 2013, 10:05 pm Last Edit: Jan 14, 2013, 10:09 pm by AWOL Reason: 1
Mr Interrupt and Miss Delay are not best friends.

This is also straight from the reference page you quoted
Quote
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.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

HazardsMind

Quote
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?
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

retrolefty


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

KirAsh4

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.


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.

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. :)

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.

dhenry

Change your alarm() to this:

Code: [Select]

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


Go Up