base program for tilt measurement

Dependencies:   COG4050_ADT7420

Fork of COG4050_adxl355_adxl357 by ADI_CAC

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include <inttypes.h>
00003 #include "ADXL355.h"
00004  
00005 Serial pc(USBTX, USBRX);
00006  
00007 ADXL355 accl(SPI1_CS0, SPI1_MOSI, SPI1_MISO, SPI1_SCLK); // PMOD port
00008  
00009 int main(){
00010     pc.baud(9600);
00011     pc.printf("SPI ADXL355 and ADXL357 Demo\n");
00012     pc.printf("GET device ID\n");
00013     accl.reset();
00014     uint8_t d; 
00015         d=accl.read_reg(accl.DEVID_AD);
00016         pc.printf("AD id = %x \r\n",d);
00017         d=accl.read_reg(accl.DEVID_MST);
00018         pc.printf("MEMS id = %x \r\n",d);
00019         d=accl.read_reg(accl.PARTID);
00020         pc.printf("device id = %x \r\n",d);
00021         d=accl.read_reg(accl.REVID);
00022         pc.printf("revision id = %x \r\n",d);
00023     pc.printf("GET device data [x, y, z, t] \r\n");
00024     accl.set_power_ctl_reg(accl.MEASUREMENT);
00025     d=accl.read_reg(accl.POWER_CTL);
00026     pc.printf("power control on measurement mode = %x \r\n",d);
00027     uint32_t x,y,z;
00028     uint16_t t;
00029     while(1) {
00030         x = accl.scanx();
00031         y = accl.scany();
00032         z = accl.scanz();
00033         t = accl.scant();
00034         pc.printf("%u \t %u \t %u \t %u \r\n" , x,y,z,t);
00035         wait(1.0);
00036   }
00037 }
00038