7、同步串行总线【I2C】

常用HAL库函数:

//硬件I2C往EEPROM写数据查询方式

HAL_I2C_Mem_Write(&hi2c1,0xa0,0,I2C_MEMADD_SIZE_16BIT,wBuf,4,0xffff); 

//硬件I2C从EEPROM读数据查询方式

HAL_I2C_Mem_Read(&hi2c1,0xa0,0,I2C_MEMADD_SIZE_16BIT,rBuf,4,0xffff);

//硬件I2C往EEPROM写数据中断方式

HAL_I2C_Mem_Write_IT(&hi2c1,0xa0,0,I2C_MEMADD_SIZE_16BIT,wBuf,4);

//硬件I2C从EEPROM读数据中断方式

HAL_I2C_Mem_Read_IT(&hi2c1,0xa0,0,I2C_MEMADD_SIZE_16BIT,rBuf,4);

示例代码:

image.png 

实验验证:

image.png