Hello. I have a program where I must save some data to EEPROM before every reset cycle and I sucessfully write 14 bytes like that:
I write 3 values to the EEPROM:
quantity - 2 bytes
serial_number -10 bytes
device_id - 2 bytes
Therefore 14 bytes in total
For the following example, I am not writing anything to the first 12 bytes ( quantity and serial_number), but only value 2 to the device_id

After writing value 2 to the device id, I can confrim that it is sucesfully written as you can see from above.
After a reset, I must read back the values that I have written, however, I am not able to sucessfully read back the value from the EEPROM:
All I do, is :
EEPROM.get(12,SLAVE_ID);
Serial.print("SLAVE ID after get = ");
Serial.println(SLAVE_ID);
and the result is:

If I write value 4, it will read back:

Can someone help me understand what is going on here with my EEPROM?
Code:
void write_14_byte_chunks(int eeprom_pointer){
if (item_inside.quantity != last_quantity || NEW_SLAVE_ID != SLAVE_ID || strcmp (item_inside.serial,last_serial) != 0){
Serial.println("There is a mismatch between old and new variables, writing EEPROM");
int new_eeprom_pointer = (eeprom_pointer*14) ;
if(item_inside.quantity == 0 )
EEPROM.writeUShort(new_eeprom_pointer, 65535); //This will wryte 2 byte number
else
EEPROM.writeUShort(new_eeprom_pointer, item_inside.quantity); //This will wryte 2 byte number
new_eeprom_pointer += sizeof(unsigned short);// increment addr by 2
Serial.print("Address after writing quantity=");
Serial.println(new_eeprom_pointer);
EEPROM.writeString(new_eeprom_pointer, item_inside.serial);// this will write 10 byte string
new_eeprom_pointer += 10;
Serial.print("Address after writing Serial=");
Serial.println(new_eeprom_pointer);
if(NEW_SLAVE_ID == 0){
EEPROM.write(new_eeprom_pointer, 65535);
Serial.println("Writing 0xff to eeprom");
}
else{
EEPROM.write(new_eeprom_pointer, NEW_SLAVE_ID);
new_eeprom_pointer += sizeof(unsigned short);;// increment addr by 2
Serial.print("Address after writing slave id=");
Serial.println(new_eeprom_pointer);
}
EEPROM.commit();
}
else
Serial.println("No need to write eeprom");
}
I write 3 values to the EEPROM:
quantity - 2 bytes
serial_number -10 bytes
device_id - 2 bytes
Therefore 14 bytes in total
For the following example, I am not writing anything to the first 12 bytes ( quantity and serial_number), but only value 2 to the device_id

After writing value 2 to the device id, I can confrim that it is sucesfully written as you can see from above.
After a reset, I must read back the values that I have written, however, I am not able to sucessfully read back the value from the EEPROM:
All I do, is :
EEPROM.get(12,SLAVE_ID);
Serial.print("SLAVE ID after get = ");
Serial.println(SLAVE_ID);
and the result is:

If I write value 4, it will read back:

Can someone help me understand what is going on here with my EEPROM?