I am trying to write and read from EEPROM on a new M404 with deviceOS@6.3.0. Some code:
// Address to read and write to/from
static const int EEPROM_ADDR = 512;
// struct to save
struct FirmwareSettingsNew {
uint8_t hasBeenConfigured; // 1 byte
uint8_t version; // 1 byte
Environment env; // 1 byte
SensorModel sensorModel; // 1 byte
WeatherStationModel wxModel; // 1 byte
uint8_t board_version_major; // 1 byte
uint8_t board_version_minor; // 1 byte
uint8_t board_version_patch; // 1 byte
char serialNumber[20]; // 20 bytes
};
I do something like this:
EEPROM.get(EEPROM_ADDR, settings);
if (settings.hasBeenConfigured != 1) {
// Initialize for the first time
FirmwareSettingsNew newObj = {
s_hasBeenConfigured,
s_version,
s_env,
s_sensorModel,
s_wxModel,
p_board_version_major,
p_board_version_minor,
p_board_version_patch,
"",
};
EEPROM.put(EEPROM_ADDR, newObj);
}
What's strange is that if I run the code and loop over it, it appears the EEPROM has been written correctly and will read correctly the second (and future) time around. However, if I reset the device, it defaults to values of settings.hasBeenConfigured=246
and settings.version=228
.
The code is currently doing pretty much nothing else. What could be causing this? I've tried to see if it was a power issue, and it doesn't appear to be. I don't have my logic analyzer with me otherwise I would throw that on. Any hints on where to look or tests to run? I can post a full sketch if needed as well to run further tests.