Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Lance Henderson
#21291 Hi,

Background
I am currently trying to run some tests on the deep sleep capabilities of the ESP8266. I am measuring the current used in the various different type of wake up modes.

To do this I am saving the previous deep sleep state into EEPROM. Each time the setup code is run is reads the variable in address location 0 on the EEPROM, toggles it and writes it back to the EEPROM and then calls the deepSleep command.

The device I am using is a NodeMCU prototyping device.

Problem
The problem occurs on deep sleep reset. When this happens the variable read from the EEPROM memory is incorrect - is usually is some random number between 0-255. The numbers 13, 19, 238 and 255 are common but not always.

If the reset button on the device is used as the reset then the EEPROM memory will be toggled correctly.

If I press the reset while the device is in deepSleep the same problem happens.

Question
My guess is that is has something to do with the way that memory is handled during deepSleep.
Does anyone know what happens with the memory on a deepSleep?
Does the EEPROM memory location change?

Code
Here is the setup function for the firmware.

Code: Select allvoid setup() {
  int state;
 
  // Serial
  Serial.begin(115200);
  delay(10);
 
  // Start Memory
  EEPROM.begin(512);
  delay(10);
 
  // Get the current state
  state = EEPROM.read(0);
 
  // Print
  Serial.print("\n\n\n\n\nState ");
  Serial.println(state);
  Serial.println("\n\n\n\n\n");
  delay(10);
 
  // Toggle the EEPROM state
  if (state > 0)
  {
    EEPROM.write(0,0);
  } else {
    EEPROM.write(0,1);
  }
 
  // Commit the EEPROM
  EEPROM.commit();
  delay(500*10);
 
 
  Serial.println("Deep Sleep");
  // Depending on state we do different things
  if (state)
  {
    ESP.deepSleep(2*1000*1000);
  } else {
    ESP.deepSleep(2*1000*1000);
  }

}
User avatar
By cal
#21956 Moin Lance,

from what I read so far espduino uses the EEPROM api to write to the flash memory.
Parts of that flash are used for program code, wifi configuration, probably a spiffs filesystem if you use any.
You can read it from the outside using e.g. esptool.py.
I would take a look at the doc of espduino or the sourcecode of it's eeprom implementation to see how it is mapped.
If you dont't need much memory to survive a reboot you could also use some part of rtc user memory.
See memory map in wiki or use the sdk function to read/write it.

Cal