driver for gyro

Dependencies:   COG4050_ADT7420

Fork of COG4050_adxl355_adxl357-ver2 by ADI_CAC

Revision:
7:5aaa09c40283
Parent:
6:45d2393ef468
Child:
8:9e6ead2ee8d7
--- a/main.cpp	Tue Aug 14 06:49:07 2018 +0000
+++ b/main.cpp	Tue Aug 14 11:33:30 2018 +0000
@@ -1,22 +1,13 @@
 #include "mbed.h"
 #include <inttypes.h>
 #include "ADXL355.h"
+#include "ADXRS290.h"
  
 Serial pc(USBTX, USBRX);
  
-ADXL355 accl(SPI1_CS0, SPI1_MOSI, SPI1_MISO, SPI1_SCLK); // PMOD port
-
+ADXL355 accl(SPI1_CS0, SPI1_MOSI, SPI1_MISO, SPI1_SCLK);    // PMOD port
+ADXRS290 gyro(SPI0_CS2, SPI0_MOSI, SPI0_MISO, SPI0_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);
@@ -24,27 +15,28 @@
     pc.printf("GET device ID\n");
     accl.reset();
     uint8_t d; 
-        d=accl.read_reg(accl.DEVID_AD);
-        pc.printf("AD id = %x \r\n",d);
-        d=accl.read_reg(accl.DEVID_MST);
-        pc.printf("MEMS id = %x \r\n",d);
-        d=accl.read_reg(accl.PARTID);
-        pc.printf("device id = %x \r\n",d);
-        d=accl.read_reg(accl.REVID);
-        pc.printf("revision id = %x \r\n",d);
+    d=accl.read_reg(accl.DEVID_AD);
+    pc.printf("AD id = %x \r\n",d);
+    d=accl.read_reg(accl.DEVID_MST);
+    pc.printf("MEMS id = %x \r\n",d);
+    d=accl.read_reg(accl.PARTID);
+    pc.printf("device id = %x \r\n",d);
+    d=accl.read_reg(accl.REVID);
+    pc.printf("revision id = %x \r\n",d);
     pc.printf("GET device data [x, y, z, t] \r\n");
     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);
     float x, y,z;
     float t;
-    while(1) {
-        x = convert(accl.scanx())*accl.axis355_sens;
-        y = convert(accl.scany())*accl.axis355_sens;
-        z = convert(accl.scanz())*accl.axis355_sens;
+    // save data info a file
+    while(1000) {
+        x = accl.convert(accl.scanx())*accl.axis355_sens;
+        y = accl.convert(accl.scany())*accl.axis355_sens;
+        z = accl.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);
+        wait(0.1);
   }
 }
  
\ No newline at end of file