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

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

Open
Koepel opened this issue Sep 9, 2017 · 0 comments
Open

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

Koepel opened this issue Sep 9, 2017 · 0 comments

Comments

@Koepel
Copy link

Koepel commented Sep 9, 2017

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.

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