Shop OBEX P1 Docs P2 Docs Learn Events
EEPROM problems — Parallax Forums

EEPROM problems

ArchiverArchiver Posts: 46,084
edited 2001-11-09 16:35 in General Discussion
Thanks everyone who answered my question on that math problem. This
list has been very helpful. Now, I have an EEPROM related problem.
In my project, a variable is written to the EEPROM then read again.
But, the data coming out is not what came in. This is a test program
I wrote:

'Variables
ans1 var word
char var word
'EEPROM
ans2 data

ans1 = 1010 'sample going into EEPROM
debug dec ans1 'debug it
write ans2,ans1 'write to EEPROM
pause 1000 'wait
read ans2,char 'read it
debug dec char 'debug it

When ans1 is read by debug, it equals 1010. When char is read, it
equals 242. What is wrong? Thanks!
Jacob

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-11-09 16:34
    First, you need to reserve 2 bytes to store a word in EEPROM

    ans2 data word 0 ' reserves 2 bytes, preset to 0

    Then you have to WRITE and READ two bytes.

    write ans2,ans1.byte0 'byte 0 to EEPROM
    wrtie ans2+1,ans1.byte1 'byte1
    pause 1000 'wait
    read ans2,char.byte0 'byte 0 from EEPROM
    read ans2+1,char.byte1 'byte 1
    debug dec char

    -- regards,
    Tracy Allen
    electronically monitored ecosystems
    mailto:tracy@e...
    http://www.emesystems.com


    >Thanks everyone who answered my question on that math problem. This
    >list has been very helpful. Now, I have an EEPROM related problem.
    >In my project, a variable is written to the EEPROM then read again.
    >But, the data coming out is not what came in. This is a test program
    >I wrote:
    >
    >'Variables
    >ans1 var word
    >char var word
    >'EEPROM
    >ans2 data
    >
    >ans1 = 1010 'sample going into EEPROM
    >debug dec ans1 'debug it
    >write ans2,ans1 'write to EEPROM
    >pause 1000 'wait
    >read ans2,char 'read it
    >debug dec char 'debug it
    >
    >When ans1 is read by debug, it equals 1010. When char is read, it
    >equals 242. What is wrong? Thanks!
    >Jacob
  • ArchiverArchiver Posts: 46,084
    edited 2001-11-09 16:35
    Jacob -

    When using the EEPROM, WRITE and READ address a single
    byte composed of 8 bits representing 2^8 or 256
    possible values, 0 to 255. When you stored a 16-bit
    word in the space of an 8-bit byte, bits 0 to 7 of
    your word were stored and bits 8 to 15 were lost. In
    the value 1010, the important data that was lost was
    in 1-bits 8 and 9 of the word, representing 256 and
    512. 512 + 256 = 768. 1010 - 768 = 242.

    You need to store words in two EEPROM bytes.

    Bob Pence

    --- sejpower@j... wrote:
    > Thanks everyone who answered my question on that
    > math problem. This
    > list has been very helpful. Now, I have an EEPROM
    > related problem.
    > In my project, a variable is written to the EEPROM
    > then read again.
    > But, the data coming out is not what came in. This
    > is a test program
    > I wrote:
    >
    > 'Variables
    > ans1 var word
    > char var word
    > 'EEPROM
    > ans2 data
    >
    > ans1 = 1010 'sample going into EEPROM
    > debug dec ans1 'debug it
    > write ans2,ans1 'write to EEPROM
    > pause 1000 'wait
    > read ans2,char 'read it
    > debug dec char 'debug it
    >
    > When ans1 is read by debug, it equals 1010. When
    > char is read, it
    > equals 242. What is wrong? Thanks!
    > Jacob
    >
    >
    > 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/
    >
    >


    __________________________________________________
    Do You Yahoo!?
    Find a job, post your resume.
    http://careers.yahoo.com
Sign In or Register to comment.