uint16_t i2c_reg_read(uint8_t regAddr) { uint16_t dat; i2c_start(); i2c_send_byte(I2C_INA_ADDR << 1 | I2C_WRITE_CMD); i2c_send_byte(regAddr); i2c_repeat_start(); i2c_send_byte(I2C_INA_ADDR << 1 | I2C_READ_CMD); dat = i2c_read_byte(1) << 8; dat |= i2c_read_byte(1); i2c_stop(); return dat; }
bool cComm_I2C::Receive(uint8_t u8Address, uint8_t *u8ptrData, uint8_t u8Size) { i2c_start(); i2c_write(m_u8DeviceAddress, I2C_STATUS_CODE_SLA_W_TXD_ACK_RXD); i2c_write(u8Address, I2C_STATUS_CODE_DATA_TXD_ACK_RXD); i2c_repeat_start(); i2c_write(m_u8DeviceAddress|0x01, I2C_STATUS_CODE_SLA_R_TXD_ACK_RXD); u8Size--; while (u8Size--) { *u8ptrData++ = i2c_write(0xFF, I2C_STATUS_CODE_DATA_RXD_ACK_TXD); } *u8ptrData++ = i2c_write(0xFF, I2C_STATUS_CODE_DATA_RXD_NOACK_TXD); i2c_stop(); return true; }