From 9ff56d316c3b8646b9487562e947bd91929006fb Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Wed, 21 Sep 2016 17:00:28 +0100 Subject: [PATCH] I2C error count fix, as per Cleanflight PR 2310 (#624) --- src/main/drivers/bus_i2c_stm32f10x.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/drivers/bus_i2c_stm32f10x.c b/src/main/drivers/bus_i2c_stm32f10x.c index b72b30720..59a7eda9a 100644 --- a/src/main/drivers/bus_i2c_stm32f10x.c +++ b/src/main/drivers/bus_i2c_stm32f10x.c @@ -170,7 +170,7 @@ bool i2cWriteBuffer(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t len_, if (!(I2Cx->CR2 & I2C_IT_EVT)) { // if we are restarting the driver if (!(I2Cx->CR1 & I2C_CR1_START)) { // ensure sending a start while (I2Cx->CR1 & I2C_CR1_STOP && --timeout > 0) {; } // wait for any stop to finish sending - if (timeout == 0) + if (state->error || timeout == 0) return i2cHandleHardwareFailure(device); I2C_GenerateSTART(I2Cx, ENABLE); // send the start for the new job } @@ -179,10 +179,10 @@ bool i2cWriteBuffer(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t len_, timeout = I2C_DEFAULT_TIMEOUT; while (state->busy && --timeout > 0) {; } - if (timeout == 0) + if (state->error || timeout == 0) return i2cHandleHardwareFailure(device); - return !(state->error); + return true; } bool i2cWrite(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t data) @@ -219,7 +219,7 @@ bool i2cRead(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t len, uint8_t if (!(I2Cx->CR2 & I2C_IT_EVT)) { // if we are restarting the driver if (!(I2Cx->CR1 & I2C_CR1_START)) { // ensure sending a start while (I2Cx->CR1 & I2C_CR1_STOP && --timeout > 0) {; } // wait for any stop to finish sending - if (timeout == 0) + if (state->error || timeout == 0) return i2cHandleHardwareFailure(device); I2C_GenerateSTART(I2Cx, ENABLE); // send the start for the new job } @@ -228,10 +228,10 @@ bool i2cRead(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t len, uint8_t timeout = I2C_DEFAULT_TIMEOUT; while (state->busy && --timeout > 0) {; } - if (timeout == 0) + if (state->error || timeout == 0) return i2cHandleHardwareFailure(device); - return !(state->error); + return true; } static void i2c_er_handler(I2CDevice device) {