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.
1 Answer 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.
-
The literal
2000
is always interpreted by the compiler as anint
.Edgar Bonet– Edgar Bonet2020年06月29日 07:20:59 +00:00Commented 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– Delta_G2020年06月29日 13:06:46 +00:00Commented 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.Edgar Bonet– Edgar Bonet2020年06月29日 13:17:19 +00:00Commented 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– Delta_G2020年06月29日 14:39:52 +00:00Commented Jun 29, 2020 at 14:39
Explore related questions
See similar questions with these tags.
2000
or are you trying to write an arry of 2000 elements? Thats not clear in your question2000
.