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

No need to wait after Wire.requestFrom() #10

Open
Koepel opened this issue Mar 18, 2018 · 2 comments
Open

No need to wait after Wire.requestFrom() #10

Koepel opened this issue Mar 18, 2018 · 2 comments
Labels
bug good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Koepel
Copy link

Koepel commented Mar 18, 2018

In the file "Arduino-SRF/src/SonarSRF.cpp" there is a while (Wire.available() < length); after the Wire.requestFrom(). That line can be removed, because there is nothing to wait for.

When the Wire.requestFrom() returns, the I2C transaction on the bus has completely finished and the received data is waiting in a buffer in the Wire library.

@LeoColomb
Copy link
Owner

Thanks a lot for your feedback @Koepel! 👍

Really interesting point, I admit I never been really sure to follow strictly the whole I2C process... 😇
Do you have any documentation to support your suggestion?

Anyway, I would love to see a pull request with your suggestion! 🎉

@LeoColomb LeoColomb added the bug label Mar 18, 2018
@Koepel
Copy link
Author

Koepel commented Mar 18, 2018

I think we should stick with the official documentation: www.arduino.cc/en/Reference/WireRequestFrom. The Wire.requestFrom() even returns the final number of received bytes.

My "proof" is that I tell others that the waiting or timeout is something that someone has made up and others have copied it.

You could also read what Nick Gammon wrote about I2C. Search for the word "necessary".

There are a number of Wire libraries for different processors. You could look into the Wire library for AVR processors and analyze that.

P.S.: It is not a real "bug", but more an "inconvenience". The Wire library can detect a few problems on the I2C bus and might return with zero bytes in the buffer. When that happens, the Wire.available() returns zero and the while-loop would never end.

@LeoColomb LeoColomb self-assigned this Oct 8, 2021
@LeoColomb LeoColomb removed their assignment Feb 26, 2022
@LeoColomb LeoColomb added good first issue Good for newcomers help wanted Extra attention is needed labels Mar 1, 2023
@LeoColomb LeoColomb changed the title No need to wait after Wire.requestFrom(). No need to wait after Wire.requestFrom() Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants