Shop OBEX P1 Docs P2 Docs Learn Events
DS1302 perhaps I posted this too late at night.... — Parallax Forums

DS1302 perhaps I posted this too late at night....

ArchiverArchiver Posts: 46,084
edited 2002-02-12 02:40 in General Discussion
So, I'll try again.

OK, a few of you had good experience with the DS1302 RTC, and were very
helpful with your suggestions during my first attempt with it a while back.
Now I am attempting to use a 1302 again and I am getting crosseyed trying to
find my error. I have checked my basic code and my hardware 100x to no
avail. The only clue I have is that the intial time value does evidently
write and then read appropriately. The problem is that the clock does not
advance afterward.

Would anyone please care to check me out and see if I wrote some code that
won't work.....at least I'll know if I should dissect the hardware further
if no one finds an error..... It is a pain to check if the 1302 is being
clocked by the crystal or not (suggestions welcome here also...)

Anyway, here's what I have and it has worked well for me before, but not
today........(unless one of my 10 thumbs bumped something that I now can't
find....):

TIA, Chris

'****snipped DS1302 stuff - 13 is clk; 14 is data; 15 is /rst***

Csec con 0
Cmin con 1
Chr con 2
Control con 7

Adr var byte
Val var byte

dirD = %1110

time data $00, $00, $00
'from here to 'main:' w.p. bit cleared, '1302's clock RAM set to
all zeros'
'& w.p. bit set again

dir14 = 1 'clear RTC write protect bit
out15 = 0 '/rst low
out13 = 0 'sclk low
out15 = 1 '/rst brought hi while sclk is low

shiftout 14, 13, lsbfirst, [noparse][[/noparse]$80 | (control<<1) \8]
shiftout 14, 13, lsbfirst, [noparse][[/noparse]$00\8]

out15 = 0 '/rst low again, end

for Adr=0 to 2
read time + Adr, Val 'get value from BS2 EEPROM
gosub put_time 'write to DS1302
next

dir14 = 1
out15 = 0
out13 = 0
out15 = 1

shiftout 14, 13, lsbfirst, [noparse][[/noparse]$80 | (control<<1) \8]
shiftout 14, 13, lsbfirst, [noparse][[/noparse]$80\8]
out15 = 1

Main: 'from here to ShowTime, routines to read & display data from
'ADC channels, not related to time
ShowTime:

Adr = Chr
gosub get_time
serout 8,n9600, [noparse][[/noparse]I,200]
serout 8,n9600, [noparse][[/noparse]Hex2 Val]

Adr = Cmin
gosub get_time
serout 8,n9600,[noparse][[/noparse]I,203]
serout 8,n9600, [noparse][[/noparse]Hex2 Val]

Adr = Csec
gosub get_time
serout 8,n9600,[noparse][[/noparse]I,206]
serout 8,n9600, [noparse][[/noparse]Hex2 Val]

Pause 350
Goto Main
put_time:
dir14 = 1
out15 = 0 'rst
out13 = 0 'clk
out15 = 1 'rst

shiftout 14,13,lsbfirst, [noparse][[/noparse]$80 | (Adr<<1)\8] 'command byte
shiftout 14,13,lsbfirst, [noparse][[/noparse]Val\8]
out15 = 0

return

get_time:
dir14 = 1
out15 = 0
out13 = 0
out15 = 1
shiftout 14,13,lsbfirst, [noparse][[/noparse]$81 | (Adr<<1)\8] '
dir14 = 0
shiftin 14,13,lsbpre, [noparse][[/noparse]Val\8]
out15 = 0

return
Sign In or Register to comment.