LSM6DS33 Library

Dependents:   teensyIMU LSM6DS33 ALTIMU_v6

Fork of LSM6DS3 by Sherry Yang

Files at this revision

API Documentation at this revision

Comitter:
bclaus
Date:
Thu Oct 06 23:28:32 2016 +0000
Parent:
3:b1d064895178
Commit message:
functional;

Changed in this revision

LSM6DS33.cpp Show annotated file Show diff for this revision Revisions of this file
LSM6DS33.h Show annotated file Show diff for this revision Revisions of this file
--- a/LSM6DS33.cpp	Thu Oct 06 16:08:42 2016 +0000
+++ b/LSM6DS33.cpp	Thu Oct 06 23:28:32 2016 +0000
@@ -9,6 +9,7 @@
 uint16_t LSM6DS33::begin(gyro_scale gScl, accel_scale aScl,  
                         gyro_odr gODR, accel_odr aODR)
 {
+    
     // Store the given scales in class variables. These scale variables
     // are used throughout to calculate the actual g's, DPS,and Gs's.
     gScale = gScl;
@@ -49,73 +50,54 @@
     cmd[1] = 0x10;
     i2c.write(xgAddress, cmd, 2);
     
+    
     // Once everything is initialized, return the WHO_AM_I registers we read:
     return xgTest;
 }
 
 void LSM6DS33::initGyro()
 {
-    char cmd[4] = {
+    char cmd[2] = {
         CTRL2_G,
-        gScale | G_ODR_104,
-        0,          // Default data out and int out
-        0           // Default power mode and high pass settings
+        gScale | G_ODR_104
     };
 
     // Write the data to the gyro control registers
-    i2c.write(xgAddress, cmd, 4);
+    i2c.write(xgAddress, cmd, 2);
 }
 
 void LSM6DS33::initAccel()
 {
     char cmd[4] = {
         CTRL1_XL,
-        0x38,       // Enable all axis and don't decimate data in out Registers
-        (A_ODR_104 << 5) | (aScale << 3) | (A_BW_400),   // 119 Hz ODR, set scale, and auto BW
-        0           // Default resolution mode and filtering settings
-    };
+        0x30};
 
     // Write the data to the accel control registers
-    i2c.write(xgAddress, cmd, 4);
+    i2c.write(xgAddress, cmd, 2);
 }
 
 void LSM6DS33::initIntr()
 {
-    char cmd[2];
 
 }
-
 void LSM6DS33::readAll(){
     // The data we are going to read from the temp/gyr/acc/timestamp
-    char data[14];//from 0x20 to 0x42
-    char tsdata[3];
+    //char data[14];//from 0x20 to 0x42
     
-    // Set addresses
-    char subAddressLT = OUT_TEMP_L;
-    char subAddressHT = OUT_TEMP_H;
-    char subAddressXLG = OUTX_L_G;
-    char subAddressXHG = OUTX_H_G;
-    char subAddressYLG = OUTY_L_G;
-    char subAddressYHG = OUTY_H_G;
-    char subAddressZLG = OUTZ_L_G;
-    char subAddressZHG = OUTZ_H_G;
-    char subAddressXL = OUTX_L_XL;
-    char subAddressXH = OUTX_H_XL;
-    char subAddressYL = OUTY_L_XL;
-    char subAddressYH = OUTY_H_XL;
-    char subAddressZL = OUTZ_L_XL;
-    char subAddressZH = OUTZ_H_XL;
-    char subAddressTS0 = TIMESTAMP0_REG;
-    char subAddressTS1 = TIMESTAMP1_REG;
-    char subAddressTS2 = TIMESTAMP2_REG;
-    
-    // Write the address we are going to read from and don't end the transaction
-    i2c.write(xgAddress, &subAddressLT, 1, true);
-    // Read in registers containing all the data and timestamp and don't end
-    i2c.read(xgAddress, data, 14,true);
-    i2c.write(xgAddress, &subAddressTS0, 1, true);
-    i2c.read(xgAddress, tsdata, 3);
-        
+    char data[14];
+    char tsdata[3];
+
+    i2c.start();
+    i2c.write(xgAddress);
+    i2c.write(OUT_TEMP_L);
+    i2c.start();
+    i2c.write(xgAddress | 0x1);
+    for(int i =0;i<13;i++){
+        data[i]=i2c.read(1);
+    }
+    data[13]=i2c.read(0);
+    i2c.stop();
+  
     // Temperature is a 12-bit signed integer   
     temperature_raw = data[0] | (data[1] << 8);
     gx_raw = data[2] | (data[3] << 8);
@@ -124,6 +106,18 @@
     ax_raw = data[8] | (data[9] << 8);
     ay_raw = data[10] | (data[11] << 8);
     az_raw = data[12] | (data[13] << 8);
+        
+    i2c.start();
+    i2c.write(xgAddress);
+    i2c.write(TIMESTAMP0_REG);
+    i2c.start();
+    i2c.write(xgAddress | 0x1);
+    for(int i =0;i<3;i++){
+        tsdata[i]=i2c.read(1);
+    }
+    tsdata[3]=i2c.read(0);
+    i2c.stop();
+
     time_raw = tsdata[0] | (tsdata[1] << 8) | (tsdata[2] << 16);
     
     
@@ -425,4 +419,7 @@
             aRes = 16.0 / 32768.0;
             break;
     }
-}
\ No newline at end of file
+}
+
+
+ 
\ No newline at end of file
--- a/LSM6DS33.h	Thu Oct 06 16:08:42 2016 +0000
+++ b/LSM6DS33.h	Thu Oct 06 23:28:32 2016 +0000
@@ -188,6 +188,8 @@
                 accel_scale aScl = A_SCALE_2G, gyro_odr gODR = G_ODR_104, 
                 accel_odr aODR = A_ODR_104);
     
+    void readAll();
+    
     /**  readGyro() -- Read the gyroscope output registers.
     *  This function will read all six gyroscope output registers.
     *  The readings are stored in the class' gx_raw, gy_raw, and gz_raw variables. Read
@@ -290,6 +292,7 @@
     *  be set prior to calling this function.
     */
     void calcaRes();
+    
 };
 
 #endif // _LSM6DS33_H //