This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Another I2C Lockup - unique.

I'm using I2C across a short cable from an 430F5137 to a very simple slave. But when I remove then replace power to the slave (while the Master is sending), the bus locks up. I read about using a NACK to check the slave (suggestions?)

What registers do I need to clear so the slave comes back on line? It was not sending any data, only writing it so far. 

John

  • When a slave is disconnected durign a transmission, there are two possible situations:

    1) the slave is transmitter. Then the master won't notice. it will continue reading 0xff bytes until the master decides to end the transfer. However, this is nto different from the slave being connected but unable to provide mroe data (e.g. end of memory reached).

    2) the slave is receiver. Then the master will 'get' a NACK after the next byte. This is the same as if the slave doesn't want any more data (because buffer full ot whatever). The master should be able to handle this.

    Likely, the bug is in case 2 and the master assumes that the slave will always be able to accept the wanted number of bytes, so the control code of the master doesn't check for a 'premature' end of the transaction and locks up in an unexpecte situation. The master has to check for a NACK (UCNACKIFG) from a slave, which will come instead of another UCTXIFG when the slave hasn't ACKed the last byte.

    In addition, often the I2C code presented here doesn't check for the slave being really present. if the master initiates a transaction and the slave doesn't respond, then the code locks-up instead of checking for an ACK response before poceeding.

  • Jens-Michael Gross said:
    often the I2C code presented here doesn't check for the slave being really present

    Indeed - Very often (usually?), "sample code" just illustrates the "success" case.

    But, in real applications, the "success" case is (almost) the trivial case - the majority of the work goes into handling the "failure" cases.

    See also: http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortex-m3_microcontroller/f/471/p/103166/814339.aspx#814339

    Note that I2C is usually used between components on the same board,  so using it to connect separate boards is going to require particular attention to the extra complications which that brings - such as missing peripherals, poor connections, power sequencing, etc...

**Attention** This is a public forum