Hello. I am writing my own EEPROM wrapper for ESP32. I want to implement wear leveling and write data in chunks. I have created a .c and .h files for my library and implement a eeprom_rotate class where I have all my methods.
I want to pass an array of data to a function and then the function would put all the data in the EEPROM. Please see the following
// size of eeprom must be dividable by chunk_size
eeprom_rotate::eeprom_rotate(size_t size_of_eeprom, size_t chunk_size) {
EEPROM.begin(size_of_eeprom);
Serial.println("the class constructor has been created");
this->size_of_eeprom = size_of_eeprom;
this->chunk_size = chunk_size;
}
void eeprom_rotate::write_to_chunk(size_t chunk, uint8_t* data_to_write, size_t size_of_array){
EEPROM.put(chunk,data_to_write);
Serial.println("printing after put");
for(int i = 0; i<size_of_eeprom;i++){
Serial.println(EEPROM.read(i));
}
}
I am callings functions in my main arduino .ino file as following:
eeprom_rotate eeprom1(50,10);
uint8_t data_buffer[10] = {1,2,3,4,5,6,7,8,9,10};
Serial.print("size of data buffer =");
Serial.println(sizeof(data_buffer));
eeprom1.write_to_chunk(0,data_buffer,10);
But the result is not as expected:
printing after put
130
31
251
63
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
However, if I create an array in my eeprom_write_chunk method , it works as expected which proves that EEPROM is working fine.
void eeprom_rotate::write_to_chunk(size_t chunk, uint8_t* data_to_write, size_t size_of_array){
//create array inside here
int array1[10] = {1,2,3,4,5,6,7,8,9,10};
EEPROM.put(chunk, array1);
Serial.println("printing after put");
for(int i = 0; i<size_of_eeprom;i++){
Serial.println(EEPROM.read(i));
}
}
Please can someone help me understand what is happening that causes that?