From 42f643c40fea2f690da5ab2f4509eeaf47435108 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 20 Sep 2020 17:05:36 +1000 Subject: [PATCH] Update I2C_Wrapper.cpp --- .../TS100/Core/BSP/Pine64/I2C_Wrapper.cpp | 39 ++----------------- 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/workspace/TS100/Core/BSP/Pine64/I2C_Wrapper.cpp b/workspace/TS100/Core/BSP/Pine64/I2C_Wrapper.cpp index a407f21e..8834944b 100644 --- a/workspace/TS100/Core/BSP/Pine64/I2C_Wrapper.cpp +++ b/workspace/TS100/Core/BSP/Pine64/I2C_Wrapper.cpp @@ -228,9 +228,7 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData for (count = 0; count < Size; count++) { pData[count] = i2c_byte_read(count == (Size - 1)); } - - /* if not sequential write, then send stop */ - + //Have nacked last data, so have to generate the stop sequence i2c_stop(); unlock(); return true; @@ -376,39 +374,8 @@ bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { } bool FRToSI2C::probe(uint16_t DevAddress) { - if (!lock()) - return false; - i2c_start(); - /* send slave address to I2C bus */ - i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER); - /* wait until ADDSEND bit is set */ - int timeout = FLAG_TIMEOUT; - while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { - if (i2c_flag_get(I2C0, I2C_FLAG_AERR) || i2c_flag_get(I2C0, I2C_FLAG_BERR)) { - i2c_stop(); - unlock(); - return false; - } - if (timeout-- == 0) { - i2c_stop(); - unlock(); - return false; - } - } - - /* clear ADDSEND bit */ - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - /* wait until the transmit data buffer is empty */ - while (!i2c_flag_get(I2C0, I2C_FLAG_TBE)) - ; - bool no_ack = i2c_flag_get(I2C0, I2C_FLAG_AERR); - /* send a stop condition to I2C bus */ - i2c_stop_on_bus(I2C0); - /* wait until stop condition generate */ - while (I2C_CTL0(I2C0) & 0x0200) - ; - unlock(); - return !no_ack; + uint8_t temp = 0; + return Mem_Read(DevAddress, 0x00, &temp, 1); } void FRToSI2C::I2C_Unstick() {