1

Facing an issue while writing a large value (like 2000-5000) to EEPROM using EEPROM.put().
For example, While writing 2000 values to address 5 of EEPROM. Some junk values are written automatically to a nearby address (address 4, 6, 7...).

Note : Not trying to write an array of 2000 elements

Board Used : Arduino Uno (Atmega328P)

Q1 : What is the typical range of a each address by using EEPROM.put() . Like EEPROM.write() has range limit of 0-255.
Q2 : How to write large value EEPROM addresses without effecting the nearby address.

enter image description here

2
  • Are you writing the value 2000 or are you trying to write an arry of 2000 elements? Thats not clear in your question
    – chrisl
    Jun 29, 2020 at 6:07
  • @chrisl I am trying to write value 2000. Jun 29, 2020 at 6:51

1 Answer 1

1

It depends on what type of variable you have. If you have single byte variables like byte or char then it is one value to one address. But if you have an int value like:

int x = 2000;

then try to store that in EEPROM that will take 2 bytes because an int is 2 bytes in size. So if you write that to address 5 it will take 5 and 6 to write it.

If you write a long or a float, they are 4 bytes, so they will take 4 address slots in the EEPROM each.

If you just write EEPROM.put(5, 2000); then the 2000 gets seen as either int or long depending on how the code is written. I don't remember. But you certainly can't fit 2000 into a byte so it's going to have to take more than one.

4
  • The literal 2000 is always interpreted by the compiler as an int. Jun 29, 2020 at 7:20
  • Yes the compiler does but I don’t know how the put function works. It could be like print where int ends up promoted to long in the function.
    – Delta_G
    Jun 29, 2020 at 13:06
  • It's a template: it uses whatever type its argument has. Unlike print(), which is a collection of overloads. Jun 29, 2020 at 13:17
  • Ok thanks. Wasn’t able to look it up when I wrote the answer. Wasn’t sure how it was handled but knew for sure we needed more than one byte.
    – Delta_G
    Jun 29, 2020 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.