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