Rohan Gurav
/
COG4050_adxl355
Code to read the ADXL355 values using the EV COG4050.
main.cpp@0:f9431dd67dd0, 2018-08-15 (annotated)
- Committer:
- RGurav
- Date:
- Wed Aug 15 11:52:56 2018 +0000
- Revision:
- 0:f9431dd67dd0
Code to read values of the ADXL355 using the EV-COG4050
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RGurav | 0:f9431dd67dd0 | 1 | /* |
RGurav | 0:f9431dd67dd0 | 2 | Created on: 15/08/2018 |
RGurav | 0:f9431dd67dd0 | 3 | Author: Rohan Gurav |
RGurav | 0:f9431dd67dd0 | 4 | Valeria Toffoli |
RGurav | 0:f9431dd67dd0 | 5 | Code: Use the following code to read the ADXL355 values connected to the SPI channel |
RGurav | 0:f9431dd67dd0 | 6 | of the EV-COG4050-Expander board port0. Check the readme.md for connection info |
RGurav | 0:f9431dd67dd0 | 7 | |
RGurav | 0:f9431dd67dd0 | 8 | */ |
RGurav | 0:f9431dd67dd0 | 9 | #include "mbed.h" |
RGurav | 0:f9431dd67dd0 | 10 | #include <inttypes.h> |
RGurav | 0:f9431dd67dd0 | 11 | #include "ADXL355.h" |
RGurav | 0:f9431dd67dd0 | 12 | //#include "ADXRS290.h" |
RGurav | 0:f9431dd67dd0 | 13 | |
RGurav | 0:f9431dd67dd0 | 14 | Serial pc(USBTX, USBRX); |
RGurav | 0:f9431dd67dd0 | 15 | |
RGurav | 0:f9431dd67dd0 | 16 | ADXL355 accl(SPI1_CS0, SPI1_MOSI, SPI1_MISO, SPI1_SCLK); // PMOD port |
RGurav | 0:f9431dd67dd0 | 17 | //ADXRS290 gyro(SPI0_CS2, SPI0_MOSI, SPI0_MISO, SPI0_SCLK); // PMOD port |
RGurav | 0:f9431dd67dd0 | 18 | |
RGurav | 0:f9431dd67dd0 | 19 | |
RGurav | 0:f9431dd67dd0 | 20 | int main() |
RGurav | 0:f9431dd67dd0 | 21 | { |
RGurav | 0:f9431dd67dd0 | 22 | pc.baud(9600); |
RGurav | 0:f9431dd67dd0 | 23 | pc.printf("SPI ADXL355 and ADXL357 Demo\r\n"); |
RGurav | 0:f9431dd67dd0 | 24 | pc.printf("GET device ID\r\n"); |
RGurav | 0:f9431dd67dd0 | 25 | |
RGurav | 0:f9431dd67dd0 | 26 | accl.reset(); |
RGurav | 0:f9431dd67dd0 | 27 | uint8_t d; |
RGurav | 0:f9431dd67dd0 | 28 | |
RGurav | 0:f9431dd67dd0 | 29 | d=accl.read_reg(accl.DEVID_AD); |
RGurav | 0:f9431dd67dd0 | 30 | pc.printf("AD id = %x \r\n",d); |
RGurav | 0:f9431dd67dd0 | 31 | |
RGurav | 0:f9431dd67dd0 | 32 | d=accl.read_reg(accl.DEVID_MST); |
RGurav | 0:f9431dd67dd0 | 33 | pc.printf("MEMS id = %x \r\n",d); |
RGurav | 0:f9431dd67dd0 | 34 | |
RGurav | 0:f9431dd67dd0 | 35 | d=accl.read_reg(accl.PARTID); |
RGurav | 0:f9431dd67dd0 | 36 | pc.printf("device id = %x \r\n",d); |
RGurav | 0:f9431dd67dd0 | 37 | |
RGurav | 0:f9431dd67dd0 | 38 | d=accl.read_reg(accl.REVID); |
RGurav | 0:f9431dd67dd0 | 39 | pc.printf("revision id = %x \r\n",d); |
RGurav | 0:f9431dd67dd0 | 40 | |
RGurav | 0:f9431dd67dd0 | 41 | pc.printf("GET device data [x, y, z, t] \r\n"); |
RGurav | 0:f9431dd67dd0 | 42 | accl.set_power_ctl_reg(accl.MEASUREMENT); |
RGurav | 0:f9431dd67dd0 | 43 | |
RGurav | 0:f9431dd67dd0 | 44 | d=accl.read_reg(accl.POWER_CTL); |
RGurav | 0:f9431dd67dd0 | 45 | pc.printf("power control on measurement mode = %x \r\n",d); |
RGurav | 0:f9431dd67dd0 | 46 | |
RGurav | 0:f9431dd67dd0 | 47 | float x, y,z; |
RGurav | 0:f9431dd67dd0 | 48 | float t; |
RGurav | 0:f9431dd67dd0 | 49 | |
RGurav | 0:f9431dd67dd0 | 50 | /*The following part is used to perform 2's complemient and then display the data*/ |
RGurav | 0:f9431dd67dd0 | 51 | for(int i=0; i<50; i++) |
RGurav | 0:f9431dd67dd0 | 52 | { |
RGurav | 0:f9431dd67dd0 | 53 | x = accl.convert(accl.scanx())*accl.axis355_sens; |
RGurav | 0:f9431dd67dd0 | 54 | y = accl.convert(accl.scany())*accl.axis355_sens; |
RGurav | 0:f9431dd67dd0 | 55 | z = accl.convert(accl.scanz())*accl.axis355_sens; |
RGurav | 0:f9431dd67dd0 | 56 | t = 25+float(accl.scant()-1852)/(-9.05); |
RGurav | 0:f9431dd67dd0 | 57 | |
RGurav | 0:f9431dd67dd0 | 58 | pc.printf("%f \t %f \t %f \t %f \r\n" , x,y,z,t); |
RGurav | 0:f9431dd67dd0 | 59 | wait(0.1); |
RGurav | 0:f9431dd67dd0 | 60 | } |
RGurav | 0:f9431dd67dd0 | 61 | |
RGurav | 0:f9431dd67dd0 | 62 | /*------------------------------------------------------------- |
RGurav | 0:f9431dd67dd0 | 63 | // The following code will display the Raw data of the Axes |
RGurav | 0:f9431dd67dd0 | 64 | while(1) |
RGurav | 0:f9431dd67dd0 | 65 | { |
RGurav | 0:f9431dd67dd0 | 66 | x = accl.scanx(); |
RGurav | 0:f9431dd67dd0 | 67 | y = accl.scany(); |
RGurav | 0:f9431dd67dd0 | 68 | z = accl.scanz(); |
RGurav | 0:f9431dd67dd0 | 69 | t = accl.scant(); |
RGurav | 0:f9431dd67dd0 | 70 | pc.printf("%u \t %u \t %u \t %u \r\n" , x,y,z,t); |
RGurav | 0:f9431dd67dd0 | 71 | wait(1.0); |
RGurav | 0:f9431dd67dd0 | 72 | } |
RGurav | 0:f9431dd67dd0 | 73 | ----------------------------------------------------------------*/ |
RGurav | 0:f9431dd67dd0 | 74 | } |
RGurav | 0:f9431dd67dd0 | 75 |