base program for tilt measurement
Dependencies: COG4050_ADT7420 ADXL362
Fork of COG4050_adxl355_adxl357-ver2 by
Diff: ADXL35x/ADXL355.cpp
- Revision:
- 6:45d2393ef468
- Parent:
- 4:23b53636b576
- Child:
- 7:5aaa09c40283
--- a/ADXL35x/ADXL355.cpp Wed Aug 08 12:13:05 2018 +0000 +++ b/ADXL35x/ADXL355.cpp Tue Aug 14 06:49:07 2018 +0000 @@ -3,7 +3,6 @@ #include "ADXL355.h" -//DigitalOut(cs); ///< DigitalOut instance for the chipselect of the ADXL //DigitalOut int1; ///< DigitalOut instance for the chipselect of the ADXL //DigitalOut int2; ///< DigitalOut instance for the chipselect of the ADXL @@ -12,6 +11,8 @@ cs = 1; adxl355.format(8,_SPI_MODE); adxl355.lock(); + axis355_sens = 3.9e-6; + axis357_sens = 19.5e-6; } /** SPI bus frequency */ @@ -28,6 +29,8 @@ // Writing Code 0x52 (representing the letter, R, in ASCII or unicode) to this register immediately resets the ADXL362. write_reg(RESET, _RESET); cs = true; + axis355_sens = 3.9e-6; + axis357_sens = 19.5e-6; } /** ----------------------------------- */ /** Writes the reg register with data */ @@ -72,12 +75,12 @@ cs = true; return ret_val; } -uint32_t ADXL355::read_reg_u32(ADXL355_register_t reg){ +uint32_t ADXL355::read_reg_u20(ADXL355_register_t reg){ uint32_t ret_val = 0; adxl355.format(8, _SPI_MODE); cs = false; adxl355.write((reg<<1) | _READ_REG_CMD); - ret_val = adxl355.write(_DUMMY_BYTE); + ret_val = 0x0f & adxl355.write(_DUMMY_BYTE); ret_val = (ret_val<<8) | adxl355.write(_DUMMY_BYTE); ret_val = (ret_val<<8) | adxl355.write(_DUMMY_BYTE); cs = true; @@ -97,6 +100,20 @@ } void ADXL355::set_device(ADXL355_range_ctl_t range) { write_reg(RANGE, static_cast<uint8_t>(range)); + switch(range){ + case 0x01: + axis355_sens = 3.9e-6; + axis357_sens = 19.5e-6; + break; + case 0x02: + axis355_sens = 7.8e-6; + axis357_sens = 39e-6; + break; + case 0x03: + axis355_sens = 15.6e-6; + axis357_sens = 78e-6; + break; + } } /** ----------------------------------- */ /** Read the STATUS registers */ @@ -109,26 +126,37 @@ /** mode to read the data registers */ /** ----------------------------------- */ uint32_t ADXL355::scanx(){ - return read_reg_u32(XDATA3); + return read_reg_u20(XDATA3); } uint32_t ADXL355::scany(){ - return read_reg_u32(YDATA3); + return read_reg_u20(YDATA3); } uint32_t ADXL355::scanz(){ - return read_reg_u32(ZDATA3); + return read_reg_u20(ZDATA3); } uint16_t ADXL355::scant(){ return read_reg_u16(TEMP2); } /** ----------------------------------- */ +/** Activity SetUp - the measured */ +/** acceleration on any axis is above */ +/** the ACT_THRESH bits for ACT_COUNT */ +/** consecutive measurements. */ /** ----------------------------------- */ -void ADXL355::set_activity_axis(ADXL355_act_ctl_t axis) {} -void ADXL355::set_activity_cnt(uint8_t count) {} + +void ADXL355::set_activity_axis(ADXL355_act_ctl_t axis) { + write_reg(ACT_EN, axis); +} +void ADXL355::set_activity_cnt(uint8_t count) { + write_reg(ACT_COUNT, count); +} void ADXL355::set_activity_threshold(uint8_t data_h, uint8_t data_l) { uint16_t ret_val = static_cast<uint16_t>((data_h<<8)|data_l); write_reg_u16(ACT_THRESH_H, ret_val); } -void ADXL355::set_inactivity() {} +void ADXL355::set_inactivity() { + write_reg(ACT_EN, 0x00); +} /** ----------------------------------- */ /** ----------------------------------- */ void ADXL355::set_interrupt1_pin(PinName in, ADXL355_intmap_ctl_t mode) {}