Shop OBEX P1 Docs P2 Docs Learn Events
DS1302 RAM Rd/Wr constant/address formatting question — Parallax Forums

DS1302 RAM Rd/Wr constant/address formatting question

xanatosxanatos Posts: 1,120
edited 2009-07-22 16:29 in General Discussion
I've spent the past hour searching the forum.· I KNOW I've seen the answer to this somewhere - perhaps an N&V column - but I've opened and read all the likely candidates there ("getting real with the DS1302", etc).· So in frustration, I've gotta ask....

I'm looking for the *description* of how the address and the·constant to read/write to that address are actually operated on by the DS1302.· The specific lines of code I am seeking to better understand is:

reg = WrRam | (index << 1)

and

reg = RdRam | (index << 1)

Where RdRam is a constant = $C0 and WrRam = $C1.

While I "know" that this means that the constant RdRam or WrRam are OR'd with the index value for the byte to be written to and shifted left 1 bit (???), I'm not really *understanding* what's happening.· And I'd like to...

Thanks for any help!

Dave





·

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-07-20 03:27
    Hi, lets take the scenario you want to write to the chip.

    First thing is to notify the DS1302 that you want to write and to which address you want to write to.

    WrRam ($C0)·is the template for your command , the gap you have to fill in is the address which is bit 1 through 5 ( marked in·red )

    11000000

    The variable index is the address you manually enter via the debug screen , so say you entered 23 in binary thats 10111 ( the 5 bits we need )

    Next we shift the value 23 left by 1 ( index<<1 ) giving 101110 .

    Now when we OR index with WrRam we have the write command containing our address (which is now held by "reg")

    11000000

    OR

    00101110

    reg= 11101110

    Jeff T.
  • xanatosxanatos Posts: 1,120
    edited 2009-07-20 10:55
    Ah! First- Thanks! That is exactly what I was looking for. And second- I get it now! So with only 30 available spaces to write to, you're never changing the value of the leading 11, and the trailing 0/1 depending on if it's write or read, also gets left alone, you really are just filling in a "carrier gap" for the address.

    It seems so simple now... Don't know why it seemed so confusing before...

    Thanks again!

    Dave X
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-07-22 16:29
    By the way, this is all described in the comments to the DS1302 Demo Code in the Completed Projects Forum if you should need it in the future. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
Sign In or Register to comment.