Skip to main content
Graduate
April 13, 2024
Question

24C16RP EEPROM INTERFACING WITH STM32G070CBT6

  • April 13, 2024
  • 2 replies
  • 4713 views

Hello all,

I am trying to interface 24C16RP EEPROM with my MCU soldered on breakout board and  it seems like the EEPROM is behaving very weird when i am trying to write and read. first of all it starts to write from position 1 not from zero of an array that i have created to store the data and i tried a lot to figure out the cause but i couldn't and the weird part is that after writing to a specific page if am trying to read any other page of the entire page address it returns the same date i have written to it. As i know this EEPROM has 16 byte of page size and 128 pages correct me if i am wrong. With that said i am attaching the cube mx code and the ioc file and some screen short for your better understanding. Please help me if you find something error in my code.

Thanks

 

 

uint8_t data_Read[16];
uint8_t data_Write[16]="1234567898765432";

int main(void)
{
 HAL_Init();
 SystemClock_Config();
 MX_GPIO_Init();
 MX_I2C1_Init();
 MX_USART1_UART_Init();

 HAL_I2C_Mem_Write(&hi2c1, 0XA0, 1, 2, data_Write, 16, 1000);
 HAL_Delay(5);
 HAL_I2C_Mem_Read(&hi2c1, 0XA0, 9, 2, data_Read, 16, 1000);
 while (1)
 {
 HAL_UART_Transmit(&huart1, data_Read, 16, 1000);
 HAL_Delay(1000);
 }
}

 

 

 

    This topic has been closed for replies.

    2 replies

    Super User
    April 13, 2024

    > HAL_I2C_Mem_Write(&hi2c1, 0XA0, 1, 2, data_Write, 16, 1000)

    As you've mentioned above the page size of this EEPROM is 16 bytes.

    What do you think will do the above code line? (write 16 bytes, from index 1) ? Is this intentional (you want to test how the wrap-around works?)

     

     

    RChou.1Author
    Graduate
    April 15, 2024

    i want to know why it starts writing from index 1 and the data which should be written on 15th place is getting written on 0th place and if i am trying to read the data of any other page it returns me the same data.

    Graduate II
    April 15, 2024

    Did You read my response?

    This Eeprom has only 1 Byte of Address, to access the full 2K array you have to put the 3 high Bit's in DevAddress ( 0xA0, will give You the first 256 Byte, 0xA2 the next 256 Byte etc.)

    Please read the datasheet.

    Martin

    Graduate II
    April 13, 2024

    I don't understand what you try to do, but reading the datsheet of the 24C16RP, You will see that this device has only a 1 Byte Address length, so the 4. parameter has to be 1. With 2 the device will write the low part of Your address to the EEPROM!

    /**
     * @brief Write an amount of data in blocking mode to a specific memory address
     * @PAram hi2c Pointer to a I2C_HandleTypeDef structure that contains
     * the configuration information for the specified I2C.
     * @PAram DevAddress Target device address: The device 7 bits address value
     * in datasheet must be shifted to the left before calling the interface
     * @PAram MemAddress Internal memory address
     * @PAram MemAddSize Size of internal memory address
     * @PAram pData Pointer to data buffer
     * @PAram Size Amount of data to be sent
     * @PAram Timeout Timeout duration
     * @retval HAL status
     */
    HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress,
     uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)

    Martin