Shop OBEX P1 Docs P2 Docs Learn Events
How to write and read word-sized(16-bit)data to EEPROM? — Parallax Forums

How to write and read word-sized(16-bit)data to EEPROM?

ArchiverArchiver Posts: 46,084
edited 2000-08-08 13:38 in General Discussion
I can´t figure out how to write and read word-sized data to the
EEPROM. Byte-sized are no problem. I have tested something like this:

myword var word
EEaddr var word
myword =260
WRITE EEaddr, myword
read EEaddr , myword
debug "Reading myword= ", dec myword,tab,cr

Since 260 does not fit into a byte the debug shows the result of 6
(260-256).
Is there an easy way to store word instead of byte in the EEPROM?

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-08-08 11:34
    You need to split the word into 2 bytes, i.e

    myword var word
    EEaddr var word
    EEaddr = 0
    myword =260
    WRITE EEaddr, myword.lowbyte
    EEaddr = EEaddr + 1
    WRITE EEaddr, myword.highbyte

    read EEaddr , myword.lowbyte
    EEaddr = EEaddr + 1
    read EEaddr, myword.highbyte


    debug "Reading myword= ", dec myword,tab,cr

    regards, Chris Anderson
    Original Message
    From: <torsten.stahlberg@s...>
    To: <basicstamps@egroups.com>
    Sent: Tuesday, August 08, 2000 5:47 PM
    Subject: [noparse][[/noparse]basicstamps] How to write and read word-sized(16-bit)data to
    EEPROM?


    > I can´t figure out how to write and read word-sized data to the
    > EEPROM. Byte-sized are no problem. I have tested something like this:
    >
    > myword var word
    > EEaddr var word
    > myword =260
    > WRITE EEaddr, myword
    > read EEaddr , myword
    > debug "Reading myword= ", dec myword,tab,cr
    >
    > Since 260 does not fit into a byte the debug shows the result of 6
    > (260-256).
    > Is there an easy way to store word instead of byte in the EEPROM?
    >
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2000-08-08 12:02
    In a message dated 8/8/00 4:49:13 AM Central Daylight Time,
    torsten.stahlberg@s... writes:

    > I can´t figure out how to write and read word-sized data to the
    > EEPROM. Byte-sized are no problem. I have tested something like this:
    >
    > myword var word
    > EEaddr var word
    > myword =260
    > WRITE EEaddr, myword
    > read EEaddr , myword
    > debug "Reading myword= ", dec myword,tab,cr
    >
    > Since 260 does not fit into a byte the debug shows the result of 6
    > (260-256).
    > Is there an easy way to store word instead of byte in the EEPROM?

    You need two WRITEs and two READs to handle word-sized variables. Like this:

    WRITE EEaddr, myword.LOWBYTE
    WRITE EEaddr+1, myword.HIGHBYTE

    then...

    READ EEaddr, myword.LOWBYTE
    READ EEaddr+1, myword.HIGHBYTE

    -- Jon Williams
    -- Dallas, TX
  • ArchiverArchiver Posts: 46,084
    edited 2000-08-08 13:38
    you have to store the high byte, and the low byte as two seperatre stores,
    and read it back as two reads, one for high one for low.

    Norm & Monda
    Cozy MK IV #202
    Ford V-6 Powered
    Original Message
    From: <torsten.stahlberg@s...>
    To: <basicstamps@egroups.com>
    Sent: Tuesday, August 08, 2000 5:47 AM
    Subject: [noparse][[/noparse]basicstamps] How to write and read word-sized(16-bit)data to
    EEPROM?


    I can´t figure out how to write and read word-sized data to the
    EEPROM. Byte-sized are no problem. I have tested something like this:

    myword var word
    EEaddr var word
    myword =260
    WRITE EEaddr, myword
    read EEaddr , myword
    debug "Reading myword= ", dec myword,tab,cr

    Since 260 does not fit into a byte the debug shows the result of 6
    (260-256).
    Is there an easy way to store word instead of byte in the EEPROM?
Sign In or Register to comment.