Each time you write you're writing three bytes of data, but you're only incrementing the address (preset_counter) by one.write preset_counter, encoder1_counter, encoder2_counter, encoder3_counter
The next time you write you'll be overwriting part of the previously saved data.
When you go to write/read, multiply preset_counter by 4 and use that as the address so the three bytes are preserved.
Make sure preset_counter is never more than 255/4 or the address will wrap since it's a byte value.
Yes! That fixed it. I didn't realize that each data space had its own address. I thought everything in the statement was stored at the designated address.
write 4, 1, 2, 3
So 1 is stored at address 4, 2 is stored at address 5, and 3 is stored at address 6? And then if I want to write something else, it would have to be "write 7, 4, 5, 6" if I didn't want to overwrite the other data? Is that how it works?
Basically, yes, as long as you're talking about bytes.
EEPROM is byte-addressable, and each byte has its own address. Muti-byte variables like words and longs take multiple bytes (addresses) for each value.
Bookmarks