CPS-Lab1
/
Lab6
In this lab, you will: Construct a prototype
main.cpp
- Committer:
- csinders
- Date:
- 2018-02-20
- Revision:
- 1:fedb70ea0eaa
- Parent:
- 0:d5c236ffbd5e
- Child:
- 2:b56010953f54
File content as of revision 1:fedb70ea0eaa:
#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 adxl362_reg_print(int start, int length); 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; adxl362_reg_print(0,1); wait_ms(1000); /* Commented out while working on adxl362_reg_print 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 // For some reason getting 0xAC instead of 0xAD? // Printing out what value we are getting int ableToRead = adxl362.read_reg(adxl362.DEVID_AD); pc.printf("ableToRead = %d\n\r", ableToRead); /* TEMPORARILY COMMENTED OUT WHILE IT IS READING INCORRECTLY if (ableToRead != 0xAD) { pc.printf("Error: Unable to read from DEVID_AD register\n\r"); return -1; } */ // String array with all of the names of the different registers in order char regNames [37][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"}; // Example for first two registers // I think their is a better way to do this, but unsure of how. for (int i = 0; i < 2; i++) { uint8_t tmp; // hex value location of the register uint8_t hexValue; // Hex value of the register // May need to increment the registers inside of the if, since the values // are not always sequential // You can find registers inside of ADXL362.h file in ADXL362 folder // they are the ADXL362_register_t if (i == 0) { tmp = adxl362.read_reg(adxl362.DEVID_AD); hexValue = 0x00; } else if (i == 1) { tmp = adxl362.read_reg(adxl362.DEVID_MST); hexValue = 0x01; } pc.printf("%#04x: %s=%#04x\n\r", hexValue, regNames[i], tmp); // Print register } return 1; // below is github with data for ADXL362 methods //https://github.com/analogdevicesinc/mbed-adi/blob/master/libraries/ADXL362/ADXL362.cpp }