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() and no Wire.endTransmission() should be called after it. #1

Open
Koepel opened this issue Mar 15, 2018 · 1 comment

Comments

@Koepel
Copy link

Koepel commented Mar 15, 2018

In the files "LSM303.cpp" and "L3G.cpp" there is sometimes a Wire.endTransmission() after the Wire.requestFrom(). That Wire.endTransmission() can be removed, it should only be used when writing data.

The waiting or a timeout after a Wire.requestFrom() can be removed as well. When the Wire.requestFrom() returns, the I2C transaction on the bus has already completely finished and the received data is waiting in a buffer in the Wire library. If something did go wrong on the bus, the number of received bytes might be not the same as the number of requested bytes.

This:

  Wire.requestFrom(address, (byte)6);
  
  unsigned int millis_start = millis();
  while (Wire.available() < 6)
  {
    if (io_timeout > 0 && ((unsigned int)millis() - millis_start) > io_timeout)
    {
      did_timeout = true;
      return;
    }
  }

could be replaced with this:

  Wire.requestFrom(address, (byte)6);
  
  if (Wire.available() != 6)
  {
    set some kind of error
    return;
  }
@ryantm
Copy link
Contributor

ryantm commented Mar 16, 2018

Hi, Koepel.

Thank you for your reminders about this issue with our libraries.

The files you mention are copied versions of our libraries. You raised this issue with the source libraries:

pololu/l3g-arduino#12
pololu/lsm303-arduino#10

I'll leave this open until we fix the issue in those libraries and copy them to this one.

Sincerely,
Ryan

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

2 participants