When trying to read empty EEPROM hangs the device

"Resetting" the cells to 0x00 is not the best approach as it inevitably means that the next write will have to relocate the EEPROM window as there are no bits that can be written to anymore.
For flash memory bits can only be cleared (set to 0) indidvidually but to set them (1) you'll need a page erase - this is what causes flash wear.

I haven't tried it, but what happens when you "initialise" the EEPROM window by writing all 0xFF ("confirm" the value that should be there all along) and then try the code you have above?

With this code my Electron doesn't block

uint32_t addr = 0;
uint16_t data;

void setup() {
  Serial.begin();
  Serial.println("init");
  data = 0xFFFF;
  EEPROM.put(addr, data); // optional (remove/comment when run once)
}

void loop() {
  Serial.print("loop ");
  EEPROM.get(addr, data);
  addr += sizeof(data);
  Serial.printlnf("%06d: 0x%04x", addr, data);
  if (addr >= EEPROM.length()) {
      addr = 0;
      delay(1000);
  }
  else
    delay(10);
}

See here

1 Like