5 years, 8 months ago.

How can I temporarily disable I2C and re-enable after?

I'm communicating with some devices via I2C that occasionally lock up and hold one the SDA line low. I've looked at the I2C lines and the pullups are sufficient (2.2k on 3.3V signals) to generate a nice clean waveform. Speed is 100kHz.

The general consensus on how to get them functioning again is to switch the I2C pins to GPIO pins temporarily, toggle the SCL back and forth to advance the device state machine, and then switch back to I2C mode again.

How do I do this?

1 Answer

5 years, 8 months ago.

If you're using ST then this may help if it is still current or similar in the later libraries, line 135 _HAL_I2C_DISABLE(hi2c); and _HAL_I2C_ENABLE(hi2c); on line 194.

https://os.mbed.com/users/EricLew/code/STM32L4xx_HAL_Driver/docs/tip/stm32l4xx__hal__i2c__ex_8c_source.html

May be easier to power down the device and restart.

I'll look at the HAL_I2C commands, thanks for the suggestion. Unfortunately powering down the device and restarting is not a good option for me as it's running several other devices and needs to run unattended for days at a time.

posted by David Wahl 25 Apr 2019