a)
1) The stuck situation with SCL HIGH.
Stop condition terminates a transfer and can be used to abort it as well.
Therefore if SDA LOW then master should generate pulses on SCL and look for SDA HIGH. As soon as the SDA line will be returned to high level the master can generate STOP condition for abort of transfer.
Usually for this goal the I2C pins should be reconfigured to general open-drain outputs. The software generates pulses on SCL line, look for SDA HIGH and generate STOP condition.
However some devices expect different sequence. For example see please the RESET sequence for Atmel EEPROM (User's Manual of Atmel AT24C01A/02/04/08/16).
MEMORY RESET: After an interruption in protocol, power loss or system reset, any 2-wire part can be reset by following these steps:
- Clock up to 9 cycles.
- Look for SDA high in each cycle while SCL is high.
- Create a start condition.
NXP Reference Manuals for QorIQ processors recommends the following command sequence for Generation of SCL when SDA low
- Disable the I2C module and set the master bit by setting IBCR to 0x20
- Enable the I2C module by setting IBCR to 0xA0
- Read the IBDR
- Return the I2C module to slave mode by setting IBCR to 0x80
2) The stuck situation with SCL LOW.
If a slave can't receive or transmit another complete byte of data until it has performed some other function, for example servicing an internal interrupt, it can hold the clock line SCL LOW to force the master into a wait state. Data transfer then continues when the slave is ready for another byte of data and releases clock line SCL (Section 7 of I2C-bus specification).
You cannot recover with this situation. The owner of SCL line should release line SCL.
b)
Customers usually use a timer for detection of I2C hanging.
For example, SMB bus is similar to the I2C bus. The I2C Specification recommends 35ms for SMB bus.
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------