1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

EEprom - Reading and Writing

Discussion in 'Arduino' started by Wp100, Dec 24, 2015.

  1. Wp100

    Wp100 Active Member

    Joined:
    Feb 3, 2009
    Messages:
    969
    Likes:
    45
    Location:
    England
    Hi,

    Something I could do easily in Pic Assembly code but cannot see if it can be done with C++ ..?

    I am declaring a series of control parameters at the beginning of the code, all as single Bytes. eg, temp, timehours, timemins, etc
    I want to be able to store them all in eeprom in one go rather than individually ; as most Arduino examples show.
    During program run these values may be changed, so when the program is restarted, then it will read out the updated eeprom block of Bytes and restore them.

    Is this possible ?

    thanks
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,304
    Likes:
    914
    Location:
    Rochdale UK
    Do you not want to use the "two wire" library??? The Arduino IDE has this library already!!
     
  3. zahwi

    zahwi Member

    Joined:
    Oct 24, 2015
    Messages:
    186
    Likes:
    16
    This is his wish:
    "I want to be able to store them all in eeprom in one go rather than individually ; as most Arduino examples show."
    We have to put this request to Atmel.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Wp100

    Wp100 Active Member

    Joined:
    Feb 3, 2009
    Messages:
    969
    Likes:
    45
    Location:
    England

    Hi,

    Sorry, should have said Save to Internal EEprom.

    As Zahwi shows, its how can I several Byte variables be saved and restored from eeprom in one operation rather than calling each one by name; probably about 40 Bytes when the program finished.

    Eg
    byte LEDPWM_VALUE = 0;
    byte LEDPWM_PRELOAD = 30;
    byte LEDPWM_INCVALUE = 5;
    byte LEDPWM_INCTIME = 3;
    byte LEDPWM_DAY = 0;
    byte LEDPWM_MOON = 50;



    Zahwi - do not think Atmel will be interested in an Arduino / C++ problem ...?
     
  6. zahwi

    zahwi Member

    Joined:
    Oct 24, 2015
    Messages:
    186
    Likes:
    16
    Writing to eeprom is limited to about 1 million cycles. It takes several instructions in certain order. It takes about 5ms to write 1 byte. Microcontrollers don't have the option of writing more than 1 byte at a time.
    If you need to update the data often then write it to the RAM and only periodically copy it to the eeprom when the CPU isn't busy.
     
  7. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,964
    Likes:
    1,099
  8. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    You do it in C exactly the same way as in asm. What have you tried that didn't work?

    Mike.
     
  9. Wp100

    Wp100 Active Member

    Joined:
    Feb 3, 2009
    Messages:
    969
    Likes:
    45
    Location:
    England
    Hi,

    All I can find for writing to EEprom is this Write out a single byte variable " EEPROM.write(addr, val);"

    I have 40+ Byte Variables as showing in entry #4.

    So with that instruction I have to code a EErpom.Write for each variable.

    I was hoping to find some way of indetifying the whole block of byte variables and code it in one function ?
     
  10. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    Make a table that contains the addresses of the variables and then use a for loop to read/write them. To find the address use the & form. I.E &LEDPWM_VALUE will give the address of LEDPWM_VALUE.

    Mike.
     

Share This Page