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);

void rtcout_int ()
{ char buf[5] = "    ";
  time_t now;
  struct tm *ts;

  epoque++; //this is a global volatile unsigned long variable that holds the number of seconds since the arduino epoque
void rtc_setCG(byte val)
{ Wire.beginTransmission(rtc_id);
{ byte nsecond;
  nsecond=(byte)((millis()/1000) % 60);
  if ( nsecond != second )
  { second=nsecond;
    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.

  • Comments are not for extended discussion; this conversation has been moved to chat. – Nick Gammon Apr 29 '17 at 7:52
  • Please edit your question to include a Minimal, Complete, and Verifiable example of code, not just snippets. Minimal means you've stripped away irrelevant stuff, just leaving what's needed to show the problem. Complete means all the library names are shown, all the variable declarations, and all the function definitions – so people don't have to waste time guessing what you did or what you meant. Verifiable means it can be compiled and tested, allowing other people to test their theories about the problem – user31481 Nov 16 '17 at 17:20
  • The full code and or snippets is not possible because I've since then worked around the problem by using the 1Hz from the RTC to do other stuff. – louigi600 Nov 17 '17 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.