uint8_t TM_I2C_Read(I2C_TypeDef* I2Cx, uint8_t address, uint8_t reg) { uint8_t received_data; TM_I2C_Start(I2Cx, address, I2C_Direction_Transmitter, 0); TM_I2C_WriteData(I2Cx, reg); TM_I2C_Stop(I2Cx); TM_I2C_Start(I2Cx, address, I2C_Direction_Receiver, 0); received_data = TM_I2C_ReadNack(I2Cx); return received_data; }
void TM_I2C_ReadMultiNoRegister(I2C_TypeDef* I2Cx, uint8_t address, uint8_t* data, uint16_t count) { uint8_t i; TM_I2C_Start(I2Cx, address, I2C_Direction_Receiver, 1); for (i = 0; i < count; i++) { if (i == (count - 1)) { //Last byte data[i] = TM_I2C_ReadNack(I2Cx); } else { data[i] = TM_I2C_ReadAck(I2Cx); } } }
void TM_I2C_ReadMulti(I2C_TypeDef* I2Cx, uint8_t address, uint8_t reg, uint8_t* data, uint16_t count) { uint8_t i; TM_I2C_Start(I2Cx, address, I2C_Direction_Transmitter, 1); TM_I2C_WriteData(I2Cx, reg); TM_I2C_Stop(I2Cx); TM_I2C_Start(I2Cx, address, I2C_Direction_Receiver, 1); for (i = 0; i < count; i++) { if (i == (count - 1)) { //Last byte data[i] = TM_I2C_ReadNack(I2Cx); } else { data[i] = TM_I2C_ReadAck(I2Cx); } } }