0
\$\begingroup\$

I am using 24AA16 EEPROM to store my data. I have write the code for read and write using STM32Cube IDE. I am using Nucleo-F410RB Dev board. Below code is for write,

    uint8_t data_write[EEPROM_PAGESIZE] = "Hello"; // Data to be written

       // Example write operation
       printf("Writing data to EEPROM...\r\n");
       s = HAL_I2C_Mem_Write(&hi2c1, EEPROM_ADDRESS, 0x0000, I2C_MEMADD_SIZE_16BIT, data_write, EEPROM_PAGESIZE, HAL_MAX_DELAY);
       HAL_Delay(50);
       if (s == HAL_OK) {
           printf("Data write successful.\r\n");
       } else {
           printf("Data write failed.\r\n");
           Error_Handler();
       }

The page size and address for this EEPROM is,

EEPROM_PAGESIZE = 16 //in bytes
EEPROM_ADDRESS = 0xA0

And below is the code for Read,

 uint8_t data_read[EEPROM_PAGESIZE];  // Data to be read

// Example read operation
     printf("Reading data from EEPROM...\r\n");
     r = HAL_I2C_Mem_Read(&hi2c1, EEPROM_ADDRESS, 0x0000, I2C_MEMADD_SIZE_16BIT, data_read, 
    EEPROM_PAGESIZE, HAL_MAX_DELAY);
     //HAL_Delay(50);
     if (r == HAL_OK) {
         printf("Data read successful: %s\r\n", data_read);
     } else {
         printf("Data read failed.\r\n");
         Error_Handler();
     }

But read write operations can't done! Can anyone guide me to solve this issue? I am new to STM32Cube IDE!

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

The chip does not use 16-bit addresses so that's wrong. Use 8-bit addresses.

When writing, what likely happens is that when you write two address bytes, they are both 0x00, so the first memory location contains a null to terminate the string.

When doing a read, what likely happens is that chip gets one correct address byte and then it gets data into write buffer, but it does not write it due to restart condition instead of stop. So it returns what you wrote to address 0, but the first byte is 0x00 so it is an empty string.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.