Can I write to the EEPROM during program flow
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 so, I also need to read that value back. :smilewinkgrin:
Comments
John Abshier
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/
If you write the values to a DAT section byte/word/long address,
on reboot the values will magically reappear
ex.
will restart with var1 == some value. (replacing write_eeprom() with the actual function you are using to write to eeprom)
-David
@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.
Sweet!... I never thought of that... that just saved me a bunch of loader code!!!
Bill
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.
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.
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.
I could have been clearer. Thanks Mike for clarifying.
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