Fixed algorithm to read 3 bytes of accelerometer data registers
Fork of COG4050_adxl355_adxl357 by
main.cpp
- Committer:
- vtoffoli
- Date:
- 2018-08-14
- Revision:
- 6:45d2393ef468
- Parent:
- 5:05af38b6375a
- Child:
- 7:5aaa09c40283
File content as of revision 6:45d2393ef468:
#include "mbed.h" #include <inttypes.h> #include "ADXL355.h" Serial pc(USBTX, USBRX); ADXL355 accl(SPI1_CS0, SPI1_MOSI, SPI1_MISO, SPI1_SCLK); // PMOD port float 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; } int main(){ pc.baud(9600); pc.printf("SPI ADXL355 and ADXL357 Demo\n"); pc.printf("GET device ID\n"); accl.reset(); uint8_t d; d=accl.read_reg(accl.DEVID_AD); pc.printf("AD id = %x \r\n",d); d=accl.read_reg(accl.DEVID_MST); pc.printf("MEMS id = %x \r\n",d); d=accl.read_reg(accl.PARTID); pc.printf("device id = %x \r\n",d); d=accl.read_reg(accl.REVID); pc.printf("revision id = %x \r\n",d); pc.printf("GET device data [x, y, z, t] \r\n"); accl.set_power_ctl_reg(accl.MEASUREMENT); d=accl.read_reg(accl.POWER_CTL); pc.printf("power control on measurement mode = %x \r\n",d); float x, y,z; float t; while(1) { x = convert(accl.scanx())*accl.axis355_sens; y = convert(accl.scany())*accl.axis355_sens; z = convert(accl.scanz())*accl.axis355_sens; t = 25+float(accl.scant()-1852)/(-9.05); pc.printf("%f \t %f \t %f \t %f \r\n" , x,y,z,t); wait(0.50); } }