Hi Guys!
I have a "small" problem with my device
Environment:
- Arduino Mega 2560 Pro
- EEPROM library
I am making a target hardware. On startup, I enter its programming interface, where I set some variables for the operation of the machine, which I then store in EEPROM memory.
The machine is then put into use. It is switched on and off several times a day.
On power-up, I use EEPROM.get() to read the values of the variables and the machine operates with them.
It works perfectly so far!
Days, weeks, months go by, when one of the machines goes crazy, does not do what it should, or not as it should. It is almost immediately clear that there is a problem with one of the values read from the EEPROM. These values stored in the EEPROM are typically between 0 and 3000, and sometimes I can get values around 5000, 23000, which is clearly out of range. And if you turn the device off and then back on again, it will read the same erroneous value. So we can say for sure that the data stored in the EEPROM is corrupted. There is no EEPROM write on power on/off, only read. In this case, if I enter the setting menu (it is locked with code) and reset the value, the program works perfectly again!
Why can this EEPROM corruption happen?
- So far I have turned off the BOD on the Fuse bits (Brown Out Level Disabled). I know it's silly, but during normal use there is never any writing, yet the EEPROM is corrupted. During reading, can memory areas be corrupted with BOD off?
- Is there a solution to redundant storage? That I store all values in two memory areas? On startup I compare them and if they don't match I rewrite the bad one with the good one. I know it's bad because its contents are outside the value range. If it is greater than 3000 or less than 0 then its value is overwritten by the value on the copy.
EEPROM.get(805, value1);
EEPROM.get(1805, permavalue);
if ((value1<0) || (value1>3000)) {value1=permavalue;EEPROM.put(805, permavalue);}
if (permavalue != value1) {EEPROM.put(1805, value1);}
Will this work well? Am I right in thinking that there is little chance of damaging two value pairs at the same time? So theoretically I can keep checking to see if a piece of data is corrupted, and then I can write it upside down for good
Or can you imagine that just turning on the BOD would solve the problem? Is it possible that no EEPROM writing can corrupt the data due to the lack of BOD?
Or could it be that I'm using a Chinese arduino clone and the EEPROM is of poor quality?
