Skip to content

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

Closed
@ghost

Description

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

Activity

marekhalmo

marekhalmo commented on May 21, 2016

@marekhalmo

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

imval

imval commented on Jun 3, 2016

@imval

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

marekhalmo commented on Jun 16, 2016

@marekhalmo

This just sucks :(

juanmalunatic

juanmalunatic commented on Sep 21, 2016

@juanmalunatic

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

dorinclisu

dorinclisu commented on Aug 17, 2017

@dorinclisu

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.

9 remaining items

IanSC

IanSC commented on Jun 19, 2019

@IanSC

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

cimba007

cimba007 commented on Aug 17, 2019

@cimba007

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

matthijskooijman

matthijskooijman commented on Sep 6, 2019

@matthijskooijman
Collaborator

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

ermtl

ermtl commented on Mar 27, 2020

@ermtl

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

mattborja commented on Apr 13, 2022

@mattborja

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

cmaglie commented on Apr 13, 2022

@cmaglie
Member

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.

locked as resolved and limited conversation to collaborators on Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Component: CoreRelated to the code for the standard Arduino APILibrary: WireThe Wire Arduino libraryType: BugType: DuplicateAnother item already exists for this topic

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @matthijskooijman@cmaglie@ffissore@imval@cimba007

      Issue actions

        I2C/Wire library: Make Wire library non-blocking · Issue #1476 · arduino/Arduino