Shop OBEX P1 Docs P2 Docs Learn Events
Please help with basic EEPROM — Parallax Forums

Please help with basic EEPROM

thokennedythokennedy Posts: 4
edited 2010-01-08 18:01 in BASIC Stamp
I am having trouble with storing information.

If I just use the loop:
for counter = 0 to 99
write counter, 2
next

shouldn't that store '2' 100 times in the eeprom, taking up 100 bytes? When I run the memory map, or try to read them, I get nothing. Sorry I must be missing something basic here...thanks for any help.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-08 05:03
    The memory map is a compiler feature to show you what portions of the Stamp's memory are occupied by statements in your program. The memory occupied by DATA statement is included because the DATA statement defines data areas in EEPROM that are filled with preinitialized data that can be accessed with READ statements and changed with WRITE statements, but the compiler has no way to know what other areas are accessed using READ / WRITE statements, so it can't show them in the memory map.
  • thokennedythokennedy Posts: 4
    edited 2010-01-08 14:23
    Thanks for the reply Mike. What you said makes sense, I guess I'm just confused on this activity that is using write statements to 'store' photoresistor readings using just write statements, and then read statements in another program to display them in the debuger.

    Can you direct me to a simple program that I can see stores data in the EEPROM that I can then reference later? Does that data get cleared when you run another program?I guess myunderstanding is that, lets say, you store a byte in address 0 - then you can read that value, even after you shut down, until you over write it with something else.
  • allanlane5allanlane5 Posts: 3,815
    edited 2010-01-08 15:12
    Yes, your understanding is correct. I believe the 'programming' process clears all eeprom locations -- but as long as you don't reprogram the device, the eeprom will hold "WRITE" data. Perhaps 'programming' only clears the locations that are used.

    The "Memory Map" only shows what the IDE is GOING to write to your BS2 -- it doesn't actually read out the contents of the BS2.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-08 15:18
    The "BASIC Stamp Syntax and Reference Manual" has examples in the chapters on the READ / WRITE / DATA statements. You can download this from Parallax's Download pages. It should be included as one of the help files for the Stamp Editor as well.

    When you download a program to a Stamp, the program is stored starting at the upper end of the 2K of EEPROM extending downwards towards zero. Any DATA statements are stored beginning at location zero and extending upwards toward the program. If you're not using DATA statements, you can start storing data beginning at location zero. Since you have control of where the DATA statements go in memory, you can (and must) allocate where the various pieces of data go in the EEPROM. They just can't overlap the program.

    Whatever you store with a WRITE statement will stay there until changed. If you download a new program and the new program doesn't occupy the same part of memory, the data will remain. The memory map for a program will show you what parts of the EEPROM are used by the program. To restate: downloading a new program does not clear the EEPROM. It only changes the portion of the EEPROM occupied by the new program as shown in the memory map.

    Do remember that EEPROM locations can be written only a limited number of times (about 1000000 times). This may seem like a lot, but, in a loop, can be exceeded in just a few days.
  • thokennedythokennedy Posts: 4
    edited 2010-01-08 18:01
    Thanks to the both of you for helping - i'll take another shot at it tonight.
Sign In or Register to comment.