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