Skip to content

Commit 2eb4048

Browse files
committed
STM32: Correct I2C master error handling
If I2C slave support is included, then the I2C error handler would always reset the I2C address, resulting in incorrectly changing the I2C state to listen for a controller configured as I2C master. This change conditionalizes the address setting to only occur if the controller was in slave mode when the error occurred.
1 parent 75f6f2d commit 2eb4048

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

targets/TARGET_STM/i2c_api.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,10 @@ void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c){
904904

905905
#if DEVICE_I2CSLAVE
906906
/* restore slave address */
907-
i2c_slave_address(obj, 0, address, 0);
907+
if (address != 0) {
908+
obj_s->slave = 1;
909+
i2c_slave_address(obj, 0, address, 0);
910+
}
908911
#endif
909912

910913
/* Keep Set event flag */

0 commit comments

Comments
 (0)