From efbd228f8a0d2a7f8d7745a85b296b28be34a2f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Tue, 26 Mar 2019 18:07:22 +0100 Subject: [PATCH] I2C: don't clear ADDR after select to check if the slave has successfully been selected to read or write and the master is in the corresponding receive or transmit state, SR2 was checked. but reading SR2 also cleared the ADDR bit, starting the read/write transaction. the check is done in the read/write methods anyway. --- lib/i2c_master.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/i2c_master.c b/lib/i2c_master.c index f5373be..a8ab448 100644 --- a/lib/i2c_master.c +++ b/lib/i2c_master.c @@ -403,16 +403,7 @@ enum i2c_master_rc i2c_master_select_slave(uint32_t i2c, uint16_t slave, bool ad } } } - if (write) { - if (!((I2C_SR2(i2c) & I2C_SR2_TRA))) { // verify we are in transmit mode (and read SR2 to clear ADDR) - return I2C_MASTER_RC_NOT_TRANSMIT; - } - } else { - if ((I2C_SR2(i2c) & I2C_SR2_TRA)) { // verify we are in read mode (and read SR2 to clear ADDR) - return I2C_MASTER_RC_NOT_RECEIVE; - } - } - + // do not check I2C_SR2_TRA to verify if we really are in transmit or receive mode since reading SR2 also clears ADDR and starting the read/write transaction return I2C_MASTER_RC_NONE; }