Correcting time for DS1307

the old fart

Senior Member
The time on my 'I2C RTC DS1307 AT24C32 Real Time Clock' gains two seconds a day.

To correct this in software I have added this to the program.



'One Shot' perday
Code:
	if hour=8 and mins=8 and b52=0 then let b52=1 gosub correcttime:endif  ; clock runs 2second fast per day
	if mins =9 then let b52=0:endif

adjust gosub
Code:
correcttime:



	hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte   	' set DS1307 slave address
	hi2cin 0,(seconds,mins,hour)  	'Read  Time

	serout OLED,Baud,(254,128,"     correcting   ")

	pause 2000

	hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte 
	hi2cout 0,(seconds,mins,hour)


	
  	return
 

1968neil

Senior Member
Your issue with it gaining a couple of seconds a day maybe due to the incorrect crystal ?
The RES038 from techsupplies is the correct type for the DS1307 12pf version or you may have some stray capacitance between the input pins of the DS1307, if using veroboard (stripboard) i tend to mount the crystal as close to the input pins as possible and even go to the point of flowing the solder between the connections to give a little extra track.
Worth checking, i built the very same clock and mine keeps the time very well.
Regards
Neil
 
Top