LSM303DLHC library with Free Fall Interrupt Initialisation.
Fork of LSM303DLHC by
Diff: LSM303DLHC.cpp
- Revision:
- 6:0b1dad2f6270
- Parent:
- 5:ee458711d467
- Child:
- 7:1dabdf7beada
--- a/LSM303DLHC.cpp Wed Feb 03 20:08:41 2016 +0000 +++ b/LSM303DLHC.cpp Thu Aug 23 18:11:09 2018 +0000 @@ -11,6 +11,8 @@ * http://www.pololu.com/ * http://forum.pololu.com/ * + * FREE FALL INTERRUPT CODE ADDED BY TASOS CHARISIS + * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without @@ -49,7 +51,13 @@ OUT_Z_M = 0x07, /* --- Acc --- */ CTRL_REG1_A = 0x20, + CTRL_REG3_A = 0x22, CTRL_REG4_A = 0x23, + CTRL_REG5_A = 0x24, + REFERENCE_A = 0x26, + INT1_CFG_A = 0x30, + INT1_THS_A = 0x32, + INT1_DURATION_A = 0x33, OUT_X_A = 0x28, OUT_Y_A = 0x2A, OUT_Z_A = 0x2C, @@ -84,17 +92,17 @@ reg_v = 0; - reg_v |= 0x37; /* X/Y/Z axis enable. */ + reg_v |= 0x57; /* Normal mode 100 Hz X/Y/Z axis enable. */ write_reg(addr_acc,CTRL_REG1_A,reg_v); reg_v = 0; // reg_v |= 0x01 << 6; /* 1: data MSB @ lower address */ - reg_v = 0x01 << 4; /* +/- 4g */ + reg_v = 0x10 << 4; /* +/- 8g */ write_reg(addr_acc,CTRL_REG4_A,reg_v); /* -- mag --- */ reg_v = 0; - reg_v |= 0x06 << 2; /* Minimum data output rate = 15Hz */ + reg_v |= 0x06 << 2; /* Minimum magnetic data output rate = 75Hz */ write_reg(addr_mag,CRA_REG_M,reg_v); reg_v = 0; @@ -104,6 +112,23 @@ reg_v = 0; /* Continuous-conversion mode */ write_reg(addr_mag,MR_REG_M,reg_v); + +/** ------------------------FREE FALL INTERRUPT SETTINGS------------------------------------------- +--------------------CALIBRATION VALUES ARE g THRESHOLD AND DURATION---------------------------------- +**/ + + //Setup Free Fall INT as INT1 + reg_v = 0x40; /* AOI1 interrupt on INT1 */ + write_reg(addr_acc,CTRL_REG3_A,reg_v); + + reg_v = 0x32; /* 50 Counts --> 0.2g at +- 8g scale (4mg/LSB*/ + write_reg(addr_acc,INT1_THS_A,reg_v); + + reg_v = 0x5; /* 5 Counts --> 50ms duration at 100Hz sampling */ + write_reg(addr_acc,INT1_DURATION_A,reg_v); + + reg_v = 0x95; /* Enable AOI and low events not high on all axes */ + write_reg(addr_acc,INT1_CFG_A,reg_v); } @@ -120,10 +145,10 @@ *mz = float(short(mag[2] << 8 | mag[3]))/980; *my = float(short(mag[4] << 8 | mag[5]))/1100; - return true; + return 1; } - return false; + return 0; }