Part number: 24FC256
I am using an EEPROM to store some configurations for the MCU logic that must be retained if a power down condition occurs. Also, I store events into the EEPROM so that I don't lose them.
I would like to extend the EEPROM life endurance as much as I can and to achieve that I have thought in some techniques.
- Store binary value
I have some configuration variables that are boolean values. So writing 0x00 and 0x01 to a byte over and over again doesn't look very efficient. To accomplish this a better wear leveling, I have designed the following strategy:
Starting from the 0xFF value (0b11111111) I would consider the value as a '0' if the first '1' of the value is in an odd position. So in this case, the first '1' is in the 7th position (most significant bit first). That means that the value 0xFF encodes a '0'.
Now I want to change the value from '0' to '1'. So I write a 0x7F value to the EEPROM (0b01111111). Now the first '1' is in an even position, so that means that the value stores a '1'.
Once the value is 0b00000001, the next value written is 0b11111111 and the process starts again.
I think that the idea is pretty clear.
My question is, does this strategy improve x8 the life span of that EEPROM byte? As I understand it, what causes a cell to wear out is erasing it (converting 0 to 1), but the writing process (converting 1 to 0) does not involve wearing it out. And as I perform 8 write cycles before erasing it again I reduce erase cycles to an 1/8th.
I want to beleave that the EEPROM is smart enough to not perform an erase before the write if there is no 0 -> 1 transition from the old value to the new one.
- Store data arrays
Another task to accomplish is to store events in the EEPROM. Say I want to store the unix timestamp when an event has happened. Having a circular buffer of 32 elements of 4 bytes each.
Once an event has been sent, I would like to "remove" them from the buffer. To do that, I have thought to write the 4 byte element to 0x00000000. Other approach would be to erase them to 0xFFFFFFFF. When a new event happens, it is written in the previously removed element.
Would this strategy involve two erase/write cycles? (First to remove the value and second to write the new one) Or it performs a write in the case of 0x00000000 (which doesn't wear out) so this operation wouldn't count? Or it performs an erase to turn the value to all 0xFF, so the next time only has to write?
All these questions arose from the doubt about what exactly causes the cell wear out, if it is just the erase step or not.