cancel
Showing results for 
Search instead for 
Did you mean: 

HAL function to generate an I2C software reset on the bus

BHoff
Associate II

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?

1 REPLY 1
Jack Peacock_2
Senior III

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