CPS-Lab1
/
Lab6
In this lab, you will: Construct a prototype
main.cpp
- Committer:
- csinders
- Date:
- 2018-02-20
- Revision:
- 0:d5c236ffbd5e
- Child:
- 1:fedb70ea0eaa
File content as of revision 0:d5c236ffbd5e:
#include "mbed.h" #include "ADXL362.h" // Interface pulled from ADXL362.cpp // ADXL362::ADXL362(PinName CS, PinName MOSI, PinName MISO, PinName SCK) : ADXL362 adxl362(PA_0,PA_7,PA_6,PA_1); Serial pc(USBTX, USBRX); int main() { pc.printf("Starting program\n\r"); adxl362.reset(); wait_ms(600); // we need to wait at least 500ms after ADXL362 reset adxl362.set_mode(ADXL362::MEASUREMENT); int8_t x,y,z; while(1) { x=adxl362.scanx_u8(); y=adxl362.scany_u8(); z=adxl362.scanz_u8(); pc.printf("x = %d y = %d z = %d\r\n",x,y,z); wait_ms(100); } } int adxl362_reg_print(int start, int length) { // Check if start is within registry if (start < 0 || start > 0x2E) { pc.printf("Error: start value passed to adxl362_reg_print outside of range of registry\n\r"); return -1; } // check if length is negative if (length < 0) { pc.printf("Error: length passed to adxl362_reg_print is negative\n\r"); return -1; } // check if valid communication with device going if (adxl362.read_reg(adxl362.DEVID_AD) != 0xAD) { pc.printf("Error: Unable to read from DEVID_AD register\n\r"); } // String array with all of the names of the different registers in order char regNames [0x2E][20] = { "DEVID_AD", "DEVID_MST", "PARTID", "REVID", "XDATA", "YDATA", "ZDATA", "STATUS", "FIFO_ENTRIES_L", "FIFO_ENTRIES_H", "XDATA_L", "XDATA_H", "YDATA_L", "YDATA_H", "ZDATA_L", "ZDATA_H", "TEMP_L", "TEMP_H", "RESERVED", "RESERVED", "SOFT_RESET", "THRESH_ACT_L", "THRESH_ACT_H", "TIME_INACT_L", "TIME_ACT", "THRESH_INACT_L", "THRESH_INACT_H", "TIME_INACT_L", "TIME_INACT_H", "ACT_INACT_CTL", "FIFO_CONTROL", "FIFO_SAMPLES", "INTMAP1", "INTMATP2", "FILTER_CTL", "POWER_CTL", "SELF_TEST"}; // below is github with data for ADXL362 methods //https://github.com/analogdevicesinc/mbed-adi/blob/master/libraries/ADXL362/ADXL362.cpp }