driver for gyro

Dependencies:   COG4050_ADT7420

Fork of COG4050_adxl355_adxl357-ver2 by ADI_CAC

Revision:
6:45d2393ef468
Parent:
5:05af38b6375a
Child:
7:5aaa09c40283
--- a/main.cpp	Wed Aug 08 12:13:05 2018 +0000
+++ b/main.cpp	Tue Aug 14 06:49:07 2018 +0000
@@ -5,7 +5,19 @@
 Serial pc(USBTX, USBRX);
  
 ADXL355 accl(SPI1_CS0, SPI1_MOSI, SPI1_MISO, SPI1_SCLK); // PMOD port
+
  
+float convert(uint32_t data){
+    // If a positive value, return it
+    if ((data & 0x80000) == 0)
+    {
+        return float(data);
+    }
+    //uint32_t rawValue = data<<(32-nbit);
+    // Otherwise perform the 2's complement math on the value
+    return float((~(data - 0x01)) & 0xfffff) * -1;
+    }
+    
 int main(){
     pc.baud(9600);
     pc.printf("SPI ADXL355 and ADXL357 Demo\n");
@@ -24,15 +36,15 @@
     accl.set_power_ctl_reg(accl.MEASUREMENT);
     d=accl.read_reg(accl.POWER_CTL);
     pc.printf("power control on measurement mode = %x \r\n",d);
-    uint32_t x,y,z;
-    uint16_t t;
+    float x, y,z;
+    float t;
     while(1) {
-        x = accl.scanx();
-        y = accl.scany();
-        z = accl.scanz();
-        t = accl.scant();
-        pc.printf("%u \t %u \t %u \t %u \r\n" , x,y,z,t);
-        wait(1.0);
+        x = convert(accl.scanx())*accl.axis355_sens;
+        y = convert(accl.scany())*accl.axis355_sens;
+        z = convert(accl.scanz())*accl.axis355_sens;
+        t = 25+float(accl.scant()-1852)/(-9.05);
+        pc.printf("%f \t %f \t %f  \t %f \r\n" , x,y,z,t);
+        wait(0.50);
   }
 }
- 
+ 
\ No newline at end of file