DeepSleep and EEPROM
Posted: Mon Jun 22, 2015 5:26 pm
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.
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 all
void 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);
}
}