Hello all... I am attempting to use the Sparkfun DS1307 sqw output as an interrupt to ensure that some timers are checked once a minute. I have it working, however the I am getting multiple reads on the interrupt pin. Here is the applicable code
#include <Wire.h>
#include <DS1307RTC.h>
#include <Time.h>
volatile boolean sqwinterrupt = false;
void setup() {
pinMode(3, INPUT_PULLUP); // Used as interrupt pin for DS1307 sqw output @ 1Hz
// This sets the sqw of the ds1307 to 1Hz, used as interrupt to check the times to see if outputs need updating
Wire.begin();
Wire.beginTransmission(0x68);
Wire.write(0x07); // Goto the sqw register
Wire.write(0x10); // binary B00010000 sets sqwenable to 1 and rs0 and rs1 to 0
Wire.endTransmission();
attachInterrupt(1, sqwInterrupt, FALLING);
}
void loop() {
t = now();
if (sqwinterrupt == true) {
Serial.print("Sqw:");
Serial.print(hour(t));
Serial.print(":");
Serial.print(minute(t));
Serial.print(":");
Serial.println(second(t));
sqwinterrupt = false;
if (second(t) == 0) { // Only need to check the timers once a minute
checkTimers();
Serial.print("Timers checked at: ");
Serial.print(hour(t));
Serial.print(":");
Serial.print(minute(t));
Serial.print(":");
Serial.println(second(t));
}
}
/*************************
*** sqwInterrupt() ****
*************************/
void sqwInterrupt() {
sqwinterrupt = true;
}
This gives me an output like so:
Sqw:21:46:57
Sqw:21:46:57
Sqw:21:46:57
Sqw:21:46:57
Sqw:21:46:58
Sqw:21:46:58
Sqw:21:46:58
Sqw:21:46:58
Sqw:21:46:58
Sqw:21:46:59
Sqw:21:46:59
Sqw:21:46:59
Sqw:21:46:59
Sqw:21:47:0
Timers checked at: 21:47:0
Sqw:21:47:0
Timers checked at: 21:47:0
Sqw:21:47:0
Timers checked at: 21:47:0
Sqw:21:47:0
Timers checked at: 21:47:0
Sqw:21:47:0
Timers checked at: 21:47:0
Sqw:21:47:1
Sqw:21:47:1
Sqw:21:47:1
Sqw:21:47:1
Sqw:21:47:1
Sqw:21:47:2
Sqw:21:47:2
Sqw:21:47:2
Sqw:21:47:2
Sqw:21:47:2
Sqw:21:47:3
Sqw:21:47:3
Sqw:21:47:3
Any ideas on why this might be? I guess I could use a flag to check that the once the timers are checked to skip until the 1 second mark... but that seems unnecessary
Any help would be appreciated and thanks in advance!