Shop OBEX P1 Docs P2 Docs Learn Events
DS 1302 and SHIFTIN — Parallax Forums

DS 1302 and SHIFTIN

agentileagentile Posts: 101
edited 2006-03-23 18:43 in BASIC Stamp
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

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-23 18:22
    My question is why would you want to do it this way?· It seems like a lot more work to do the same thing.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • agentileagentile Posts: 101
    edited 2006-03-23 18:22
    After some trial and error testing...Here is why the code won't work.

    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 WilliamsJon Williams Posts: 6,491
    edited 2006-03-23 18:43
    Not apparently, it does -- SHIFTOUT makes both the data and clock pins outputs, and this behavior is documented.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.