-
-
Notifications
You must be signed in to change notification settings - Fork 7k
TWI timeout #1842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TWI timeout #1842
Conversation
I would really like to see something like this in the core. I got a sensor that works perfectly 99.9% of times, but sometimes it will suddenly lock up the I2C bus and this will make the entire system fail. Note that it runs two DC motors, so they will keep spinning, as the microcontroller is just stuck in the while loop. For now I have just "solved" it by using a watchdog timer. |
Also see: #1476 |
This needs to get merged, or something similar to it. This bug just bought me an AVR Dragon to find the issue. |
Cherry picked and squashed by @thirtythreeforty from arduino#1842.
@thirtythreeforty I'll fix the merge conflicts when I'm back on internet that's fast enough to clone the ridiculously oversized repository. I had completely forgotten about this considering I opened this over a year ago. |
Conflicts: libraries/Wire/utility/twi.h
News? |
Cherry picked and squashed by @thirtythreeforty from arduino#1842.
@DanNixon, you closed this pull request but it seems that your proposal have never been merged. Was there any particular reason behind this? |
@wmarkow It sat for over two years with no activity. |
Ok, I just thought that there was something wrong with your proposed fix. I'm facing the same problem with Wire library and adding some timeout feature would help for me. So I started to look for a solution and I have found you pull request. Actually I took some of your ideas to implement my own solution. Thanks. |
@wmarkow I can vouch that this solution works perfectly... we pulled this commit in, as-is, for a project a couple years ago. |
Thank you guys for your input. It is good enough for me to know that this commit works nice. |
I also used this fix, it should be included especially if you i2c bus isn't that good shielded. |
I've also tested in sure-to-hang conditions (first by connecting CLK to ground and also in a system with very long I2C cables), and I can confirm that I've got several days uptime. |
It's been 9 [expletive deleted] YEARS since that bug was first discussed (2011), countless people pulled their hair trying to understand why their Arduino was freezing, why would it work normally, then suddenly stop, a dozen of times, it's been raised in here, dozens of times people had been told to get lost, use something else, etc ... If the fix was difficult, if it compromised compatibility or added other problem, it would be understandable, but it's not the case, all that [expletive deleted] is caused by those 2 damn lines of code that obviously can create an infinite loop if for some reason the read operation does not complete : // wait for read operation to complete
while(TWI_MRX == twi_state){
continue;
} Yes, I know, this state is not supposed to happen according to the I2C protocol, but guess what ? electrical glitches didn't get the memo. Countless people, after losing hours or days kind of solved the issue either by making a modified version for themselves, or switching to another library, so there are several implementations of a timeout that are simple and would easily solve the issue. But arduino developpers stubbornly refuse to fix it ! You think I'm rude ? After 9 years of giving the finger on this issue to the whole community for absolutely no reason, I couldn't care less. How long before you close it again ? |
Adds an iteration limit to the while loops in various
twi_
functions and resets TWI bus if limit is reached.Stops entire microcontroller form hanging if for whatever reason the TWI bus fails.