Problem while working with EEPROM.
----------------------------- Delete below -----------------------------
Basic Infos
- [x] This issue complies with the issue POLICY doc.
- [x] I have read the documentation at readthedocs and the issue is not addressed there.
- [x] I have tested that the issue is present in current master branch (aka latest git).
- [x] I have searched the issue tracker for a similar issue.
- [x] If there is a stack dump, I have decoded it.
- [x] I have filled out all fields below.
Platform
- Hardware: [ESP-12 device]
- Core Version: [Core:2.5.2=20502000]
- Development Env: [Arduino IDE]
- Operating System: [Windows]
Settings in IDE
- Module: [Generic ESP8266 Module]
- Flash Mode: [dio]
- Flash Size: [4MB]
- lwip Variant: [v2 Lower Memory]
- Reset Method: [ck]
- Flash Frequency: [40Mhz]
- CPU Frequency: [80Mhz]
- Upload Using: [SERIAL]
- Upload Speed: [115200]
Problem Description
When writing values to the EEPROM and reading them later, the data is different. The sketch gives an example of such a problem. First I read and display data from EEPROM cells, then I try to fill them in and read again. What the cells should be filled with differs from what is stored in them.
MCVE Sketch
#ifdef DEBUG_ESP_PORT
#define DEBUG_MSG(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )
#else
#define DEBUG_MSG(...)
#endif
#include "src/EEPROM.h"
void setup() {
Serial.begin(115200);
EEPROM.begin(200);
init_eeprom_first_time ();
}
void loop() {
}
void init_eeprom_first_time () {
int lsize = 100;
Serial.println();
Serial.print("lsize in init eeprom proc: ");
Serial.println(lsize);
Serial.print("EEPROM.length: ");
Serial.println(EEPROM.length());
Serial.println("EEPROM before filling out:");
for (int i = 0; i < lsize; i++) {
Serial.print(" >");
Serial.print(EEPROM.read(i));
Serial.print("< ");
}
Serial.println();
if (EEPROM.read(0) != 42) {
EEPROM.begin(1);
for (int i = 0; i < lsize; i++) {
EEPROM.write(i, 23);
}
EEPROM.write(0, 43);
EEPROM.write(2, 42);
EEPROM.write(5, 42);
EEPROM.write(10, 42);
EEPROM.write(15, 42);
EEPROM.commit();
Serial.println("EEPROM after filling out:");
for (int i = 0; i < lsize; i++) {
Serial.print(" >");
Serial.print(EEPROM.read(i));
Serial.print("< ");
}
Serial.println();
DEBUG_MSG("bootup...\n");
}
EEPROM.end();
}
Debug Messages
SDK:2.2.1(cfd48f3)/Core:2.5.2=20502000/lwIP:STABLE-2_1_2_RELEASE/glue:1.1-7-g82abda3/BearSSL:a143020
lsize in init eeprom proc: 100
EEPROM.length: 200
EEPROM before filling out:
>43< >23< >42< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255< >255<
EEPROM after filling out:
>43< >23< >42< >23< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< >0< bootup...
You only need one EEPROM.begin() line. What's that second one doing there?
You are setting the EEPROM size to 1 byte with EEPROM.begin(1) and also ignoring the return values for the different EEPROM.xxx calls.
See the EEPROM example for the proper way to do this, and for further questions please use https://esp8266.com for help with coding problems not related to core issues.