Showing results for 
Search instead for 
Did you mean: 

PSoC Creator & Designer Software

Esteemed Contributor

I am using an application with a simple master (PSOC) and a slave device.




When I issue R/W commands to Slave, I accumulate the return values from the I2C API,


and then evaluate this for > 0 (errors), eg. looking for an error, to implement error handling.




If I disconnect clock or data line the I2Cm gets stuck in a I2Cm API, a function called clockstretch2.




So net effect is to take down entire application.




Code being used -




 unsigned char I2Cok = 0;


 I2Cok = ( I2Cm_fSendStart( SLAVADD, I2Cm_WRITE ) == 0 ) ? 1 : 0;   // Send start bit
 I2Cok = ( I2Cm_fWrite( memadr ) == 0 ) ? I2Cok + 1 : I2Cok;                 // Send command to read Tobject
 I2Cok = ( I2Cm_fSendRepeatStart( SLAVADD, I2Cm_READ ) == 0 ) ? I2Cok + 1 : I2Cok; // Send repeat start bit
 rxBuf[ 0 ] = I2Cm_bRead( I2Cm_ACKslave );      // Read low order byte
 rxBuf[ 1 ] = I2Cm_bRead( I2Cm_ACKslave );      // Read high order byte
 rxBuf[ 2 ] = I2Cm_bRead( I2Cm_ACKslave );      // Read PEC




Code works fine, until I disconnect a clock or data line to I2C slave, or if a loss of power to slave


occured. Clearly this should be considered a defect in I2C API implementation, inability to handle


a HW failure. I suppose a workaround would be watchdog, but that I think is a poor choice.




Is this also case for Creator ?




Regards, Dana.

1 Reply
Expert II

I had a similar problem once when I sought for a communication interface that could be connected or not. To my astonishment I found out that in the specs for I2C there is nothing like a timeout or a defined failure. The only workaround so far I could evaluate was that one (1) living slave seems to hinder the I2C from stalling. Testing the connection could be made with I2Cm_SendStart() which will return a value != 0 when the connection to the slave is broken. I did not find a way to capture a broken connection within a transaction.