Hi,
I accidentally found a way to get I2C stuck and so far could not find a solution for it. Hope someone can give some hints.
- LPC55S69 Evaluation board
- SI7055 I2C temperature sensor connected to FC2
- Using NXP I2C driver and freeRTOS on top of those
Case if fairly simple. Temperature measurements means that we write one byte to sensor, wait for a while and read result.
I noticed that if I disconnect SCK wire, temperature reading(I2C write) fails(naturally). If I then connect SCK again and try to read temperature, I2C write never returns. Bug is in MCU side, sensor does not keep lines down or anything.
What I have found out so far is that in RTOS driver level it does not return because NXP driver never calls the `I2C_RTOS_Callback` given to `I2C_MasterTransferCreateHandle`. In NXP level it hangs because `I2C_RunTransferStateMachine` called by `I2C_MasterTransferHandleIRQ` is called only once(`kStartState`) and then nothing. I2C also sends nothing to lines when it gets stuck(checked with scope)
I have tried to eyeball and debug the driver code, but it looks solid to me. I am suspecting that maybe the actual I2C peripheral is somehow messed up.
When I disconnect the SCK, I can see following events in NXP I2C driver(I2C_RunTransferStateMachine)
status=5244961, state=6(kStartState) -> result=0
status=5245025, state=2(kTransmitDataState) -> result=2608(kStatus_I2C_StartStopError)
// RTOS callback called -> error returned to application
And after this next write is just
status=5244961, state=6 -> result=0
//Stuck
For reference, if I disconnect SDA wire, writing the byte fails like this:
status=5244961, state=6 -> result=0
status=5245057, state=2 -> result=2611(kStatus_I2C_Addr_Nak)
// RTOS callback called -> error returned to application
status=5244961, state=0 -> result=2609(kStatus_I2C_UnexpectedState)
After this I2C is working just fine and interrupts from I2C are coming through if I connect the SDA again.