4.2 Bad Clock Stretching
Occasionally in I2C, the bus may deadlock during clock-stretching. One of the challenges with debugging this condition is figuring out which device is responsible. A logic analyzer is a helpful tool for this - if the communication just prior to the deadlock is captured, the deadlocking device will be determined. The fault occurs when the faulty device clock stretches before ACK/NACK.
If the fault is on the MCU side, the I2C driver possibly did not clear the clock stretching bit in the peripheral hardware when needed, which can be verified by reading the state of the bit. Alternatively, resetting the peripheral (or its state machines) will release the Serial Clock (SCL) line.
If the fault is not in the microcontroller, then the only thing to do is reset the faulty I2C device. If there is no reset line, then the device will be power-cycled.