1 2 Previous Next 15 Replies Latest reply on Oct 3, 2018 8:26 AM by StWa_1982846

    I2C hangs

    MiSa_288856

      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

        • 1. Re: I2C hangs
          MR_41

          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

          • 2. Re: I2C hangs
            ArvindK_86

            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?

            • 3. Re: I2C hangs
              JoMe_264151

              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

              • 4. Re: I2C hangs
                ArvindK_86

                 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.

                • 5. Re: I2C hangs
                  JoMe_264151

                  No, no 3240 avail.

                     

                   

                     

                  Bob

                  • 6. Re: I2C hangs

                     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? 

                    • 7. Re: I2C hangs
                      DaKn_263916

                      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.

                      • 8. Re: I2C hangs

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

                        • 9. Re: I2C hangs
                          DaKn_263916

                          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.

                          • 10. Re: I2C hangs
                            StSi_1143416

                            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

                            • 11. Re: I2C hangs
                              SampathS_11

                              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

                                 

                              • 12. Re: I2C hangs

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

                                • 13. Re: I2C hangs

                                  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

                                  • 14. Re: I2C hangs
                                    JoMe_264151

                                    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

                                    1 2 Previous Next