Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: LSM9DS1.cpp
- Revision:
- 4:7ffcb378cfd4
- Parent:
- 3:f96b287c0bf7
- Child:
- 6:28c4b3c8b43d
--- 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);
}