This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TivaWare Sensorlib Bug in MPU9150.c & MPU6050.c

There's a bug in the Sensorlib code (Rev 2.1.0.12573) that manages the tMPU9150 struct (in MPU9150.c: MPU9150Write; also in MPU6050.c: MPU6050Write). The error incorrectly indexes data structures if the accelerometer or gyro scales are not set to "0" (most sensitive), so subsequent floating point scaling of the sensor data will be in error.

The error has been there at least since Rev 1.0 (my earliest revision).  Basically, the pui8Data[] index is MPU9150_O_*** - ui8Reg, but should be reversed, as anything but "0" is negative.

The diff code is:

@@ -678,7 +678,7 @@ MPU9150Write(tMPU9150 *psInst, uint_fast8_t ui8Reg, const uint8_t *pui8Data,
         //
         // See if a soft reset is being requested.
         //
-        if(pui8Data[MPU9150_O_PWR_MGMT_1 - ui8Reg] &
+        if(pui8Data[ui8Reg - MPU9150_O_PWR_MGMT_1] &^M
            MPU9150_PWR_MGMT_1_DEVICE_RESET)
         {
             //
@@ -702,7 +702,7 @@ MPU9150Write(tMPU9150 *psInst, uint_fast8_t ui8Reg, const uint8_t *pui8Data,
         //
         // Extract the FS_SEL from the GYRO_CONFIG register value.
         //
-        psInst->ui8NewGyroFsSel = ((pui8Data[MPU9150_O_GYRO_CONFIG - ui8Reg] &
+        psInst->ui8NewGyroFsSel = ((pui8Data[ui8Reg - MPU9150_O_GYRO_CONFIG] &^M
                                     MPU9150_GYRO_CONFIG_FS_SEL_M) >>
                                    MPU9150_GYRO_CONFIG_FS_SEL_S);
     }
@@ -717,7 +717,7 @@ MPU9150Write(tMPU9150 *psInst, uint_fast8_t ui8Reg, const uint8_t *pui8Data,
         // Extract the AFS_SEL from the ACCEL_CONFIG register value.
         //
         psInst->ui8NewAccelAfsSel =
-            ((pui8Data[MPU9150_O_ACCEL_CONFIG - ui8Reg] &
+            ((pui8Data[ui8Reg - MPU9150_O_ACCEL_CONFIG] &^M
               MPU9150_ACCEL_CONFIG_AFS_SEL_M) >>
              MPU9150_ACCEL_CONFIG_AFS_SEL_S);
     }

Cheers,
Doug

  • Hi PAk,


    I read through the first two pages and some of the last page of that thread (and have read through enough of the Invensense forums last year) to know that there are significant code problems with areas in the Sensorlib.

    I don't think the bug I found (this thread) is related to what you are struggling with: as much of it as I've experienced so far only affects accel & gyro scaling when not on the default (minimum) scale.  So as long as you're working with the unaltered CompDCM demo code, you're on the default scale and ok.  It doesn't affect the chip programming.

    This bug, however, would be related to any quaternion work you're doing; though in your referenced thread it seemed others were noticing problems related to either sensor data or the DCM filtering, which I believe is before the quaternion processing in the CompDCM example.

    Good luck!

    Doug

  • Hey sorry to bump up an old thread, but I recently encountered this problem. But it seems to me the bug is

    ((pui8Data[ui8Reg - MPU9150_O_ACCEL_CONFIG] &

    as it should be

    ((pui8Data[MPU9150_O_ACCEL_CONFIG - ui8Reg] &

    ui8Reg will always be less than MPU9150_O_ACCEL_CONFIG when running this line. Hence, MPU9150_O_ACCEL_CONFIG - ui8Reg gives you the correct offset. But curiously the problem I'm seeing is exactly what is described here.