JChristensen / DS3232RTC

Arduino Library for Maxim Integrated DS3232 and DS3231 Real-Time Clocks
GNU General Public License v3.0
394 stars 137 forks source link

Using SqWav 1Hz to interrupt Arduino every second #33

Closed codemonkey09 closed 8 years ago

codemonkey09 commented 8 years ago

I am attempting to build an RTC using the DS3231. In my code i use the 1Hz square wave to interrupt the Arduino every second, and read the time from the 3231 over i2c every time the interrupt is received. The problem is that, I have noticed that my clock is drifting over time. So far, over 3 days (72hrs) the clock has sped up by around 2.5 seconds. I am unable to identify the source of the issue, but, based on your other comments i am guessing the 1Hz interrupt is not a general use-case. I feel like i am missing something here. Any help would be appreciated.

JChristensen commented 8 years ago

My first question is what is the source of this particular DS3231. Devices from eBay or other sketchy sellers may well be counterfeit and out of spec (or worse). I recommend only buying from reputable suppliers that can trace the supply chain back to the manufacturer. In fact I often use the 1Hz interrupt for timekeeping and it works just fine. Although I do it a little differently. I only read the time from the RTC once during initialization, then I increment it at each interrupt. Doing an I2C read every second is just unnecessary overhead.

codemonkey09 commented 8 years ago

yes, this part was bought off eBay. I can try another part from DigiKey. Thanks for the tip.