Skip to content

Wrong use of Wire library #265

Open
Open
@Koepel

Description

@Koepel

A few issues have already been reported about code with the Wire functions of I2Cdev.cpp.
#252 (timeout is not in Arduino library)
#181 (adding a repeated start)
#76 (data length)

In 5 places, the Wire.requestFrom() is followed by a Wire.endTransmission(). That causes an extra I2C transaction with the address on the I2C bus and the Slave acknowledging. The Wire.requestFrom() is a complete I2C transaction on its own, and should not be followed by a Wire.endTransmission().

A timeout for getting data after Wire.requestFrom() is not needed. When the Wire.requestFrom() returns, the I2C transaction has completely finished and the received data is in the receive buffer in the Wire library. That data can be read with Wire.read(). In case there was a bus error or a collision, the return value of Wire.requestFrom() or Wire.available() will be less than the number of requested byte (it will most likely be zero). A single check for that error or collision is possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions