XMC 2Go I2C error handling when no device is connected

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hi, I'm using XMC2Go development board and go I2C working correctly with some external devices. Now I need to make the code reliable when device is disconnected, but I found that I2C channel gets into a state that I can't recover.

I call
// init sequence, 
// and then
XMC_I2C_CH_MasterStart(channel, address, command);
XMC_I2C_CH_GetStatusFlag(channel);
// when device is present is present it returns XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED
// but when it's disconnected it gives XMC_I2C_CH_STATUS_FLAG_START_CONDITION_RECEIVED (!)


The status code surprised me, but fine, I could treat it as error here, however now the channel is broken, when I call
XMC_I2C_CH_MasterStart(channel, address, command);
again (e.g. trying to check if device is now connected) it will hang.

I'm guessing the first call to XMC_I2C_CH_MasterStart left the transmit buffer full and subsequent calls to this method will hang on XMC_USIC_CH_GetTransmitBufferStatus returning busy.

Now, the questions are
- how to properly detect lack of device and
- (if the above code it approximately what should be done) how to reset the channel in case of detected errors (I tried calling
XMC_I2C_CH_Stop(CHANNEL); XMC_I2C_CH_Start(CHANNEL);
, but it didn't help)
0 Likes
2 Replies
User13817
Level 3
Level 3
Hello kamils,

Are you using DAVE4? In case of using it, could you please provide your code/project?
I've been trying to use I2C+Sense2Go to read a TLV493D (on DAVE4) but it isn't working as expected. I did it on DAVE3 but I want to move to the newest one.

Thank you,
Best regards.
0 Likes
User13264
Level 1
Level 1
I think I was facing the same problem.

XMC_I2C_CH_MasterStart() would hang after a NACK response.

Turns out this was because I had a XMC_I2C_CH_MasterStop() after receiving the NACK. This would sit in the transmit buffer blocking any future use of the I2C bus.

Hope this helps someone. I came across this thread from a google search.
0 Likes