Merge pull request #8280 from bcostm/fix_i2c_stop

STM32: Fix I2C stop condition
pull/7948/head
Cruz Monrreal 2018-10-08 10:23:38 -05:00 committed by GitHub
commit 8fd99449c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -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;