I2C hangs

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

cross mob
MiSa_288856
Level 1
Level 1

Hallo,

   

I wish to find a solution for an issue that I often found when using I2C bus. If I configure my PSOC as an I2C master and try to 'talk' on a connection where no slave is present or where a slave is in some critical condition the whole system hangs. Of course I can detect this by using the internal watchdog and disable the I2C hardware but in some cases this's not a good solution since it will disable also coomunication with slaves that are currently working. It's possibile to prevent this hang-over? It's possible to define a custom function to inspect the bus for 'working' slaves before starting the real communication?

   

Best Regards,

   

 Michele Santucci

0 Likes
15 Replies
MR_41
Employee
Employee
First like received

You can use the low level function fSendStart to check if a Slave ACKed the start condition and then use high level functions only if the slave was present.  Following are the steps.

1. Use fSendStart and see if the Slave ACKs. If no ACK, send a Stop and release the bus
2. If Slave ACKs, send a stop to release the bus, re-enable the I2C interrupt (as fSendStart disables the I2C interrupt), and start using the high level API

Check out the project here.

Interfacing an I2C EEPROM to PSoC

This project shows a method to use the fSendStart function to poll if a slave is active on the bus before using a high level API.

Best Regards,
Ganesh
The PSoC Hacker

0 Likes
ArvindK_86
Employee
Employee
10 sign-ins 5 sign-ins 10 solutions authored

Those are some good points to prevent stalling of the CPU when I2C is involved.

   

 

   

But I did face some issues when the software I2C module is used (I2Cm user module).

   

 

   

Specifically, any command after I2Cm_fSendStart is not executed.

   

Any thoughts on this anyone?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Can you please create a small project (preferably for a 29466) which creates that issue to have a look on it?

   

Think it would clarify what exactly doesn't work as you expect.

   

 

   

Bob

0 Likes
ArvindK_86
Employee
Employee
10 sign-ins 5 sign-ins 10 solutions authored

 Would you happen to have a CY3240 and the little I2C slave board with you? I have a project for this hardware combination.

   

 

   

If not, I'll port to 29466 and post it.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

No, no 3240 avail.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

 I have up to six slaves on a board and I would like to know which ones are present. I implemented the routine and code suggested above but every thing hangs up after the the master recieves an ACK from 4th slave and. The routine hangs in during the I2CHW_fSendStart for the 5th slave.

   

 Any Ideas or help? 

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

I have a similiar problem, using I2Cm module. If the slave clock or data

   

line is disconnected the firmware hangs in the clockstretch2 asm routine

   

the module uses. I have a Tech Case being looked at by Cypress. I will

   

pass on this thread to them.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Have you received any information back from cypress on solving this problem?

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Yes, the SW team is going to, in the next release, date unknown, implement

   

a timeout function associated with the I2C clocking routines.

   

 

   

This will fix disconnected pins, SCL, SDA, pullups, from hanging main().

   

 

   

Regards, Dana.

0 Likes
StSi_1143416
Level 2
Level 2
First question asked First reply posted First like received

Hi Dana, I know that this is an old post but I seem to have a similar problem with the IIC bus hanging. It hangs in the

   

uint8 SensorIIC_MasterReadByte(uint8 acknNak) subroutine on the line         while(SensorIIC_WAIT_BYTE_COMPLETE(SensorIIC_CSR_REG))
 

   

Do you know if the timeout function has been implemented yet?

   

Best Regards

   

Stephen

0 Likes
SampathS_11
Moderator
Moderator
Moderator
250 sign-ins 250 solutions authored 5 questions asked

Hello Stephan,

   

Timeout has not been implemented, since I2C has no specification on the time limit. 

   

I would like to point you to the discussion in this thread:

   

I2CHW - SDA line low problem - detection and solution

   

Best regards,

   

Sampath

   

0 Likes
Anonymous
Not applicable

There is some more information about I2C "hangs" at http://www.mbedded.ninja/programming/microcontrollers/psoc/components#i2c (and how to overcome them).

0 Likes
Anonymous
Not applicable

I have a similar problem and I've been looking through the include files. If you change this #define to 1, #define I2C_TIMEOUT_ENABLE (1u) then it compiles in this function: #if (I2C_TIMEOUT_ENABLED) I2C_TimeoutStop(); #endif /* End (I2C_TIMEOUT_ENABLED) */ which is undefined. Can't seem to find this in the docs, but I'm assuming we're meant to implement I2C_TimeoutStop for cleanup in our main? thanks, Johann

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Johann, refer to the answer SAMP.CY gave: Timeout is not implemented.

   

On the other hand: A timeout would break the standards for I2C.  A timeout was never defined in the protocol.

   

When a running connection dies and your code hangs in the I2C communication, you can reboot your machine (using WDT).

   

 

   

Bob

0 Likes

Bob,

No, you cannot always just reboot to solve an I2C hang. When the communicator is also running a BLE session, a reboot closes the session and leaves it hanging. We need a clean way to keep I2C from hanging in the first place. FIX THE PROBLEM.

Right now I am fighting to interface a Nordic nRF51422 BLE as I2C master with a CY8C20666A/EzI2Cs slave. The Cypress part hangs with both SDA and SCL low every time the Nordic writes a single byte to the bus. Nothing but a full system reset gets it started again. I am starting to see why all the SWD interfaces abandoned I2C protocol.

Steve

0 Likes