ds1307 read time back on a m2

jinx

Senior Member
hi,
am trying to read back the time and no surpise am having trouble,i,ve been reading this thread http://www.picaxeforum.co.uk/showthread.php?21281-DS1307-decimal-and-BCD-confusion&highlight=reading+time+ds1307+m2 am stumped on the conversion of decimal to bcd method. i.ve used the PE wizard to set the time i hope
Code:
' set time/date on DS1307 RTC
'Automatically generated by Wizard

'Make sure DS1307 chip and cell inserted on datalogger module
'and that the cable is in the 'run' position.
'After downloading, status LED will be Green for pass or Red for fail.
'After success, download empty program to PICAXE to prevent
'time being reset on next power-up of board.
#picaxe 20m2


symbol r_led = b.6 
symbol g_led = b.4
'First program the date
	high r_led ' write protect eeprom
       low g_led
	i2cslave %11010000, i2cslow, i2cbyte
	writei2c 0, ($00, $29, $21, $02, $27, $08, $12, $10)
	pause 50

'Now check has been set OK 
	let b8 = $02
	let b9 = $27
	let b10 = $08
	let b11 = $12
	let b12 = $10

	readi2c 0, (b0,b1,b2,b3,b4,b5,b6,b7)

	if b7 <> b12 then fail
	if b6 <> b11 then fail
	if b5 <> b10 then fail
	if b4 <> b9 then fail
	if b3 <> b8 then fail
ok:
	high g_led
	low r_led
	goto ok
fail:
	low g_led
	high r_led
	goto fail
this appears to work.
now my code to read it back is just terrible what i get back appears more like a starfleet time starlog
Code:
symbol delay = 500



symbol sec = b0
symbol mins = b1
symbol hour = b2
symbol day = b3
symbol date = b4
symbol month = b5
symbol year = b6
symbol control = b7
symbol temp = b8
symbol rtc = %11010000






init:i2cslave rtc,i2cslow,i2cbyte
         pause delay

main:

do
readi2c 0,(sec,mins,hour,day,date,month,year)


bcdtoascii sec,mins,hour
sertxd("time",#sec,#mins,#hour,cr,lf)
loop
would someone please give me some pointers to read the time back
my setup is a homemade 20m2 exo board and the ds1307 module board made from strip board it has the battery 3v backup added i,ve left the sqw pin floating all other pins wired up as the data sheet suggest.
thx jinx.
 

nick12ab

Senior Member
Code:
bcdtoascii sec,mins,hour
sertxd("time",#sec,#mins,#hour,cr,lf)
The bcdtoascii command just doesn't work like that. The syntax is:
Code:
bcdtoascii inputvar,outputvar1,outputvar2
So the code you actually need to use is:
Code:
bcdtoascii sec,b9,b10
bcdtoascii mins,b11,b12
bcdtoascii hour,b13,b14
sertxd ("time: ",b13,b14,":",b11,b12,":",b9,b10)
 

PaulRB

Senior Member
hi,
am trying to read back the time and no surpise am having trouble,i,ve been reading this thread http://www.picaxeforum.co.uk/showthread.php?21281-DS1307-decimal-and-BCD-confusion&highlight=reading+time+ds1307+m2 am stumped on the conversion of decimal to bcd method. i.ve used the PE wizard to set the time i hope
Code:
' set time/date on DS1307 RTC
'Automatically generated by Wizard

'Make sure DS1307 chip and cell inserted on datalogger module
'and that the cable is in the 'run' position.
'After downloading, status LED will be Green for pass or Red for fail.
'After success, download empty program to PICAXE to prevent
'time being reset on next power-up of board.
#picaxe 20m2


symbol r_led = b.6 
symbol g_led = b.4
'First program the date
	high r_led ' write protect eeprom
       low g_led
	i2cslave %11010000, i2cslow, i2cbyte
	writei2c 0, ($00, $29, $21, $02, $27, $08, $12, $10)
	pause 50

'Now check has been set OK 
	let b8 = $02
	let b9 = $27
	let b10 = $08
	let b11 = $12
	let b12 = $10

	readi2c 0, (b0,b1,b2,b3,b4,b5,b6,b7)

	if b7 <> b12 then fail
	if b6 <> b11 then fail
	if b5 <> b10 then fail
	if b4 <> b9 then fail
	if b3 <> b8 then fail
ok:
	high g_led
	low r_led
	goto ok
fail:
	low g_led
	high r_led
	goto fail
this appears to work.
now my code to read it back is just terrible what i get back appears more like a starfleet time starlog
Code:
symbol delay = 500



symbol sec = b0
symbol mins = b1
symbol hour = b2
symbol day = b3
symbol date = b4
symbol month = b5
symbol year = b6
symbol control = b7
symbol temp = b8
symbol rtc = %11010000






init:i2cslave rtc,i2cslow,i2cbyte
         pause delay

main:

do
readi2c 0,(sec,mins,hour,day,date,month,year)


bcdtoascii sec,mins,hour
sertxd("time",#sec,#mins,#hour,cr,lf)
loop
would someone please give me some pointers to read the time back
my setup is a homemade 20m2 exo board and the ds1307 module board made from strip board it has the battery 3v backup added i,ve left the sqw pin floating all other pins wired up as the data sheet suggest.
thx jinx.
Jinx,

You don't want to use both bcdtoascii and then use # in your sertxd command. They both convert to ASCII, so do one or the other.

Also, think your bcdtoascii command it over-writing the mins and hours value retrieved from the rtc.

Paul
 

jinx

Senior Member
hi guys,thanks for the speedy response thanks for the link mark,nick as ever helpful thx ,paul thx for explaining

the module actually work here's a pic'sDSCF0070.JPGDSCF0071.JPG
now am thinking of using this method on the shield that we get with the 401, i did a dry fit the battery will fit under the xbee shield where the xbee goes it's compact but does fit and hopeful when i get the xbee the ds1307 will fit under the xbee.
 
Hey Nick12ab,
I was having a similar problem trying to display the time kept by the DS1307 on an LCD display. I did a comprehensive search of the forum and found many many posts, but none that correctly addressed the problem I was having (until one minute ago). I was about to begin a thread myself. Your reply from up here solved it. I am just writing to show my endless appreciation. You have helped me directly in the past (an LCD problem if I remember correctly) and you have come to the rescue (indirectly) once again. You sir, ROCK.
Thank you!
Andrés
 

nick12ab

Senior Member
Hey Nick12ab,
I was having a similar problem trying to display the time kept by the DS1307 on an LCD display. I did a comprehensive search of the forum and found many many posts, but none that correctly addressed the problem I was having (until one minute ago). I was about to begin a thread myself. Your reply from up here solved it. I am just writing to show my endless appreciation. You have helped me directly in the past (an LCD problem if I remember correctly) and you have come to the rescue (indirectly) once again. You sir, ROCK.
Thank you!
Andrés
Glad to have helped.

P.S. Yes it was an LCD issue.
 
Top