Skip to content

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

Open

Description

@Koepel

Module::read waits after calling HardwareI2C::requestFrom() and clearing the buffer:

Modulino._wire->requestFrom(address, howmany + 1);
auto start = millis();
while ((Modulino._wire->available() == 0) && (millis() - start < 100)) {
delay(1);
}

Both are not needed.

HardwareI2C::requestFrom() is either successful or it fails. It does a full I2C session with a START and STOP condition. When the HardwareI2C::requestFrom() function has returned, the I2C bus is idle. After that, it is not possible to wait from something with a idle I2C bus.

HardwareI2C::available() does not check the I2C bus, it checks the amount of read data in the software buffer in the Wire library.
Therefore, only the line with the HardwareI2C::requestFrom() function call is needed here.


This is not needed:

while (Modulino._wire->available()) {
Modulino._wire->read();
}

The Wire library does not use a stream of data, it uses packages. The buffers are cleared before each session on the I2C bus.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions