2020-04-22 5:24 AM
I sometimes have a problem during debugging, that after reset the Eeprom connected to I2C bus does not respond any more.
I assume that the reason might be that I reset my system during a running I2C communication - leaving the bus in an indeterminate state (kept by the Eeprom device).
There are examples for creating a sort of "software reset" on the bus by sending a couple of bits on the bus until the bus is released.
My question: is there a HAL or LL function that will provide such a functionality? Or will I really need to do this by bit banging?
2020-04-22 7:26 AM
An I2C bus hang is usually caused by the bus peripheral holding the SDA line low. I disable and reset the I2C peripheral, switch the SDA to GPIO input and SCL to GPIO output, then send clock pulses on the SCL line (slowly, 100KHz 50% duty) until the SDA goes high. After that I configure the I2C again. This usually clears the peripheral, though it's not a guarantee. Worst case you may still have to power cycle the board to clear the peripheral, depending on the part.
I don;t use the HAL or LL libraries so I'm not aware of any HAL/LL routine for this. I doubt there is one since it tends to be highly dependent on the hardware, especially the SCL clock duty cycle when bit banging.
Jack Peacock
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.