Infinite While loop in I2C communication

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

cross mob
Anonymous
Not applicable

Hi guys, this is my first post in the forum, so please correct me if I do something wrong.

   

I'm using a CYBLE-014008-EVAL with the CY8CKIT-042-BLE.

   

I'm communicating with 4 ADS1115 via I2C in a rather complicate ambient (I2C communications are going to fail due to inducted errors from time to time). The problem is that in the source generated code for the I2C SCBs, there are several while loops where my program gets stuck.

   

I wanted to do something to restart the process when I2C fails, but I can't modify the source code without it getting restored every time I rebuild the project. Is there anything in the API I haven't found which could help me? If not, is there any way I can modify the source code (I already tried this: http://www.cypress.com/knowledge-base-article/avoiding-changes-source-file-get-overwritten-psoc-crea... )?

   

I would also like to know which of the ADCs has failed and send some kind of error, but I'm stuck in the same problem as before.

   

 

   

Thanks in advance..and great job! This is a great community

   

PD: I can't attach the project due to the matter of it. I can paste some parts of the code if needed though.

0 Likes
1 Solution
cadi_1014291
Level 6
Level 6
25 likes received 10 likes received 10 likes given

Hi,

   

You can try importing the I2C component (https://www.youtube.com/watch?v=cEAEk-HRib8), then change it's name (i.e. myI2C) and then modify the API in it, and then test it on your project.

   

I found a post where it talks about the same problem, he modified the component, see section Dangerous While() Loops: http://blog.mbedded.ninja/programming/microcontrollers/psoc/components

   

 

   

Hope it helps

   

Carlos

View solution in original post

0 Likes
7 Replies
cadi_1014291
Level 6
Level 6
25 likes received 10 likes received 10 likes given

Hi,

   

You can try importing the I2C component (https://www.youtube.com/watch?v=cEAEk-HRib8), then change it's name (i.e. myI2C) and then modify the API in it, and then test it on your project.

   

I found a post where it talks about the same problem, he modified the component, see section Dangerous While() Loops: http://blog.mbedded.ninja/programming/microcontrollers/psoc/components

   

 

   

Hope it helps

   

Carlos

0 Likes
Anonymous
Not applicable

Hi Carlos,

   

Thank you very much for the fast answer.

   

It is exactly what I was looking for. I will implement it on Monday and see if I get it to work properly.

   

 

   

Regards

   

Gabriel

0 Likes
Anonymous
Not applicable

I managed to modify the source code, and now I added a counter and sent an error when I2C hangs. My problem is that I can't reset it. I read that sometimes SCL pin stays LOW and you have to manually put it to HIGH to properly restart I2C communications again.

   

Any idea on how to restart I2C communications without restarting the whole system with CySoftwareReset() ??

   

 

   

Regards

   

Gabriel

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

Pull the sda line low for 9 clock cycles to reset the "hanging" slaves.

   

 

   

Bob

0 Likes

Hi @Gabriel and @Bob,

   

@Gabriel, that was quick, glad to help :).

   

By chance you know if it's possible to upload this modified I2C component (to GitHub for example) without getting into troubles with Cypress? (i don't know the license of the default component).

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Well, I guess we can always ask for fogiveness 😉

   

I'm uploading the modified file to paste into the component in case someone ends up with the same question. I also added some code to identify which slave failed and in which channel of the slave the issue appeared. 

   

To use the file, just delete the .txt extension

   

Greetings

   

Gabriel

0 Likes

Greetings

   

Thanks Gabriel, will check this for sure.

   

 

   

Carlos

0 Likes