I assumed the microcontroller has 3 components as per storing data: - flash memory for the program - RAM for variables - EEPROM for non-volatile user-storage
And I always assumed those are separate chips on the board. However, working directly with a RobotDyn Uno R3 leads me to believe I may be wrong somehow.
I compiled this program:
#include <EEPROM.h> struct SettingsStruct { String server; String port; String user; String password; String description; } gSettings = { "192.168.1.6", "8080", "fci blah vlak", "zangazang4", "Extra string here" }; void setup() { Serial.begin(9600); //saveConfig(); Serial.print(F("EEPROM size is: ")); Serial.print(EEPROM.length()); Serial.print(F(" bytes")); Serial.println(""); loadConfig(); Serial.print(F("Server: ")); Serial.print(gSettings.server); Serial.println(""); Serial.print(F("Port: ")); Serial.print(gSettings.port); Serial.println(""); Serial.print(F("Username: ")); Serial.print(gSettings.user); Serial.println(""); Serial.print(F("Password: ")); Serial.print(gSettings.password); Serial.println(""); Serial.print(F("Description: ")); Serial.print(gSettings.description); } void loop() { // nope } void loadConfig() { for (unsigned int t=0; t<sizeof(gSettings); t++) *((char*)&gSettings + t) = EEPROM.read(t); } void saveConfig() { for (unsigned int t=0; t<sizeof(gSettings); t++) EEPROM.write(t, *((char*)&gSettings + t)); } Problem is that each time I add new elements to the struct, and I run the program, the serial prints different things. I recognize previously saved strings but they are right shifted, meaning that somehow the ZERO address of EEPROM might have moved backwards and previously saved strings move right and offocurse, appear on other struct variables.
This leads me to believe the actual EEPROM is related with the flash memory and depends on it on each compile. As if the ZERO address of EEPROM is established after each compile.
Can anyone confirm this or lead me to some documentation relating this? It's a weird mystery that I would like to clear out.