Skip to main content
Graduate II
January 30, 2025
Solved

STM32F411RE I2C Write/Read an External EEPROM Memory 24LC1025

  • January 30, 2025
  • 2 replies
  • 1196 views

Hello community :)

I need help using the EEPROM Memory 24LC1025.

I've this address for the 24LC1025 EEPROM ( A0 = 0, A1 = 0 and A2 = 1). And I'm trying to write/read on the data address range 10000h-1FFFFh but I'm not able to, when I try to do anything in this sector it rollovers to the data address range 0000h-FFFFh and I haven't figured out why.

Here's part of my code:

I2C_HandleTypeDef hi2c1;

uint8_t dataread[127];

int main(void)
{
 HAL_Init();
 SystemClock_Config();
 MX_GPIO_Init();
 MX_DMA_Init();
 MX_I2C1_Init();
 MX_USART6_UART_Init();

 HAL_I2C_Mem_Read(&hi2c1, 0x54<<1, 0x0000, I2C_MEMADD_SIZE_16BIT, dataread, sizeof(dataread), 1000);
 HAL_UART_Transmit(&huart6, dataread, sizeof(dataread), HAL_MAX_DELAY);

 while (1)
 {
 }
}

I've modified the Mem_Read function incresing MemAddress from uint16_t to uint32_t because I wasn't able to reach one of the higher addresses.

In the datasheet the method of accesing different blocks of memory or different sectors is by modifying (setting or clearing) a "bit block", is there a way of doing this using the HAL? Where should I look to modify the content of the bytes sent to the I2C device to set or clear the bit block?

    This topic has been closed for replies.
    Best answer by TDK

    The 16th bit of the address is B0 which is part of the slave address.

    TDK_0-1738281973574.png

     

    To write to 0x10000 and above, use the slave address 0b1010100 << 1.

    To write below that, use the slave address 0b1010000 << 1.

    2 replies

    TDKAnswer
    Super User
    January 31, 2025

    The 16th bit of the address is B0 which is part of the slave address.

    TDK_0-1738281973574.png

     

    To write to 0x10000 and above, use the slave address 0b1010100 << 1.

    To write below that, use the slave address 0b1010000 << 1.

    Graduate II
    January 31, 2025

    Thank you so much for your help. :) @TDK 

    Graduate II
    January 31, 2025

    You didn't need to modify the HAL_I2C_Mem_Read function as 16bit address works.

    You need to read a little bit more about the Block bit B0. It selects the 2 blocks that are available on that EEPROM. 

    If B0 = 0, then you are accessing address 0-0xFFFF. 
    If B0 = 1, then you are accessing address 10000-1FFFF. So if you pass 0x800 for the memory address, you're actually reading address 0x10800.

     

    If B0 = 0, then control byte (slave address) is 0x50.

    If B0 = 1, then control byte (slave address) is 0x54

     

    Graduate II
    January 31, 2025

    Thank you very much for your help @Karl Yamashita. Also your solution is very accurate and very informative. :)