Shop OBEX P1 Docs P2 Docs Learn Events
Can I write to the EEPROM during program flow — Parallax Forums

Can I write to the EEPROM during program flow

wanderingjeepwanderingjeep Posts: 3
edited 2010-09-30 08:43 in Propeller 1
I want to save data so that next time my program starts it will "Remember" its current settings. Is that possible?

If so, I also need to read that value back. :smilewinkgrin:

Comments

  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-09-28 15:04
    Go to the second sticky thread, Propeller Education Kit, Labs, Tools and Applications. In that thread there is a section on EEPROM Datalogging.

    John Abshier
  • JonnyMacJonnyMac Posts: 9,236
    edited 2010-09-28 16:40
    Yes, you can do that. You should write to a very high EE address so that you don't clash with normal program space.

    I did this in the EH16-DMX for EtherealFX. You can set the brightness levels into the device with a DMX console. The main loop watches and if it sees the local address change from 1 to 0 it saves the current channel leves to EEPROM.

    On reboot, those values are read back into the dimming processor; if no active DMX data is available the previously-save settings are used.

    My I2C object (one among many good ones) lets you write and read bytes, words, longs, and strings. Note, though, that it's designed not to clash with other I2C devices hence requires pull-ups on SCL and SDA.

    http://obex.parallax.com/objects/528/
  • jazzedjazzed Posts: 11,803
    edited 2010-09-28 16:49
    I want to save data so that next time my program starts it will "Remember" its current settings. Is that possible?

    If so, I also need to read that value back. :smilewinkgrin:

    If you write the values to a DAT section byte/word/long address,
    on reboot the values will magically reappear :)
  • DelusDelus Posts: 79
    edited 2010-09-28 21:57
    You can also write to the eeprom at the same address a variable has in ram and the next time you start the program the variable will be loaded with that value.
    ex.
    long var1
    
    ...
    
    write_eeprom(@var1, somevalue)
    

    will restart with var1 == some value. (replacing write_eeprom() with the actual function you are using to write to eeprom)

    -David
  • lardomlardom Posts: 1,659
    edited 2010-09-28 22:59
    I use Martin Hebel's "BS2 Functions" which you can find in the obex. I think it is the easiest way I've found to write to the eeprom. I learned that a variable has the same memory address in RAM and eeprom. This means you can write "cat" in RAM to "cat" in eeprom and change default values on reboot.
    @JonnyMac, I've learned a lot from you and I want to learn to write to a high EE address because I think it will help me understand wear-leveling. I will download and study your I2C object.
  • wjsteelewjsteele Posts: 697
    edited 2010-09-29 08:08
    jazzed wrote: »
    If you write the values to a DAT section byte/word/long address,
    on reboot the values will magically reappear :)

    Sweet!... I never thought of that... that just saved me a bunch of loader code!!!

    Bill
  • JonnyMacJonnyMac Posts: 9,236
    edited 2010-09-29 10:25
    jazzed wrote: »
    If you write the values to a DAT section byte/word/long address,
    on reboot the values will magically reappear :)

    Really? Can you demonstrate that with a bit of code because I tried it and it doesn't work. Updating the DAT (RAM) section does nothing to modify the EEPROM image that the code is booted from after a reset.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-29 10:31
    Jon,
    You have to write to the EEPROM image at the same address as that of the variable in the DAT section in RAM. Since the EEPROM is a byte for byte image of what gets loaded into RAM, the DAT variable will have the value last written to EEPROM at the same address.
  • JonnyMacJonnyMac Posts: 9,236
    edited 2010-09-29 10:55
    Mike Green wrote: »
    Jon,
    write to the EEPROM image

    There's the key.

    I -- and perhaps others -- was confused by the comment about writing to a DAT section. It seemed to me that suggestion was just updating the DAT section, not actually updating the image. If, on the other hand and as you seem to suggest, that one could write the the address in the EEPROM that matches the DAT address, I'm right there with you.

    I updated my test program to write to the EE image at the same address of the DAT value -- works like a charm. Like Bill, I'm going to change a couple programs to simplify saving/loading values from EEPROM.
  • jazzedjazzed Posts: 11,803
    edited 2010-09-29 15:35
    I did say the address, and the topic was EEPROM.
    I could have been clearer. Thanks Mike for clarifying.
  • JonnyMacJonnyMac Posts: 9,236
    edited 2010-09-30 07:50
    I think the Starbucks hadn't kicked in yet and my brain locked in on "write the values to a DAT section." I apologize if I contributed to any confusion (I may in fact have caused it) -- hopefully the little demo program makes up for may lack of gray matter activity yesterday morning. <grin>
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-09-30 08:43
    It doesn't have to be in the DAT section. You can also write to the address (in EEPROM) of global variables.

    The directions given by John Abshier will get you to information on how to do this.

    It's pretty cool to have variables remember there value from the last time I ran a program.

    Duane
Sign In or Register to comment.