ESP32 EEPROM access

sterwen
Posts: 6
Joined: Sun Sep 02, 2018 12:17 pm

ESP32 EEPROM access

Postby sterwen » Sun Sep 02, 2018 9:07 pm

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 ?

boarchuz
Posts: 605
Joined: Tue Aug 21, 2018 5:28 am

Re: ESP32 EEPROM access

Postby boarchuz » Mon Sep 03, 2018 10:14 am

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.

sterwen
Posts: 6
Joined: Sun Sep 02, 2018 12:17 pm

Re: ESP32 EEPROM access

Postby sterwen » Mon Sep 03, 2018 3:51 pm

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 ?

Who is online

Users browsing this forum: No registered users and 52 guests