VGR
Dependents: VITI_motor_angle_1 VITI_motor_angle_2 VITI_motor_angle_3
Diff: LSM9DS1.cpp
- Revision:
- 3:f96b287c0bf7
- Parent:
- 2:ac3b69ccd3dd
- Child:
- 4:7ffcb378cfd4
--- a/LSM9DS1.cpp Fri Jun 17 21:12:22 2016 +0000 +++ b/LSM9DS1.cpp Tue Jun 21 22:27:17 2016 +0000 @@ -60,6 +60,8 @@ setMagODR(mODR); // Set the magnetometer output data rate. setMagScale(mScale); // Set the magnetometer's range. + initIntr(); + // Once everything is initialized, return the WHO_AM_I registers we read: return (xgTest << 8) | mTest; } @@ -103,6 +105,59 @@ i2c.write(mAddress, cmd, 4); } +void LSM9DS1::initIntr() +{ + char cmd[2]; + + 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; + i2c.write(xgAddress, cmd, 2); + cmd[0] = INT_GEN_THS_XL_G + 6; + cmd[1] = (500 & 0x7F); + i2c.write(xgAddress, cmd, 2); + cmd[0] = INT_GEN_DUR_G; + cmd[1] = 0x80; + i2c.write(xgAddress, cmd, 2); + + 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; + i2c.write(xgAddress, cmd, 2); + cmd[0] = INT_GEN_DUR_XL; + cmd[1] = (1 & 0x7F); + i2c.write(xgAddress, cmd, 2); + + cmd[0] = INT1_CTRL; + cmd[1] = (1 << 7) | (1 << 6); + i2c.write(xgAddress, cmd, 2); + cmd[0] = CTRL_REG8; + cmd[1] = (1 << 5); + i2c.write(xgAddress, cmd, 2); + + cmd[0] = INT2_CTRL; + cmd[1] = (1 << 0) | (1 << 1); + i2c.write(xgAddress, cmd, 2); + cmd[0] = CTRL_REG8; + cmd[1] = (1 << 5); + i2c.write(xgAddress, cmd, 2); + + cmd[0] = INT_CFG_M; + cmd[1] = (1 << 0); + i2c.write(xgAddress, cmd, 2); + + cmd[0] = INT_THS_H_M; + cmd[1] = uint8_t((10000 & 0x7F00) >> 8); + i2c.write(xgAddress, cmd, 2); + cmd[0] = INT_THS_L_M; + cmd[1] = uint8_t(10000 & 0x00FF); + i2c.write(xgAddress, cmd, 2); +} + void LSM9DS1::readAccel() { // The data we are going to read from the accel @@ -147,6 +202,17 @@ mz = mz_raw * mRes; } +void LSM9DS1::readIntr() +{ + char data[1]; + char subAddress = INT_GEN_SRC_G; + + i2c.write(xgAddress, &subAddress, 1, true); + i2c.read(xgAddress, data, 1); + + intr = (float)data[0]; +} + void LSM9DS1::readTemp() { // The data we are going to read from the temp @@ -167,7 +233,6 @@ temperature_f = temperature_c * 1.8 + 32; } - void LSM9DS1::readGyro() { // The data we are going to read from the gyro