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

readRawAccel() conversion error #23

Open
TzOk83 opened this issue Dec 27, 2019 · 1 comment
Open

readRawAccel() conversion error #23

TzOk83 opened this issue Dec 27, 2019 · 1 comment

Comments

@TzOk83
Copy link

TzOk83 commented Dec 27, 2019

There is a bug which reveals itself on 16 or 32 bit MPUs. RAW acceleration is returned via 2 8-bit registers, but is signed, and 2's complement encoded. Registers are mapped as uint8_t (unsigned 8-bit), which is fine, but they are bitshifted and ORed together and assigned to float variable.
xha << 8 | xla creates xa, but it's type is uint16_t, while it should be int16_t... both can be assigned to float variable, but only second one is valid.

Is:

ra.XAxis = xha << 8 | xla;
ra.YAxis = yha << 8 | yla;
ra.ZAxis = zha << 8 | zla;

Should be:

ra.XAxis = (int16_t)(xha << 8 | xla);
ra.YAxis = (int16_t)(yha << 8 | yla);
ra.ZAxis = (int16_t)(zha << 8 | zla);
@I-Connect
Copy link

thx man, this saves me a lot of time and searching!
(was running it on esp32)

I-Connect added a commit to I-Connect/Sense_MPU6050 that referenced this issue Apr 30, 2020
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

2 participants