BMI160 Initial

Dependents:   MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_Pitch_Charles Maxim_Squeeks

Revision:
6:9615aa90087d
Parent:
5:35e032c8d8aa
Child:
7:9848196cb65e
--- a/bmi160.cpp	Wed Dec 14 23:48:07 2016 +0000
+++ b/bmi160.cpp	Thu Dec 15 00:38:04 2016 +0000
@@ -66,11 +66,20 @@
 int32_t BMI160::getTemperature(float *temp)
 {
     uint8_t data[2];
+    uint16_t rawTemp;
     
     int32_t rtnVal = readBlock(TEMPERATURE_0, TEMPERATURE_1, data);
     if(rtnVal == RTN_NO_ERROR)
     {
-        *temp = (((data[1] << 8) | data[0])/512.0);
+        rawTemp = ((data[1] << 8) | data[0]);
+        if(rawTemp & 0x8000)
+        {
+            *temp = (23.0F - (((0xFFFF - rawTemp) + 1)/512.0F));
+        }
+        else
+        {
+            *temp = ((rawTemp/512.0F) + 23.0F);
+        }
     }
     
     return rtnVal;