Skip to content
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

I2C/Wire library: Make Wire library non-blocking #1476

Closed
ghost opened this issue Jun 20, 2013 · 12 comments
Closed

I2C/Wire library: Make Wire library non-blocking #1476

ghost opened this issue Jun 20, 2013 · 12 comments
Assignees
Labels
Component: Core Related to the code for the standard Arduino API Library: Wire The Wire Arduino library Type: Bug Type: Duplicate Another item already exists for this topic

Comments

@ghost
Copy link

ghost commented Jun 20, 2013

The Wire library has while loops that could go on forever. Although this will not happen in a normal situation, if it happens, the blocking stops the Arduino from working and that could be a safety issue.

Arduino version 1.0.5

A simple loop as timeout could solve this, as suggested here, http://diydrones.com/forum/topics/i2c-wiring-library-lockup
A non-blocking version was also made in 2011 by gknight4, http://forum.arduino.cc/index.php/topic,70705.0.html

@marekhalmo
Copy link

Agree, this is crucial. If you have 20 sensors plugged in to arduino and one goes damaged/unplugged, everything freezes!
Please fix this :(

@imval
Copy link

imval commented Jun 3, 2016

Issue is opened since almost 3 years :/ Is there anyone that can do something about this bug ? I have big issues with this, I'll probably use a timeout in the loop.

@marekhalmo
Copy link

This just sucks :(

@juanmalunatic
Copy link

Agreed, the proposed solutions should work fine and this is a much needed bug-fix.

@dorinclisu
Copy link

dorinclisu commented Aug 17, 2017

Is this fix present in Arduino 1.6.10? Because I still have the issue, but I can't use the latest IDE due to other compatibility problems.

@VladimirAkopyan
Copy link

This is ridiculous - are we ever going to fix this?

@IanSC
Copy link

IanSC commented Jun 19, 2019

try this dropin replacement:
https://github.com/IanSC/Arduino-Wire.h

@cimba007
Copy link

@IanSC: What is the best way to replace the default wire library? Do you have and experience on this?

@matthijskooijman
Copy link
Collaborator

I'm closing this issue, in favor of arduino/ArduinoCore-avr#42 (which is in the, now, correct repository).

@ermtl
Copy link

ermtl commented Mar 27, 2020

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 ...
#7328
#2418
#1842
#5249
arduino/ArduinoCore-avr#42
Google shows pages after pages of people getting started and who get discouraged by this elusive bug they don't understand. This runs totally contrary of what arduino is supposed to stand for.

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 ?
Just be honest, and put a "[expletive deleted] you all, WONTFIX" label on it ...

@mattborja
Copy link

Yeah, still a problem in 2022 in Arduino 1.8.19. My Wire.endTransmission() still hangs if my IC is disconnected.

Waiting for a reply on rambo/I2C#12 before switching to that.

@cmaglie
Copy link
Member

cmaglie commented Apr 13, 2022

Quoting @matthijskooijman answer for future reference:

@mattborja, this timeout feature has actually been implemented (two years ago) in arduino/ArduinoCore-avr#107, but it is not enabled by default. Did you try turning it on using https://www.arduino.cc/reference/en/language/functions/communication/wire/setwiretimeout/ ?

Since we seem to have forgotten closing this issue, I'll do that now. For future reference, arduino/ArduinoCore-avr#107 implemented the feature, arduino/ArduinoCore-avr#362 is still pending to add feature detection macros like WIRE_HAS_TIMEOUT, and arduino/ArduinoCore-avr#363 is a draft to enable timeouts by default in the future.

@arduino arduino locked as resolved and limited conversation to collaborators Apr 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: Core Related to the code for the standard Arduino API Library: Wire The Wire Arduino library Type: Bug Type: Duplicate Another item already exists for this topic
Projects
None yet
Development

No branches or pull requests