Hello Belaya,
The following is a I2C read and write example on STM32F401, you could refer it.
uint8_t GTXBuffer[256];
int8_t SensorAPI_I2Cx_Read(uint8_t slave_address7, uint8_t subaddress, uint8_t *pBuffer, uint16_t ReadNumbr) { uint16_t DevAddress = slave_address7 << 1;
// send register address HAL_I2C_Master_Transmit(&I2C_HANDLE, DevAddress, &subaddress, 1, BUS_TIMEOUT); HAL_I2C_Master_Receive(&I2C_HANDLE, DevAddress, pBuffer, ReadNumbr, BUS_TIMEOUT); return 0; }
int8_t SensorAPI_I2Cx_Write(uint8_t slave_address7, uint8_t subaddress, uint8_t *pBuffer, uint16_t WriteNumbr) { uint16_t DevAddress = slave_address7 << 1;
GTXBuffer[0] = subaddress; memcpy(>XBuffer[1], pBuffer, WriteNumbr);
// send register address HAL_I2C_Master_Transmit(&I2C_HANDLE, DevAddress, GTXBuffer, WriteNumbr+1, BUS_TIMEOUT); return 0; }
... View more