Shop OBEX P1 Docs P2 Docs Learn Events
DS1302 Help — Parallax Forums

DS1302 Help

ArchiverArchiver Posts: 46,084
edited 2002-01-19 17:42 in General Discussion
I am trying to understand the sample code given by Parallax for the
DS1302 IC, the problem is, I cannot understand how the program works.

All I want the DS1302 and the BS 2 is,

1. Program the current time to the DS1302.
2. Make the BS2 read the time on the DS1302.

Can some one help.

Thank you very much.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-01-19 17:19
    Does anyone know if this code for the DS1302 will work with a DS1215?

    thanks,

    leroy

    chris01@t... wrote:
    >
    > It's not as difficult as it looks. Look at Peter Anderson's site for a nice
    > commented tutorial. Try www.phanderson.com/stamp/ds1302_des.html which is
    > much clearer with more notations that make sense.
    > I struggled with this for a while only to realise that that it's all about
    > juggling DIR of the I/O and the output state of /RST.
    > The basics are:
    > 1. Put the I/O in the appropriate state while the serial clock line is low.
    > 2. Bring /RST high and start writing a command to the clock via shiftout
    > with $80, LSB1st. Your first command will probably be to clear the write
    > protect bit. Bring the /RST line low to end the write.
    > 3. Read the starting time that you have previously put in the Stamp's EEPROM
    > (data stmt), byte by byte. If you're only using HH:MM:SS you'll only need 3
    > bytes. This works well by setting I/O direction again then using a shiftout,
    > LSB1st inside a for/next loop - for each byte.
    > 4. Set the write protect bit
    > 5. Read and display your time by making I/O output, bringing /RST high
    > again, then shifting out a command byte for READ, changing I/O to in, then
    > finally shiftiing in a time value byte by byte. You'll need to do this
    > sequentially for the HH, MM & SS bytes. Display using debug to screen or
    > serout to an LCD after each byte. Use the HEX2 modifier to convert the BCD
    > to something you'll recognize as time.
    >
    > As long as you remember that the /RST line has to be high for the chip to do
    > anything, and that you have separate commands (I think they're $80 & $81 for
    > write & read) and remember that you have write protect bit to deal with, the
    > rest will just use your regular old basic programming skills that you have
    > used many times. This is a great chip that is easy to work with once you
    > become accustomed to this method. Along with the clock function, it has
    > another 31 bytes of RAM you can write to and read from with the same
    > interface which more than doubles the BS2's RAM as a bonus.
    >
    > Chris
    >
    > I am trying to understand the sample code given by Parallax for the
    > DS1302 IC, the problem is, I cannot understand how the program works.
    >
    > All I want the DS1302 and the BS 2 is,
    >
    > 1. Program the current time to the DS1302.
    > 2. Make the BS2 read the time on the DS1302.
    >
    > Can some one help.
    >
    > Thank you very much.
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    > Body of the message will be ignored.
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and Body
    of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2002-01-19 17:42
    It's not as difficult as it looks. Look at Peter Anderson's site for a nice
    commented tutorial. Try www.phanderson.com/stamp/ds1302_des.html which is
    much clearer with more notations that make sense.
    I struggled with this for a while only to realise that that it's all about
    juggling DIR of the I/O and the output state of /RST.
    The basics are:
    1. Put the I/O in the appropriate state while the serial clock line is low.
    2. Bring /RST high and start writing a command to the clock via shiftout
    with $80, LSB1st. Your first command will probably be to clear the write
    protect bit. Bring the /RST line low to end the write.
    3. Read the starting time that you have previously put in the Stamp's EEPROM
    (data stmt), byte by byte. If you're only using HH:MM:SS you'll only need 3
    bytes. This works well by setting I/O direction again then using a shiftout,
    LSB1st inside a for/next loop - for each byte.
    4. Set the write protect bit
    5. Read and display your time by making I/O output, bringing /RST high
    again, then shifting out a command byte for READ, changing I/O to in, then
    finally shiftiing in a time value byte by byte. You'll need to do this
    sequentially for the HH, MM & SS bytes. Display using debug to screen or
    serout to an LCD after each byte. Use the HEX2 modifier to convert the BCD
    to something you'll recognize as time.

    As long as you remember that the /RST line has to be high for the chip to do
    anything, and that you have separate commands (I think they're $80 & $81 for
    write & read) and remember that you have write protect bit to deal with, the
    rest will just use your regular old basic programming skills that you have
    used many times. This is a great chip that is easy to work with once you
    become accustomed to this method. Along with the clock function, it has
    another 31 bytes of RAM you can write to and read from with the same
    interface which more than doubles the BS2's RAM as a bonus.

    Chris



    I am trying to understand the sample code given by Parallax for the
    DS1302 IC, the problem is, I cannot understand how the program works.

    All I want the DS1302 and the BS 2 is,

    1. Program the current time to the DS1302.
    2. Make the BS2 read the time on the DS1302.

    Can some one help.

    Thank you very much.


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Sign In or Register to comment.