1.0.1
Update:
write()method supports arbitrary address offset write over page boundary (version 1.0.0)- code simplified (version 1.0.1)
What is "write() method supports arbitrary address offset write over page boundary"?
In previous version, the byte address for multi-byte write need to be aligned to page-write size (16 bytes) boundary. From version 1.0.0, user doesn't need to care this limitation. User can write any size of data from any address.
The sample/test code of this new feature is available as examples/M24C02_test_arbitrary_address_write_over_page_boundary.
Example:
Next code is super simple version to see the difference.
It writes 50 characters of _ first and then 29 characters string is written.
#include "M24C02.h"
#include <string.h>
M24C02 eeprom;
constexpr int length = 50;
constexpr char test_str0[] = "Hello, M24C02! Is this work?";
char clear0[length];
char s[length];
void show_data(uint8_t *dp, int data_length) {
char s[2] = { 0 };
Serial.print(">> ");
for (int i = 0; i < data_length; i++) {
*s = *dp++;
Serial.print(s);
}
Serial.println("");
}
void setup() {
Serial.begin(9600);
while (!Serial)
;
Wire.begin();
Serial.println("\n***** Hello, M24C02! *****");
memset(clear0, '_', sizeof(clear0));
clear0[sizeof(clear0) - 1] = '\0';
eeprom.write( 0, (uint8_t *)clear0, sizeof(clear0));
eeprom.write( 8, (uint8_t *)test_str0, sizeof(test_str0));
eeprom.read(0, (uint8_t *)s, length);
Serial.println("read back from EEPROM :");
show_data((uint8_t *)s, length);
}
void loop() {
}In previous version (0.9.0), the read back data shows the data is corrupted because the address were not aligned to page-write size.
***** Hello, M24C02! *****
read back from EEPROM :
>> 24C02! IHello, Mork?___s this w_________________
Now in version 1.0.1 😃
***** Hello, M24C02! *****
read back from EEPROM :
>> ________Hello, M24C02! Is this work?____________