DS 1302 and SHIFTIN
Hello,
· I am working with the DS 1302 real time clock.· I have a code which reads the clock just fine, but I am trying to replace a SHIFTIN command with a FOR loop.·· Below I have included the·part of my code which reads the seconds register.· When I use the SHIFTIN command (LSBPRE), the seconds read fine.··But then I replace the SHIFTIN with the·FOR loop shown below and the seconds register reads 00 continually.··It appears that the code is written correctly, taking into account the·bit shifting direction, and the fact that the data must be read prior to the first clock stroke.··Can someone tell me what I am missing.
thanks,
agentile
DataIO··· CON·· 11
Clock···· CON·· 8
CS1302··· CON·· 10
DIR11 = %1
DIR10=%1
DIR8=%1
k VAR Nib
sec VAR Byte
HIGH CS1302
SHIFTOUT DataIO,Clock,LSBFIRST,[noparse][[/noparse]%10000001]
This works...··· SHIFTIN DataIO,Clock,LSBPRE,[noparse][[/noparse]secs]
This doesn't...· FOR k=1 TO 8
··················· · secs=secs>>1
··················· · secs.highbit=IN11
··················· · PULSOUT clock,2
·················· · ·NEXT
LOW CS1302
· I am working with the DS 1302 real time clock.· I have a code which reads the clock just fine, but I am trying to replace a SHIFTIN command with a FOR loop.·· Below I have included the·part of my code which reads the seconds register.· When I use the SHIFTIN command (LSBPRE), the seconds read fine.··But then I replace the SHIFTIN with the·FOR loop shown below and the seconds register reads 00 continually.··It appears that the code is written correctly, taking into account the·bit shifting direction, and the fact that the data must be read prior to the first clock stroke.··Can someone tell me what I am missing.
thanks,
agentile
DataIO··· CON·· 11
Clock···· CON·· 8
CS1302··· CON·· 10
DIR11 = %1
DIR10=%1
DIR8=%1
k VAR Nib
sec VAR Byte
HIGH CS1302
SHIFTOUT DataIO,Clock,LSBFIRST,[noparse][[/noparse]%10000001]
This works...··· SHIFTIN DataIO,Clock,LSBPRE,[noparse][[/noparse]secs]
This doesn't...· FOR k=1 TO 8
··················· · secs=secs>>1
··················· · secs.highbit=IN11
··················· · PULSOUT clock,2
·················· · ·NEXT
LOW CS1302
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
The SHIFTOUT command apparently sets the data port (pin 11) as an output.· If you follow the SHIFTOUT command with and IN11 read command, the port is still set as an output, and so it reads 0.· IF you follow the SHIFTOUT command with a data direction command, DIR11=1, then the succeeding FOR loop code will work.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax