mirror of https://github.com/ARMmbed/mbed-os.git
STM32: Fix I2C stop condition
Need to ensure the transmission has been started before sending a STOP condition. Issue found on the NUCLEO_H743ZI due certainly to the high-speed clock used. But this is normally needed also on all STM32 devices using the I2C peripheral version 2.pull/8280/head
parent
f1587b50d7
commit
9cade872db
|
@ -590,6 +590,17 @@ int i2c_stop(i2c_t *obj)
|
|||
#endif
|
||||
// Disable reload mode
|
||||
handle->Instance->CR2 &= (uint32_t)~I2C_CR2_RELOAD;
|
||||
|
||||
// Ensure the transmission is started before sending a stop
|
||||
if ((handle->Instance->CR2 & (uint32_t)I2C_CR2_RD_WRN) == 0) {
|
||||
timeout = FLAG_TIMEOUT;
|
||||
while (!__HAL_I2C_GET_FLAG(handle, I2C_FLAG_TXIS)) {
|
||||
if ((timeout--) == 0) {
|
||||
return I2C_ERROR_BUS_BUSY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate the STOP condition
|
||||
handle->Instance->CR2 |= I2C_CR2_STOP;
|
||||
|
||||
|
|
Loading…
Reference in New Issue