Page 1 of 1

ESP32 EEPROM access

Posted: Sun Sep 02, 2018 9:07 pm
by sterwen
Hello,

I am porting a SW from ATMega to ESP32 and have some difficulties with the EEPROM as apparently nothing is stored. I have added the initialization sequence

Code: Select all

 Serial.println("\nTesting EEPROM Library\n");
  if (!EEPROM.begin(EEPROM.length())) {
    Serial.println("Failed to initialise EEPROM");
    Serial.println("Restarting...");
    delay(1000);
    ESP.restart();
  }
  
But this is permanently failing. I am using an ESP32 VROOM module.
What do I miss ?

Re: ESP32 EEPROM access

Posted: Mon Sep 03, 2018 10:14 am
by boarchuz
EEPROM.length() has a default value of 0, so begin() will fail.

Two options:

Initialise an EEPROMClass and provide it with a size

Code: Select all

EEPROMClass myEeprom("eeprom",64);
if(!myEeprom.begin(myEeprom.length()))
{
    Serial.println("failed to initialise myEeprom");
}
or pass the size into EEPROM.begin()

Code: Select all

#define EEPROM_SIZE 64
if (!EEPROM.begin( EEPROM_SIZE ))
{
    Serial.println("failed to initialise EEPROM");
}
Or, even better, use the Preferences library. It's EEPROM on steroids.

Re: ESP32 EEPROM access

Posted: Mon Sep 03, 2018 3:51 pm
by sterwen
Ok, thanks. I had found the solution briefly before you post. Now everything works as expected.


I have one additional question concerning the NVS area. How to access it ?