3

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

VE7JRO
2,51519 gold badges27 silver badges29 bronze badges
asked Apr 27, 2017 at 9:11
3
  • Comments are not for extended discussion; this conversation has been moved to chat. Commented Apr 29, 2017 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 Commented Nov 16, 2017 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. Commented Nov 17, 2017 at 14:56

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.