I've s 1Hz square wave coming from a DS1307 SQW/OUT pin going into pin2 on the Nano that is set up as input with internal pullup enabled. I've set up the interrupt on falling edge but I can't get the ISR to execute every second (it's not executing at all). If I wire up a button normally open to ground pin2 and I press and hold it down I can get the ISR to execute. Where's the problem:
- Is the DS1307 not grounding fast enough for the falling edge logic to pick it up ?
- Is the internal pullup resistance on pin2 too high for the square wave to be picked up (tension on pin2 is never high enough to trigger a falling/rising edge event) ?
- Is 1Hz too fast for the internal falling/rising edge logic to trigger the event ?
- Have I done something else wrong ?
- Is it a problem on the clone only ?
This is a snippet of the code to get an idea of what I'm trying to do:
void rtc_setCG(byte val);
const byte rtc_id = 0x68; //DS1307 i2c id: 0x68h, 104 dec, 150 octal, 1101000b
pinMode(2, INPUT_PULLUP);
attachInterrupt (digitalPinToInterrupt(2), rtcout_int, FALLING);</p>
void rtcout_int ()
{ char buf[5] = " ";
time_t now;
struct tm *ts;
wdt_reset();
noInterrupts();
epoque++; //this is a global volatile unsigned long variable that holds the number of seconds since the arduino epoque
interrupts();
}
void rtc_setCG(byte val)
{ Wire.beginTransmission(rtc_id);
Wire.write((byte)0x07);
Wire.write(val);
Wire.endTransmission();
}
ISR (TIMER1_COMPA_vect)
{ byte nsecond;
nsecond=(byte)((millis()/1000) % 60);
if ( nsecond != second )
{ second=nsecond;
epoque++;
minute=(byte)((epoque / 60) % 60);
hour=(byte)(((epoque / 3600) + timezone) % 24);
}
}
rtc_setCG(0x10); //this is how I set up the ds1307 to do 1hz on the SQW/OUT
I've put a speaker on the SQW/OUT and I can hear it click so the DS1307 is set up right for what I'm trying to do but I can't get the ISR to execute on the falling edge. I tried plying with rising edge or change but made no difference.