Skip to main content
Senior III
June 10, 2026
Solved

EEPROM Read and Write Function Definition

  • June 10, 2026
  • 2 replies
  • 42 views

I am trying to interface the EEPROM AT24C04C with STM32G4 series controllers. I have confusion in the function parameters

HAL_StatusTypeDef HAL_I2C_Mem_Read_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress,
uint16_t MemAddSize, uint8_t *pData, uint16_t Size)

Can you please clarify on the MemAddSize parameter what has to be sent to for the above EEPROM?

2nd Question: 1 page is 16 bytes, is it possible for me to write data above 16 bytes as well?

 

Best answer by Pavel A.

> Can you please clarify on the MemAddSize parameter

Per the  AT24C04C data sheet, the address part of  the I2C transaction is always one byte (8 bit) - which covers 256 bytes. Extra address bit is encoded in the I2C device address. In other words,  AT24C04C occupies two I2C addresses, each holds 256 data bytes. For example, 0b1010000x and 0b1010001x. Bit 1 (mask 0x2) of the I2C address selects the half.

> is it possible for me to write data above 16 bytes as well?

Don’t think so. The data sheet says “up to 16 bytes”. To move more, use several transactions.

 

2 replies

Ozone
Principal
June 10, 2026

While I don’t use Cube / HAL, I think this is a generic I2C function, not specific for the 2404 EEPROM devices.
You will need to read the device datasheet (of the AT24C04C) to check what a write entails, and check the source code (of  HAL_I2C_Mem_Read_IT) were this parameter ends up.

> 2nd Question: 1 page is 16 bytes, is it possible for me to write data above 16 bytes as well?

Again, check with the datasheet. Here two quotes from the Microchip datasheet :

> Page Write: The 4K and 8K EEPROM devices are capable of a 16-byte Page Write.

> If more than 16 data words are transmitted to the EEPROM, the data word address will “roll over” and previous data will be overwritten.

Andrew Neil
Super User
June 10, 2026

@Ozone 

I think this is a generic I2C function, not specific for the 2404 EEPROM devices

 

This is correct.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Ozone
Principal
June 11, 2026

Since I don’t use Cube/HAL, I start with the datasheet of the device to design my own “HAL” code.

Reading the datasheets is highly recommended in general, and simply mandatory in some cases. Even if some vendor’s salesmen want to make you believe otherwise.

Pavel A.
Pavel A.Best answer
June 10, 2026

> Can you please clarify on the MemAddSize parameter

Per the  AT24C04C data sheet, the address part of  the I2C transaction is always one byte (8 bit) - which covers 256 bytes. Extra address bit is encoded in the I2C device address. In other words,  AT24C04C occupies two I2C addresses, each holds 256 data bytes. For example, 0b1010000x and 0b1010001x. Bit 1 (mask 0x2) of the I2C address selects the half.

> is it possible for me to write data above 16 bytes as well?

Don’t think so. The data sheet says “up to 16 bytes”. To move more, use several transactions.