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

Wire library has no timeout functionality (meaning it is blocking). #83

Open
second-pair opened this issue Sep 9, 2020 · 3 comments
Open

Comments

@second-pair
Copy link

In trying to solve some I2C issues I've been having, I came across this thread (and a great many others), which indicate the Wire libraries don't have any timeout capabilities, particularly making Wire .endTransmission () blocking. This has since been solved and merged into ArduinoCore-avr and has appeared in my libraries locally. To the best of my knowledge (and my own experience), the ArduinoCore-megaavr Wire library is also blocking. I haven't been able to find this fix in the ArduinoCore-megaavr version of Wire, and I haven't found any other issues relating to this, so I'm raising one now.

I'm not aware of the development relationship between the two cores, so if this already on its way, that's great. If not (and it's appropriate to do so), I'd like to see the functionality added to ArduinoCore-avr added here too. Particularly, I'd like to see functionality added that's similar to that provided by the new functions setWireTimeout(), getWireTimeoutFlag(), clearWireTimeoutFlag().

@freddyrios
Copy link

freddyrios commented Oct 5, 2020

Also interested to hear if this also affects the megaavr. I spotted a while loop in the source, so it seems likely.

Do note however that this is a (good) mitigation to try to reduce the impact of underlying issues. So we are supposed to look into those regardless of this change as we can still see other serious issues due to root cause. See arduino/reference-en#895

@softhack007
Copy link

softhack007 commented Nov 27, 2021

Hi, from looking into the wire library code, it seems to me that the logic is very different from arduinocore-avr. The only place where a "while" loop occurs is in function TWI_MasterWriteRead():

/* Arduino requires blocking function */
while(master_result == TWIM_RESULT_UNKNOWN) {}
// in case of arbitration lost, retry sending
if (master_result == TWIM_RESULT_ARBITRATION_LOST) {
goto trigger_action;
}

In contrast to the avr core, the main work is performed by hardware and an ISR.

So the first question is- is it possible that the ISR never updates the status? I saw that there are error codes for "bus error" and "arbitration lost".

Please also consider that there could be another infitite loop in case of repeated TWIM_RESULT_ARBITRATION_LOST.

@valerioformato
Copy link

+1 I find the I2C bus on my Uno wifi rev2 randomly freezing with 2 devices on it, and this feature would probably help a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants