Shop OBEX P1 Docs P2 Docs Learn Events
BS2 Serin String in to EEPROM to save when power off. — Parallax Forums

BS2 Serin String in to EEPROM to save when power off.

Jeff_5_Jeff_5_ Posts: 36
edited 2011-10-25 11:42 in BASIC Stamp
I have a basic stamp program i wrote that reads in three differnt strings. Word1, Word2, Word3.

Here is my serin statement. SERIN 1,84,[ STR Word1\4]
DEBUG STR Word1, CR

I have one of these for all three variables Once i read in all three i run a comparison program and some leds. Anyway my program works good except every time the basic stamp loses power i have to reread in Word1,Word2,Word3.

So how can i Serin Write to EEPROM so when powered off they will be saved.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-24 20:42
    You're reading in 3 separate strings each consisting of 4 characters (bytes). There is no automatic way to write these to EEPROM. You can use the READ and WRITE statements to write the variables. I assume that Word1, Word2, and Word3 are all declared as byte arrays with "Word1 VAR Byte(4)". In that case, you'd do " WRITE 0, Word1(0), Word1(1), Word1(2), Word1(3)" in order to write the 4 bytes into EEPROM locations 0-3. You'd do something similar for Word2 and Word3, maybe using locations 4-7 and 8-11 for those values. Reading these bytes back from EEPROM would work the same way.
  • Jeff_5_Jeff_5_ Posts: 36
    edited 2011-10-25 04:45
    Thanks Mike your the man. I had a feeling you would have an answer for me as you have been very helpful in the past.

    Yes my Array is declared as Word1 VAR Byte(4)

    Your saying i should do this

    SERIN 1,84,[ STR Word1\4]
    then
    WRITE 0,Word1(0)
    WRITE 1,Word1(1)
    WRITE 2,Word1(2)
    WRITE 3,Word1(3)

    That will write them to the EEPROM

    To get the back out the do my comparison i need to

    READ 0,Word1(0)
    READ 1,Word1(1)
    READ 2,Word1(2)
    READ 3,Word1(3)

    Then i can do my compassion.

    IF ((Word1(0)=Word(0)) AND (Word(1)=Word2(1)) and so on....

    Of course i would do the WRITE and READ statements for all three Arrays. Word1, Word2, Word3

    This should work correct?

    One more question. If i read from EEPROM every time i do my compassion wont that slow my program down alot? I do this comparison probably 100 times a minute. I really just need to read from EEPROM on startup not every time.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-25 07:20
    A READ takes about 550us (see here). You've got 12 READs. You do them 100 times. That's 660ms compared to one minute (60000ms).
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2011-10-25 11:42
    Jeff,

    It seems to me in your code that you're not writing out Word values, but rather single byte values. Is this what you intended? If indeed there are Word values in your array then when the first WRITE executes data is writen to locations 0 and 1. However in your second WRITE statement you will overwrite location 1. You need to increase your addresses by two when writing Word values (2 bytes).
Sign In or Register to comment.