Arduino Uno - EEPROM locations not consistant -
i trying write items eeprom , later read them out. finding reading not getting same put in @ times. narrow down example can show you. below read variables 2 address.
const int start_add_type = (eeprom.length() - 10); const int start_add_id = (eeprom.length() - 4);
i @ value (via rs232)
serial.begin(9600); serial.println(start_add_type); serial.println(start_add_id);
of them @ start of setup() , see get
1014 1020
i again @ end
serial.println(start_add_type); serial.println(start_add_id);
and get
1014 818
i cannot see why should change. did try calling them const e.g. const
const int start_add_type = (eeprom.length() - 10); const int start_add_id = (eeprom.length() - 4);
but gave same result. here sit puzzled @ must have missed. got idea?
#include "eeprom.h" int start_add_type = (eeprom.length() - 10); int start_add_id = (eeprom.length() - 4); char id[7] = "encpg2"; char stored_id[5]; char input[10]; //string type; void setup() { serial.begin(9600); serial.println(start_add_type); serial.println(start_add_id); // start_add = (eeprom.length() - 10); // use method pcb independent. (int = 0; < 6; i++) { stored_id[i] = eeprom.read(start_add_type + i); // read id eeprom. } if (stored_id != id) // check if 1 have got same 1 in code id[7] { (int = 0; < 6; i++) { eeprom.write(start_add_type + i, id[i]); // write id eeprom. } } serial.println(start_add_type); serial.println(start_add_id); } void loop() { }
you overwriting memory in loop:
for (int = 0; < 6; i++) { stored_id[i] = eeprom.read(start_add_type + i); }
stored_id array 5 bytes long, writing stored_id[5] rewrite start_add_id variable, weird value 818, equals 0x0332 hex , 0x32 '2' character of id
for fixing issue, declare stored_id in way:
char stored_id[6];
Comments
Post a Comment