base program for tilt measurement
Dependencies: COG4050_ADT7420 ADXL362
Fork of COG4050_adxl355_adxl357-ver2 by
Diff: ADXL35x/ADXL355.cpp
- Revision:
- 7:5aaa09c40283
- Parent:
- 6:45d2393ef468
- Child:
- 8:9e6ead2ee8d7
--- a/ADXL35x/ADXL355.cpp Tue Aug 14 06:49:07 2018 +0000 +++ b/ADXL35x/ADXL355.cpp Tue Aug 14 11:33:30 2018 +0000 @@ -6,6 +6,9 @@ //DigitalOut int1; ///< DigitalOut instance for the chipselect of the ADXL //DigitalOut int2; ///< DigitalOut instance for the chipselect of the ADXL +/** ----------------------------------- */ +/** SPI (MAX 10MHZ) and reset */ +/** ----------------------------------- */ ADXL355::ADXL355(PinName cs_pin, PinName MOSI, PinName MISO, PinName SCK): adxl355(MOSI, MISO, SCK), cs(cs_pin) { cs = 1; @@ -13,15 +16,14 @@ adxl355.lock(); axis355_sens = 3.9e-6; axis357_sens = 19.5e-6; + calib_data.Sxx = 3.9e-6; + calib_data.Syy = 3.9e-6; + calib_data.Szz = 3.9e-6; } - -/** SPI bus frequency */ void ADXL355::frequency(int hz) { adxl355.frequency(hz); } - -/** Software resets */ void ADXL355::reset(void) { adxl355.format(8, _SPI_MODE); @@ -221,4 +223,18 @@ ret_val |= static_cast<uint64_t>(y) << 24; ret_val |= static_cast<uint64_t>(z) ; return ret_val; + } + +/** ----------------------------------- */ +/** CALIBRATION AND CONVERSION */ +/** ----------------------------------- */ +float ADXL355::convert(uint32_t data){ + // If a positive value, return it + if ((data & 0x80000) == 0) + { + return float(data); + } + //uint32_t rawValue = data<<(32-nbit); + // Otherwise perform the 2's complement math on the value + return float((~(data - 0x01)) & 0xfffff) * -1; } \ No newline at end of file