Skip to content

Commit 3453063

Browse files
bcostmadbridge
authored andcommitted
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.
1 parent b44bf98 commit 3453063

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

targets/TARGET_STM/i2c_api.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,17 @@ int i2c_stop(i2c_t *obj)
590590
#endif
591591
// Disable reload mode
592592
handle->Instance->CR2 &= (uint32_t)~I2C_CR2_RELOAD;
593+
594+
// Ensure the transmission is started before sending a stop
595+
if ((handle->Instance->CR2 & (uint32_t)I2C_CR2_RD_WRN) == 0) {
596+
timeout = FLAG_TIMEOUT;
597+
while (!__HAL_I2C_GET_FLAG(handle, I2C_FLAG_TXIS)) {
598+
if ((timeout--) == 0) {
599+
return I2C_ERROR_BUS_BUSY;
600+
}
601+
}
602+
}
603+
593604
// Generate the STOP condition
594605
handle->Instance->CR2 |= I2C_CR2_STOP;
595606

0 commit comments

Comments
 (0)