Modified getOffset for calibrating Thermal Drift coefficients.

Dependents:   9Dof_unit_testing

Fork of ITG3200 by James Watanabe

Modified to make getOffset() function easier to use.

Files at this revision

API Documentation at this revision

Comitter:
gltest26
Date:
Wed Sep 12 11:36:48 2012 +0000
Parent:
1:9bef044f45ad
Child:
3:eea9733ca427
Commit message:
Made the code portable for other compilers, at least places which I have modified.

Changed in this revision

ITG3200.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ITG3200.cpp	Tue Sep 11 16:56:23 2012 +0000
+++ b/ITG3200.cpp	Wed Sep 12 11:36:48 2012 +0000
@@ -201,12 +201,18 @@
     char tx = TEMP_OUT_H_REG;
     char rx[2];
     
-    i2c_.write((ITG3200_I2C_ADDRESS << 1) & 0xFE, &tx, 1);
+    i2c_.write(I2C_ADDRESS, &tx, 1);
+    
+    i2c_.read(I2C_ADDRESS, rx, 2);
     
-    i2c_.read((ITG3200_I2C_ADDRESS << 1) | 0x01, rx, 2);
-    
-    return int16_t((uint16_t(rx[0]) << 8) | uint16_t(rx[1]));
-    
+    // Readings are expressed in 16bit 2's complement, so we must first
+    // concatenate two bytes to make a word and sign extend it to obtain
+    // correct negative values.
+    // ARMCC compiles char as unsigned, which means no sign extension is
+    // performed during bitwise operations to chars. But we should make sure
+    // that lower byte won't extend its sign past upper byte for other
+    // compilers if we want to keep it portable.
+    return int16_t(((unsigned)rx[0] << 8) | (unsigned)rx[1]);
 }
 
 float ITG3200::getTemperature(){
@@ -270,7 +276,7 @@
     i2c_.read(I2C_ADDRESS, rx, 6);
     
     for(int i = 0; i < 3; i++)
-        readings[i] = int16_t((int) rx[i * 2 + 0] << 8) | ((int) rx[i * 2 + 1]);
+        readings[i] = int16_t((unsigned) rx[i * 2 + 0] << 8) | ((unsigned) rx[i * 2 + 1]);
 }
 
 char ITG3200::getPowerManagement(void){