Modified LSM9DS1 Library

Dependents:   LSM9DS1_Demo BLE_LoopbackUART_with_LSM9DS1 BLE_LoopbackUART_with_LSM9DS1-2

Fork of LSM9DS1 by Eugene Gonzalez

Files at this revision

API Documentation at this revision

Comitter:
5hel2l2y
Date:
Wed Jun 22 22:11:37 2016 +0000
Parent:
3:f96b287c0bf7
Commit message:
Modified interrupt initialization.

Changed in this revision

LSM9DS1.cpp Show annotated file Show diff for this revision Revisions of this file
LSM9DS1.h Show annotated file Show diff for this revision Revisions of this file
--- a/LSM9DS1.cpp	Tue Jun 21 22:27:17 2016 +0000
+++ b/LSM9DS1.cpp	Wed Jun 22 22:11:37 2016 +0000
@@ -60,6 +60,7 @@
     setMagODR(mODR); // Set the magnetometer output data rate.
     setMagScale(mScale); // Set the magnetometer's range.
     
+    // Interrupt initialization stuff
     initIntr();
     
     // Once everything is initialized, return the WHO_AM_I registers we read:
@@ -108,53 +109,69 @@
 void LSM9DS1::initIntr()
 {   
     char cmd[2];
+    uint16_t thresholdG = 500;
+    uint8_t durationG = 10;
+    uint8_t thresholdX = 20;
+    uint8_t durationX = 1;
+    uint16_t thresholdM = 10000;
     
+    // 1. Configure the gyro interrupt generator
     cmd[0] = INT_GEN_CFG_G;
     cmd[1] = (1 << 5);
     i2c.write(xgAddress, cmd, 2);
-    cmd[0] = INT_GEN_THS_XH_G + 6;
-    cmd[1] = (500 & 0x7F) >> 8;
+    // 2. Configure the gyro threshold
+    cmd[0] = INT_GEN_THS_ZH_G;
+    cmd[1] = (thresholdG & 0x7F00) >> 8;
     i2c.write(xgAddress, cmd, 2);
-    cmd[0] = INT_GEN_THS_XL_G + 6;
-    cmd[1] = (500 & 0x7F);
+    cmd[0] = INT_GEN_THS_ZL_G;
+    cmd[1] = (thresholdG & 0x00FF);
     i2c.write(xgAddress, cmd, 2);
     cmd[0] = INT_GEN_DUR_G;
-    cmd[1] = 0x80;
+    cmd[1] = (durationG & 0x7F) | 0x80;
     i2c.write(xgAddress, cmd, 2);
     
+    // 3. Configure accelerometer interrupt generator
     cmd[0] = INT_GEN_CFG_XL;
     cmd[1] = (1 << 1);
     i2c.write(xgAddress, cmd, 2);
-    cmd[0] = INT_GEN_THS_X_XL + 1;
-    cmd[1] = 20;
+    // 4. Configure accelerometer threshold
+    cmd[0] = INT_GEN_THS_X_XL;
+    cmd[1] = thresholdX;
     i2c.write(xgAddress, cmd, 2);
     cmd[0] = INT_GEN_DUR_XL;
-    cmd[1] = (1 & 0x7F);
+    cmd[1] = (durationX & 0x7F);
     i2c.write(xgAddress, cmd, 2);
     
+    // 5. Configure INT1 - assign it to gyro interrupt
     cmd[0] = INT1_CTRL;
+//    cmd[1] = 0xC0;
     cmd[1] = (1 << 7) | (1 << 6);
     i2c.write(xgAddress, cmd, 2);
     cmd[0] = CTRL_REG8;
-    cmd[1] = (1 << 5);
+//    cmd[1] = 0x04;
+    cmd[1] = (1 << 2) | (1 << 5) | (1 << 4);
     i2c.write(xgAddress, cmd, 2);
     
+    // Configure interrupt 2 to fire whenever new accelerometer
+    // or gyroscope data is available.
     cmd[0] = INT2_CTRL;
     cmd[1] = (1 << 0) | (1 << 1);
     i2c.write(xgAddress, cmd, 2);
     cmd[0] = CTRL_REG8;
-    cmd[1] = (1 << 5);
+    cmd[1] = (1 << 2) | (1 << 5) | (1 << 4);
     i2c.write(xgAddress, cmd, 2);
     
+    // Configure magnetometer interrupt
     cmd[0] = INT_CFG_M;
-    cmd[1] = (1 << 0);
+    cmd[1] = (1 << 7) | (1 << 0);
     i2c.write(xgAddress, cmd, 2);
     
+    // Configure magnetometer threshold
     cmd[0] = INT_THS_H_M;
-    cmd[1] = uint8_t((10000 & 0x7F00) >> 8);
+    cmd[1] = uint8_t((thresholdM & 0x7F00) >> 8);
     i2c.write(xgAddress, cmd, 2);
     cmd[0] = INT_THS_L_M;
-    cmd[1] = uint8_t(10000 & 0x00FF);
+    cmd[1] = uint8_t(thresholdM & 0x00FF);
     i2c.write(xgAddress, cmd, 2);
 }
 
--- a/LSM9DS1.h	Tue Jun 21 22:27:17 2016 +0000
+++ b/LSM9DS1.h	Wed Jun 22 22:11:37 2016 +0000
@@ -260,6 +260,8 @@
     *  those _after_ calling readMag().
     */
     void readMag();
+    
+    /** Read Interrupt **/
     void readIntr();
     
     /**  readTemp() -- Read the temperature output register.
@@ -350,6 +352,7 @@
     */
     void initAccel();
     
+    /** Initialize Interrupts **/
     void initIntr();
     
     /**  initMag() -- Sets up the magnetometer to begin reading.