Pages: [1]   Go Down
Author Topic: Detecting/Understanding interrupts  (Read 392 times)
0 Members and 1 Guest are viewing this topic.
Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Queens, New York
Offline Offline
Faraday Member
**
Karma: 101
Posts: 3644
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 14, 2013, 04:06:17 pm by KirAsh4 » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26332
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 14, 2013, 04:09:53 pm by AWOL » Logged

"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.

Queens, New York
Offline Offline
Faraday Member
**
Karma: 101
Posts: 3644
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. smiley

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.
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Change your alarm() to this:

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

Pages: [1]   Go Up
Jump to: