From 72c7cedf1219e2ced25774d69d03414f1f739a8b Mon Sep 17 00:00:00 2001 From: Bradley Scott Date: Thu, 23 Mar 2017 10:54:59 -0400 Subject: [PATCH] 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. --- targets/TARGET_STM/i2c_api.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/targets/TARGET_STM/i2c_api.c b/targets/TARGET_STM/i2c_api.c index e2ce23def3..23e4fa6d13 100644 --- a/targets/TARGET_STM/i2c_api.c +++ b/targets/TARGET_STM/i2c_api.c @@ -904,7 +904,10 @@ void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c){ #if DEVICE_I2CSLAVE /* restore slave address */ - i2c_slave_address(obj, 0, address, 0); + if (address != 0) { + obj_s->slave = 1; + i2c_slave_address(obj, 0, address, 0); + } #endif /* Keep Set event flag */