Go Down

Topic: SparkFun's Real Time clock Module (Read 850 times) previous topic - next topic


Hello all.

I know there are a few threads about this component, but I'm having some weirdness that I haven't seen mentioned elsewhere.

I'm using the Sparkfun Real Time Clock Module with an older (pre-NG) Arduino.  

With Wire.h, I'm able to communicate with the clock, set the time and read it, but after a few hours, the clock seems to go all crackers on me.  

Typically what I have observed is this : after running well for a few hours, at the change of a new hour (has happened at 12h, 14h, and 6h), the clock will jump to 2h, for no apparent reason.

I'm using code I found in the playground ( at http://www.arduino.cc/playground/Main/UsbMemory, relevant bit is near the bottom of the page):

Code: [Select]
#include <Wire.h>

int second = 0;    
int minute = 0;
int hour =0;
int day_of_week=0;
int day = 0;
int month = 0;
int year = 0;

void setup()


void loop()
 // reset register pointer

 // request 7 bytes from ds1307
 Wire.requestFrom(104, 7);    
 second = Wire.receive();      
 minute = Wire.receive();      
 hour = Wire.receive();        
 day = Wire.receive();        
 month = Wire.receive();      
 year = Wire.receive();  

 // Convert all the BCD values that might have "tens" to decimal
 int hours=hour/16* 10 + hour % 16;
 int minutes=minute/16 * 10 + minute % 16;
 int days=day/16 * 10 + day % 16;
 int months=month/16 * 10 + month % 16;

 Serial.print( hour );
 Serial.print( minutes );
 //no need to rush


I'm using pull-up resistors in there, the circuit is built as it ought be, yet the clock (actually 2 different ones) consistently gives me this problem.

Any ideas what is going on? Is it a code issue? A problem with using this older board? An issue with the clock modules (somehow I think that is unlikely)?

I have posted a similar topic at sparkfun in case it's a clock issue, but i have a feeling it's either in my code, or because of the older board.  I'll be testing out an NG this afternoon (no fancy Decimilia for me yet!), but curious if anyone has any insight into this.


I've got a similar module with similar problems.

When I set the time, it sets *a* time but not the time I was expecting.
I assume its just because I'm reading or writing it incorrectly. Your probably doing the same.

Double check the data sheet throughly.


Dec 11, 2007, 05:52 pm Last Edit: Dec 12, 2007, 11:44 am by droolcup Reason: 1
Yeah, I know I'm setting the right time initially, as it runs correctly for a few hours before acting all funny.  Crossing my fingers right now, since I've left it going all day, maybe it actually stayed consistent this time.

you were right, i wasn't setting the time correctly (as I earlier attested, oops).  the following code allowed me to set it correctly (almost 24 hours of the right time now)

sorry for the noise.

Code: [Select]

#include <Wire.h>

void setup()


Wire.send(0x80 | 0x02);    



Dec 12, 2007, 03:23 pm Last Edit: Dec 12, 2007, 08:57 pm by leKuk Reason: 1
i think it is possible to do exact timing with just an arduino. I believe the 16Mhz crystal should run stable enough and one would just have to calibrate it once to get the "real" speed of it.

at least it could be much more precise than it is now. Don't know exactly what dedicated clock chips do extra for temperature/voltage change compensation though, still i doubt these things are needed for most arduino clocks.

did anyone try that yet? does anyone know the specs/tolerance for the standard crystal?

best, kuk


You could make a Arduino clock but its far easier to grab a dirt cheap chip and make it do all the hard work.
They include calendar stuff as well remember.

Also millis() and similar functions arent 100% accurate.
It would be a pain in the butt to count instructions to figure out its margin of error and correct it (without introducing more error).

Go Up