I2C EEPROM 24LC16b, 24LC65 problem ...
Hello,
I have a problem with I2C eeprom 24LC16b and also with 24LC65. Altough the internal buffer is 16 bytes I can sent at once only 15 bytes (14 characters + 1 null char) and the same is aslo for 24LC65 (Instead of 64 I can store only 63 chars at once = 62 chars + 1 null char).
I use HAL drivers. All the initialization code is created by CubeMX. I tried with internall pull ups and also with external 4.7K pul-ups.
Bellow is a snippet from my code inside main function.
Bellow is also a screenshot from my serial (UART) program, where you can see results readed from my EEPROM 24LC16b when I store "12345678901234", "123456789012345", "1234567890123456". "12345678901234567", "123456789012345678", "1234567890123456789" respectively.
We can see that when the length of the string is greater than 16 chars remaining characters go to the begining of the EEPROM buffer. That seems OK but where does go character 16 (second output bellow) - buffer is 16 bytes long)!? When I used 24LC65 the same occours after 64 character but character 64 is missing as it was for output 2 bellow).
Look at the last picture bellow (outputs). The first output is OK (we can also see the last null character). In the 3rd output (I store 17 chars into eeprom) null character rotate to the first location and owerwrite 1 (that's OK), but where did null go in the 2nd output. When I store 16 characters the last character e (and other last characters from later outputs where I store more than 16 characters) wasn't written by our program => so it is something old data from the memory; that's also OK).
Thanks for help!
char writeStr[] = "12345678901234"; //14 bytes + 1 for "null" = 15 chars
char readStr[200]; //Here I want to read a string from I2C eeprom
//memory location address
uint16_t MemAddress = 0x0;
//I2c device address =(0x50<<1) = A0
uint16_t i2cAddress = (uint16_t)(0x50<<1);
//write into I2C eeprom
HAL_I2C_Mem_Write(&hi2c2, i2cAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, (uint8_t*)writeStr,strlen(writeStr)+1, HAL_MAX_DELAY);
//wait until internal write is finished ...
while(HAL_I2C_IsDeviceReady(&hi2c2, i2cAddress, 1, HAL_MAX_DELAY) != HAL_OK);
HAL_I2C_Mem_Read(&hi2c2, i2cAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, (uint8_t*)readStr,strlen(writeStr)+1, HAL_MAX_DELAY);
//test 1: string from EEPROM send to PC through UART
HAL_UART_Transmit(&huart1, (uint8_t*)readStr, strlen(writeStr)+1, HAL_MAX_DELAY);
//test 2: if string from EEPROM equals writeStr => turn on LED
if(strcmp(writeStr, readStr) == 0) {
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);
}
Results:

