LSM6DS3 Library

Dependents:   LSM6DS3_Demo BLE_LoopbackUART_with_LSM6DS3 I2C_LSM6DS3 angle_test ... more

Files at this revision

API Documentation at this revision

Comitter:
5hel2l2y
Date:
Tue Jun 21 20:51:25 2016 +0000
Parent:
1:924c7dea286e
Commit message:
Adding interrupt.

Changed in this revision

LSM6DS3.cpp Show annotated file Show diff for this revision Revisions of this file
LSM6DS3.h Show annotated file Show diff for this revision Revisions of this file
diff -r 924c7dea286e -r ed14e6196255 LSM6DS3.cpp
--- a/LSM6DS3.cpp	Mon Jun 20 19:15:31 2016 +0000
+++ b/LSM6DS3.cpp	Tue Jun 21 20:51:25 2016 +0000
@@ -44,6 +44,9 @@
     setAccelODR(aODR); // Set the accel data rate.
     setAccelScale(aScale); // Set the accel range.
     
+    // Interrupt initialization stuff;
+    initIntr();
+    
     // Once everything is initialized, return the WHO_AM_I registers we read:
     return xgTest;
 }
@@ -74,6 +77,27 @@
     i2c.write(xgAddress, cmd, 4);
 }
 
+void LSM6DS3::initIntr()
+{
+    char cmd[2];
+    
+    cmd[0] = TAP_CFG;
+    cmd[1] = 0x0E;
+    i2c.write(xgAddress, cmd, 2);
+    cmd[0] = TAP_THS_6D;
+    cmd[1] = 0x03;
+    i2c.write(xgAddress, cmd, 2);
+    cmd[0] = INT_DUR2;
+    cmd[1] = 0x7F;
+    i2c.write(xgAddress, cmd, 2);
+    cmd[0] = WAKE_UP_THS;
+    cmd[1] = 0x80;
+    i2c.write(xgAddress, cmd, 2);
+    cmd[0] = MD1_CFG;
+    cmd[1] = 0x48;
+    i2c.write(xgAddress, cmd, 2);
+}
+
 void LSM6DS3::readAccel()
 {
     // The data we are going to read from the accel
@@ -112,6 +136,17 @@
     az = az_raw * aRes;
 }
 
+void LSM6DS3::readIntr()
+{
+    char data[1];
+    char subAddress = TAP_SRC;
+
+    i2c.write(xgAddress, &subAddress, 1, true);
+    i2c.read(xgAddress, data, 1);
+
+    intr = (float)data[0];
+}
+
 void LSM6DS3::readTemp()
 {
     // The data we are going to read from the temp
diff -r 924c7dea286e -r ed14e6196255 LSM6DS3.h
--- a/LSM6DS3.h	Mon Jun 20 19:15:31 2016 +0000
+++ b/LSM6DS3.h	Tue Jun 21 20:51:25 2016 +0000
@@ -150,6 +150,8 @@
         A_BW_105 = 0x6,         // 105 Hz (0x6)
         A_BW_50 = 0x7           // 50 Hz (0x7)
     };
+    
+    
 
     // We'll store the gyro, and accel, readings in a series of
     // public class variables. Each sensor gets three variables -- one for each
@@ -164,6 +166,7 @@
     float gx, gy, gz;
     float ax, ay, az;
     float temperature_c, temperature_f; // temperature in celcius and fahrenheit
+    float intr;
 
     
     /**  LSM6DS3 -- LSM6DS3 class constructor
@@ -217,6 +220,9 @@
     */
     void readTemp();
     
+    /** Read Interrupt **/
+    void readIntr();
+    
     /**  setGyroScale() -- Set the full-scale range of the gyroscope.
     *  This function can be called to set the scale of the gyroscope to 
     *  245, 500, or 2000 degrees per second.
@@ -281,6 +287,9 @@
     */
     void initAccel();
     
+    /** Setup Interrupt **/
+    void initIntr();
+    
     /**  calcgRes() -- Calculate the resolution of the gyroscope.
     *  This function will set the value of the gRes variable. gScale must
     *  be set prior to calling this function.