From 81034685c5cd3191554b21592c5b87ce5893a5a6 Mon Sep 17 00:00:00 2001 From: mayankgour13 <36739521+mayankgour13@users.noreply.github.com> Date: Mon, 22 Oct 2018 23:18:25 +0530 Subject: [PATCH] Typecasting added to support 32-bit controllers. For 32-bit controllers size of Integer is 32-bit which does not treat 16-bit 2's complement value +/- ve but only as 16-bit +ve Integer as the first MSB is always 0. --- MPU6050.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MPU6050.cpp b/MPU6050.cpp index d9cc131..a8cb335 100644 --- a/MPU6050.cpp +++ b/MPU6050.cpp @@ -373,9 +373,9 @@ Vector MPU6050::readRawAccel(void) uint8_t zla = Wire.receive(); #endif - ra.XAxis = xha << 8 | xla; - ra.YAxis = yha << 8 | yla; - ra.ZAxis = zha << 8 | zla; + ra.XAxis = (int16_t)(xha << 8 | xla); + ra.YAxis = (int16_t)(yha << 8 | yla); + ra.ZAxis = (int16_t)(zha << 8 | zla); return ra; } @@ -434,9 +434,9 @@ Vector MPU6050::readRawGyro(void) uint8_t zla = Wire.receive(); #endif - rg.XAxis = xha << 8 | xla; - rg.YAxis = yha << 8 | yla; - rg.ZAxis = zha << 8 | zla; + rg.XAxis = (int16_t)(xha << 8 | xla); + rg.YAxis = (int16_t)(yha << 8 | yla); + rg.ZAxis = (int16_t)(zha << 8 | zla); return rg; }