Skip to content

Usage of Wire.requestFrom() and local scope of buffer. #2

@Koepel

Description

@Koepel

Hi, that code by loveelectronics.co.uk (it does not exist anymore) has sadly a bug.

The Wire.beginTransmission() and Wire.endTransmission() should not be used with Wire.requestFrom(). They are only used when writing data.
In the file "arduino/libraries/love_ADXL345/love_ADXL345.cpp" in the function Read(), those are used around the Wire.requestFrom(), those Wire.beginTransmission() and Wire.endTransmission() can be removed.

In the function Read(), the buffer is created on the stack, and a pointer to that buffer is returned. That is a bug. The scope of that buffer is only inside the function. As soon as the function returns, that buffer is no longer valid.

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