In this lab, you will: Construct a prototype

Dependencies:   ADXL362 mbed

Revision:
1:fedb70ea0eaa
Parent:
0:d5c236ffbd5e
Child:
2:b56010953f54
diff -r d5c236ffbd5e -r fedb70ea0eaa main.cpp
--- a/main.cpp	Tue Feb 20 15:54:29 2018 +0000
+++ b/main.cpp	Tue Feb 20 20:36:42 2018 +0000
@@ -6,6 +6,8 @@
 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();
@@ -13,6 +15,9 @@
     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();
@@ -20,6 +25,7 @@
         pc.printf("x = %d y = %d z = %d\r\n",x,y,z);
         wait_ms(100);
     }
+    */
 }
 
 int adxl362_reg_print(int start, int length) {
@@ -35,13 +41,18 @@
     }
     
     // check if valid communication with device going
-    if (adxl362.read_reg(adxl362.DEVID_AD) != 0xAD) {
+    // 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 [0x2E][20]  = {
+    char regNames [37][20]  = {
          "DEVID_AD", "DEVID_MST", "PARTID",
          "REVID", "XDATA", "YDATA",
          "ZDATA", "STATUS", "FIFO_ENTRIES_L", 
@@ -55,6 +66,25 @@
          "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