i2c_master: fix stop generation

This commit is contained in:
King Kévin 2020-12-16 02:42:34 +01:00
parent 99593b92d0
commit 69787f1714
1 changed files with 4 additions and 2 deletions

View File

@ -210,7 +210,7 @@ enum i2c_master_rc i2c_master_stop(void)
if (!(I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_BUSY)) { // release is not busy
return I2C_MASTER_RC_NONE; // bus has probably already been released
}
if (I2C_CR1(I2C(I2C_MASTER_I2C)) & (I2C_CR1_START | I2C_CR1_STOP)) { // ensure start or stop operations are not in progress
if (I2C_CR1(I2C(I2C_MASTER_I2C)) & (I2C_CR1_START)) { // ensure start is not in progress
return I2C_MASTER_RC_START_STOP_IN_PROGESS;
}
@ -218,7 +218,9 @@ enum i2c_master_rc i2c_master_stop(void)
i2c_disable_ack(I2C(I2C_MASTER_I2C)); // disable ACK to be able to close the communication
}
i2c_send_stop(I2C(I2C_MASTER_I2C)); // send stop to release bus
if (!(I2C_CR1(I2C(I2C_MASTER_I2C)) & (I2C_CR1_STOP))) { // ensure stop operations is not in progress
i2c_send_stop(I2C(I2C_MASTER_I2C)); // send stop to release bus
}
return i2c_master_wait_stop();
}