debugging library
Fork of LIS3DH by
Diff: LIS3DH.cpp
- Revision:
- 9:c32d2b25d4c2
- Parent:
- 8:0999d25ed7bc
- Child:
- 10:18b993cca7ab
--- a/LIS3DH.cpp Wed Aug 23 09:26:06 2017 +0000 +++ b/LIS3DH.cpp Sat Jun 09 09:12:34 2018 +0000 @@ -24,7 +24,10 @@ : _i2c_p(new I2C(p_sda, p_scl)), _i2c(*_i2c_p) { _i2c.frequency(400000); - initialize (addr, LIS3DH_DR_NR_LP_50HZ, LIS3DH_FS_8G); + initialize (addr, LIS3DH_DR_NR_LP_50HZ, LIS3DH_FS_8G); //tsai: change this to 10Hz, 16uA to 8uA. + //initialize (addr, LIS3DH_DR_NR_LP_10HZ, LIS3DH_FS_8G); //8uA consumption at 10Hz + // LIS3DH_DR_NR_LP_10HZ = 2 + // LIS3DH_FS_8G = 2, full scale } LIS3DH::LIS3DH (I2C& p_i2c, @@ -57,14 +60,35 @@ } // Reg.1 dt[0] = LIS3DH_CTRL_REG1; - dt[1] = 0x07; - dt[1] |= data_rate << 4; - _i2c.write(acc_addr, dt, 2, false); + dt[1] = 0x07; //0000 0111 + dt[1] |= data_rate << 4; // 0000 0111 |= 0010 0000 ---> 0010 0111; 10Hz, high res, xyz enbabled. + + //note: dt[1]=0x0F; //low resolution; @ datarate; Must also zero out CTRL_REG4[3] + //dt[1] = 0x07; + _i2c.write(acc_addr, dt, 2, false); //address, command, bytes + + + // Reg.4 dt[0] = LIS3DH_CTRL_REG4; - dt[1] = 0x08; // High resolution - dt[1] |= fullscale << 4; + dt[1] = 0x08; // High resolution //0000 1000 + dt[1] |= fullscale << 4; // + //fullscale = 0000 0010 + //fullscale << 4 = 0010 0000 + //result of OR = 0010 1000 ----> + // continuous update + // endian, LSB @ lowest address + // 10 = 8G scale + // High resolution (10bit) ENABLED + // 0, 0 N/A + _i2c.write(acc_addr, dt, 2, false); + + + + + + switch (fullscale) { case LIS3DH_FS_2G: fs_factor = LIS3DH_SENSITIVITY_2G; @@ -83,6 +107,8 @@ } } + + void LIS3DH::read_reg_data(char *data) { // X,Y & Z @@ -189,4 +215,42 @@ } } - +uint8_t LIS3DH::setAct(uint8_t addr) +{ + uint8_t ret_val; + + // Check acc is available of not + acc_addr = addr; + dt[0] = LIS3DH_WHO_AM_I; + _i2c.write(acc_addr, dt, 1, true); + _i2c.read(acc_addr, dt, 1, false); + if (dt[0] == I_AM_LIS3DH) { + acc_ready = 1; + ret_val=1; + } else { + acc_ready = 0; + ret_val=2; + return ret_val; // acc chip is NOT on I2C line then terminate + } + + //Tsai: add INT + //tsai: reg. INT1_CFG + dt[0] = LIS3DH_INT1_CFG; + dt[1] = 0x3f; // 0111 1111 = movement in all xyz + _i2c.write(acc_addr, dt, 2, false); + + + //tsai: reg. LIS3DH_INT1_THS + dt[0] = LIS3DH_INT1_THS; + //0-127; I was at 10 out of 127 @ 16mg LSB; + dt[1] = 0x02; // 0000 0010 //62mg @ 8g full scale; want 38 == + _i2c.write(acc_addr, dt, 2, false); + + /* + //tsai: reg. INT1_DURATION + dt[0] = LIS3DH_INT1_DURATION; + dt[1] = 0x01; // short? + _i2c.write(acc_addr, dt, 2, false); + */ + return ret_val; +}