Skip to main content
parth kothiya
Associate III
December 30, 2021
Solved

I2C EEPROM 24C08 read write uint16_t and uint32_t?

  • December 30, 2021
  • 3 replies
  • 1972 views

how to read write i2c eeprom using HAL_I2C_Mem_Read and HAL_I2C_Mem_Write function.

how to convert uint16_t to uint8_t and uint32_t to uint8_t

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

HAL_I2C_Mem_Read( &hi2c1,IIC_ReadAddr, 10, I2C_MEMADD_SIZE_8BIT, process_read_buf, 2, 1000 );//read uint16_t command

HAL_I2C_Mem_Read( &hi2c1,IIC_ReadAddr, 10, I2C_MEMADD_SIZE_8BIT, process_read_buf, 4, 1000 );//read uint32_t command

So simple

3 replies

KnarfB
Super User
December 30, 2021

These functions take a pointer to the data, i.e.

if uint32_t x; is a variable, you supply

(uint8_t*)(&x) for the pData and

sizeof(uint32_t) for the Size parameter.

hth

KnarfB

Piranha
Principal III
December 30, 2021

The question is about basic C data types and pointers. It belongs to a school/university introductory course, not a manufacturer specific forum.

https://www.tutorialspoint.com/cprogramming/c_passing_pointers_to_functions.htm

https://www.tutorialspoint.com/cprogramming/c_type_casting.htm

aston
astonBest answer
Associate
December 31, 2021

HAL_I2C_Mem_Read( &hi2c1,IIC_ReadAddr, 10, I2C_MEMADD_SIZE_8BIT, process_read_buf, 2, 1000 );//read uint16_t command

HAL_I2C_Mem_Read( &hi2c1,IIC_ReadAddr, 10, I2C_MEMADD_SIZE_8BIT, process_read_buf, 4, 1000 );//read uint32_t command

So simple

parth kothiya
Associate III
December 31, 2021

Thanks​ works well gives exactly things I want :smiling_face_with_smiling_eyes:👍🏻