From f1c078c7218933535fb49f9b74968ccaf6ae66d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Tue, 2 May 2017 17:18:20 +0200 Subject: [PATCH] minor fix --- lib/i2c_master.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/i2c_master.c b/lib/i2c_master.c index 718bdfd..52a9463 100644 --- a/lib/i2c_master.c +++ b/lib/i2c_master.c @@ -99,10 +99,10 @@ bool i2c_master_read(uint8_t slave, const uint8_t* address, size_t address_size, // sanity check if (address==NULL || address_size==0 || data==NULL || data_size==0) { // input data is erroneous return false; - } + } if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_BUSY) { // I2C device is busy return false; - } + } if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_MSL) { // I2C device is already in master mode return false; } @@ -201,9 +201,6 @@ bool i2c_master_read(uint8_t slave, const uint8_t* address, size_t address_size, to_return = true; error: - if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_BUSY) { // release bus if busy -// i2c_send_stop(I2C(I2C_MASTER_I2C)); // send stop to release bus - } i2c_send_stop(I2C(I2C_MASTER_I2C)); // send stop to release bus timer_set_counter(TIM(I2C_MASTER_TIMER),0); // restart timer timer_clear_flag(TIM(I2C_MASTER_TIMER), TIM_SR_UIF); // clear flag @@ -221,10 +218,10 @@ bool i2c_master_write(uint8_t slave, const uint8_t* address, size_t address_size // sanity check if (address==NULL || address_size==0 || data==NULL || data_size==0) { // input data is erroneous return false; - } + } if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_BUSY) { // I2C device is busy return false; - } + } if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_MSL) { // I2C device is already in master mode return false; } @@ -293,9 +290,7 @@ bool i2c_master_write(uint8_t slave, const uint8_t* address, size_t address_size to_return = true; error: - if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_BUSY) { // release bus if busy - i2c_send_stop(I2C(I2C_MASTER_I2C)); // send stop to release bus - } + i2c_send_stop(I2C(I2C_MASTER_I2C)); // send stop to release bus timer_set_counter(TIM(I2C_MASTER_TIMER),0); // restart timer timer_clear_flag(TIM(I2C_MASTER_TIMER), TIM_SR_UIF); // clear flag timer_enable_counter(TIM(I2C_MASTER_TIMER)); // enable timer for timeouts