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 it should not be followed by Wire.endTransmission(). #26

Open
Koepel opened this issue Jun 28, 2018 · 0 comments

Comments

@Koepel
Copy link

Koepel commented Jun 28, 2018

The usage of the Wire library in this and other repositories can be improved.
Explanation: Common-mistakes, number 1 and 2.

For example this (after a Wire.requestFrom):

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

That could be removed. If you want to check the number of received bytes, it can be replaced by this:

  if( Wire.available() != 6) {
    did_timeout = true;     // it is not a timeout, it is a I2C bus error
    return;
  }

I am not sure if checking the number of received bytes is very useful, since you don't check the error code from the Wire.endTransmission() when writing data.

A while-loop after the Wire.requestFrom() can be removed:

  while (Wire.available() < 3);

A Wire.endTransmission() should not be used after a Wire.requestFrom(). That extra Wire.endTransmission() will cause an extra I2C bus transaction. Removed that will improve the working of the Arduino.

Could you check the repository yourself ? Or do I have to mention all the files ?

  • DDSA-ROS/arduino/libraries/IMU/L3G.cpp
  • DDSA-ROS/arduino/libraries/IMU/LPS.cpp
  • DDSA-ROS/arduino/libraries/lsm303-arduino/LSM303.cpp
  • DDSA-ROS/Swarmathon-Arduino/libraries/IMU/LPS.cpp
  • DDSA-ROS/Swarmathon-Arduino/libraries/IMU/L3G.cpp
  • DDSA-ROS/Swarmathon-Arduino/libraries/IMU/LSM303.cpp

and the "BlinkM_funcs.h" has also a useless while(Wire.available loop.

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

1 participant