Skip to content

Commit 9895bcf

Browse files
committed
STM32 I2C: restore slave address in case of reset
1 parent ce9d252 commit 9895bcf

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

targets/TARGET_STM/i2c_api.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,12 +751,24 @@ void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c){
751751
/* Get object ptr based on handler ptr */
752752
i2c_t *obj = get_i2c_obj(hi2c);
753753
struct i2c_s *obj_s = I2C_S(obj);
754+
#if DEVICE_I2CSLAVE
755+
I2C_HandleTypeDef *handle = &(obj_s->handle);
756+
uint32_t address = 0;
757+
/* Store address to handle it after reset */
758+
if(obj_s->slave)
759+
address = handle->Init.OwnAddress1;
760+
#endif
754761

755762
DEBUG_PRINTF("HAL_I2C_ErrorCallback:%d, index=%d\r\n", (int) hi2c->ErrorCode, obj_s->index);
756763

757764
/* re-init IP to try and get back in a working state */
758765
i2c_init(obj, obj_s->sda, obj_s->scl);
759766

767+
#if DEVICE_I2CSLAVE
768+
/* restore slave address */
769+
i2c_slave_address(obj, 0, address, 0);
770+
#endif
771+
760772
/* Keep Set event flag */
761773
obj_s->event = I2C_EVENT_ERROR;
762774
}

0 commit comments

Comments
 (0)