Rohan Gurav / Mbed OS COG4050_adxl355

Dependencies:   ADXL355

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002 Created on: 15/08/2018
00003 Author: Rohan Gurav
00004         Valeria Toffoli
00005 Code: Use the following code to read the ADXL355 values connected to the SPI channel 
00006       of the EV-COG4050-Expander board port0. Check the readme.md for connection info  
00007 
00008 */
00009 #include "mbed.h"
00010 #include <inttypes.h>
00011 #include "ADXL355.h"
00012 //#include "ADXRS290.h"
00013 
00014 Serial pc(USBTX, USBRX);
00015 
00016 ADXL355 accl(SPI1_CS0, SPI1_MOSI, SPI1_MISO, SPI1_SCLK);    // PMOD port
00017 //ADXRS290 gyro(SPI0_CS2, SPI0_MOSI, SPI0_MISO, SPI0_SCLK);   // PMOD port
00018 
00019     
00020 int main()
00021 {
00022     pc.baud(9600);
00023     pc.printf("SPI ADXL355 and ADXL357 Demo\r\n");
00024     pc.printf("GET device ID\r\n");
00025    
00026     accl.reset();
00027     uint8_t d; 
00028     
00029     d=accl.read_reg(accl.DEVID_AD);
00030     pc.printf("AD id = %x \r\n",d);
00031     
00032     d=accl.read_reg(accl.DEVID_MST);
00033     pc.printf("MEMS id = %x \r\n",d);
00034     
00035     d=accl.read_reg(accl.PARTID);
00036     pc.printf("device id = %x \r\n",d);
00037     
00038     d=accl.read_reg(accl.REVID);
00039     pc.printf("revision id = %x \r\n",d);
00040     
00041     pc.printf("GET device data [x, y, z, t] \r\n");
00042     accl.set_power_ctl_reg(accl.MEASUREMENT);
00043     
00044     d=accl.read_reg(accl.POWER_CTL);
00045     pc.printf("power control on measurement mode = %x \r\n",d);
00046     
00047     float x, y,z;
00048     float t;
00049     
00050     /*The following part is used to perform 2's complemient and then display the data*/
00051     for(int i=0; i<50; i++) 
00052     {
00053         x = accl.convert(accl.scanx())*accl.axis355_sens;
00054         y = accl.convert(accl.scany())*accl.axis355_sens;
00055         z = accl.convert(accl.scanz())*accl.axis355_sens;
00056         t = 25+float(accl.scant()-1852)/(-9.05);
00057     
00058         pc.printf("%f \t %f \t %f  \t %f \r\n" , x,y,z,t);
00059         wait(0.1);
00060     }
00061     
00062 /*-------------------------------------------------------------    
00063     // The following code will display the Raw data of the Axes 
00064      while(1) 
00065     {
00066         x = accl.scanx();
00067         y = accl.scany();
00068         z = accl.scanz();
00069         t = accl.scant();
00070         pc.printf("%u \t %u \t %u \t %u \r\n" , x,y,z,t);
00071         wait(1.0);
00072     }
00073 ----------------------------------------------------------------*/
00074 }
00075