Lab6_

Dependencies:   ADXL362 mbed

Fork of Lab6 by Jackie Youngs

Committer:
youngs2
Date:
Thu Feb 22 18:11:48 2018 +0000
Revision:
0:36f6b91a8ff8
Child:
1:308da76c50c5
asdfghjkl;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
youngs2 0:36f6b91a8ff8 1 #include "mbed.h"
youngs2 0:36f6b91a8ff8 2 #include "ADXL362.h"
youngs2 0:36f6b91a8ff8 3
youngs2 0:36f6b91a8ff8 4 // Interface pulled from ADXL362.cpp
youngs2 0:36f6b91a8ff8 5 // ADXL362::ADXL362(PinName CS, PinName MOSI, PinName MISO, PinName SCK) :
youngs2 0:36f6b91a8ff8 6 ADXL362 adxl362(PA_0,PA_7,PA_6,PA_1);
youngs2 0:36f6b91a8ff8 7
youngs2 0:36f6b91a8ff8 8
youngs2 0:36f6b91a8ff8 9 int adxl362_reg_print(int start, int length) {
youngs2 0:36f6b91a8ff8 10 if(length == 0)
youngs2 0:36f6b91a8ff8 11 length = 42;
youngs2 0:36f6b91a8ff8 12 int i = start, end = start + length;
youngs2 0:36f6b91a8ff8 13 if(start > 0x2E || start < 0x00)
youngs2 0:36f6b91a8ff8 14 return(-1);
youngs2 0:36f6b91a8ff8 15 if(length < 0)
youngs2 0:36f6b91a8ff8 16 return(-1);
youngs2 0:36f6b91a8ff8 17 if (adxl362.read_reg((ADXL362::ADXL362_register_t) 0x00) != 0xAD)
youngs2 0:36f6b91a8ff8 18 return(-1);
youngs2 0:36f6b91a8ff8 19 for( i = start; i <= end; i++) {
youngs2 0:36f6b91a8ff8 20 //0x16 -> 0x1E not used
youngs2 0:36f6b91a8ff8 21 //0x04 -> 0x07 not used
youngs2 0:36f6b91a8ff8 22 if (i == 0x04) i = 0x08;
youngs2 0:36f6b91a8ff8 23 if (i == 0x16) i = 0x1F;
youngs2 0:36f6b91a8ff8 24 char name[25];
youngs2 0:36f6b91a8ff8 25 uint8_t regval = adxl362.read_reg((ADXL362::ADXL362_register_t) i);
youngs2 0:36f6b91a8ff8 26 switch (i) {
youngs2 0:36f6b91a8ff8 27 case 0x00:
youngs2 0:36f6b91a8ff8 28 strcpy(name,"DEVID_A");
youngs2 0:36f6b91a8ff8 29 break;
youngs2 0:36f6b91a8ff8 30 case 0x01:
youngs2 0:36f6b91a8ff8 31 strcpy(name,"DEVID_MST");
youngs2 0:36f6b91a8ff8 32 break;
youngs2 0:36f6b91a8ff8 33 case 0x02:
youngs2 0:36f6b91a8ff8 34 strcpy(name, "PARTID");
youngs2 0:36f6b91a8ff8 35 break;
youngs2 0:36f6b91a8ff8 36 case 0x03:
youngs2 0:36f6b91a8ff8 37 strcpy(name,"REVID");
youngs2 0:36f6b91a8ff8 38 break;
youngs2 0:36f6b91a8ff8 39 case 0x08:
youngs2 0:36f6b91a8ff8 40 strcpy(name,"XDATA");
youngs2 0:36f6b91a8ff8 41 break;
youngs2 0:36f6b91a8ff8 42 case 0x09:
youngs2 0:36f6b91a8ff8 43 strcpy(name,"YDATA");
youngs2 0:36f6b91a8ff8 44 break;
youngs2 0:36f6b91a8ff8 45 case 0x0A:
youngs2 0:36f6b91a8ff8 46 strcpy(name,"ZDATA");
youngs2 0:36f6b91a8ff8 47 break;
youngs2 0:36f6b91a8ff8 48 case 0x0B:
youngs2 0:36f6b91a8ff8 49 strcpy(name,"STATUS");
youngs2 0:36f6b91a8ff8 50 break;
youngs2 0:36f6b91a8ff8 51 case 0x0C:
youngs2 0:36f6b91a8ff8 52 strcpy(name,"FIFO_ENTRIES_L");
youngs2 0:36f6b91a8ff8 53 break;
youngs2 0:36f6b91a8ff8 54 case 0x0D:
youngs2 0:36f6b91a8ff8 55 strcpy(name,"FIFO_ENTRIES_H");
youngs2 0:36f6b91a8ff8 56 break;
youngs2 0:36f6b91a8ff8 57 case 0x0E:
youngs2 0:36f6b91a8ff8 58 strcpy(name,"XDATA_L");
youngs2 0:36f6b91a8ff8 59 break;
youngs2 0:36f6b91a8ff8 60 case 0x0F:
youngs2 0:36f6b91a8ff8 61 strcpy(name,"XDATA_H");
youngs2 0:36f6b91a8ff8 62 break;
youngs2 0:36f6b91a8ff8 63 case 0x10:
youngs2 0:36f6b91a8ff8 64 strcpy(name,"YDATA_L");
youngs2 0:36f6b91a8ff8 65 break;
youngs2 0:36f6b91a8ff8 66 case 0x11:
youngs2 0:36f6b91a8ff8 67 strcpy(name,"YDATA_H");
youngs2 0:36f6b91a8ff8 68 break;
youngs2 0:36f6b91a8ff8 69 case 0x12:
youngs2 0:36f6b91a8ff8 70 strcpy(name,"ZDATA_L");
youngs2 0:36f6b91a8ff8 71 break;
youngs2 0:36f6b91a8ff8 72 case 0x13:
youngs2 0:36f6b91a8ff8 73 strcpy(name,"ZDATA_H");
youngs2 0:36f6b91a8ff8 74 break;
youngs2 0:36f6b91a8ff8 75 case 0x14:
youngs2 0:36f6b91a8ff8 76 strcpy(name,"TEMP_L");
youngs2 0:36f6b91a8ff8 77 break;
youngs2 0:36f6b91a8ff8 78 case 0x15:
youngs2 0:36f6b91a8ff8 79 strcpy(name,"TEMP_H");
youngs2 0:36f6b91a8ff8 80 break;
youngs2 0:36f6b91a8ff8 81 case 0x1F:
youngs2 0:36f6b91a8ff8 82 strcpy(name,"SOFT_RESET");
youngs2 0:36f6b91a8ff8 83 break;
youngs2 0:36f6b91a8ff8 84 case 0x20:
youngs2 0:36f6b91a8ff8 85 strcpy(name,"THRESH_ACT_L");
youngs2 0:36f6b91a8ff8 86 break;
youngs2 0:36f6b91a8ff8 87 case 0x21:
youngs2 0:36f6b91a8ff8 88 strcpy(name,"THRESH_ACT_H");
youngs2 0:36f6b91a8ff8 89 break;
youngs2 0:36f6b91a8ff8 90 case 0x22:
youngs2 0:36f6b91a8ff8 91 strcpy(name,"TIME_ACT");
youngs2 0:36f6b91a8ff8 92 break;
youngs2 0:36f6b91a8ff8 93 case 0x23:
youngs2 0:36f6b91a8ff8 94 strcpy(name,"THRES_INACT_L");
youngs2 0:36f6b91a8ff8 95 break;
youngs2 0:36f6b91a8ff8 96 case 0x24:
youngs2 0:36f6b91a8ff8 97 strcpy(name,"THRESH_INACT_H");
youngs2 0:36f6b91a8ff8 98 break;
youngs2 0:36f6b91a8ff8 99 case 0x25:
youngs2 0:36f6b91a8ff8 100 strcpy(name,"TIME_INACT_L");
youngs2 0:36f6b91a8ff8 101 break;
youngs2 0:36f6b91a8ff8 102 case 0x26:
youngs2 0:36f6b91a8ff8 103 strcpy(name,"TIME_INACT_H");
youngs2 0:36f6b91a8ff8 104 break;
youngs2 0:36f6b91a8ff8 105 case 0x27:
youngs2 0:36f6b91a8ff8 106 strcpy(name,"ACT_INACT_CTL");
youngs2 0:36f6b91a8ff8 107 break;
youngs2 0:36f6b91a8ff8 108 case 0x28:
youngs2 0:36f6b91a8ff8 109 strcpy(name,"FIFO_CONTROL");
youngs2 0:36f6b91a8ff8 110 break;
youngs2 0:36f6b91a8ff8 111 case 0x29:
youngs2 0:36f6b91a8ff8 112 strcpy(name,"FIFO_SAMPLES");
youngs2 0:36f6b91a8ff8 113 break;
youngs2 0:36f6b91a8ff8 114 case 0x2A:
youngs2 0:36f6b91a8ff8 115 strcpy(name,"INTMAP1");
youngs2 0:36f6b91a8ff8 116 break;
youngs2 0:36f6b91a8ff8 117 case 0x2B:
youngs2 0:36f6b91a8ff8 118 strcpy(name,"INTMAP2");
youngs2 0:36f6b91a8ff8 119 break;
youngs2 0:36f6b91a8ff8 120 case 0x2C:
youngs2 0:36f6b91a8ff8 121 strcpy(name,"FILTER_CTL");
youngs2 0:36f6b91a8ff8 122 break;
youngs2 0:36f6b91a8ff8 123 case 0x2D:
youngs2 0:36f6b91a8ff8 124 strcpy(name,"POWER_CTL");
youngs2 0:36f6b91a8ff8 125 break;
youngs2 0:36f6b91a8ff8 126 case 0x2E:
youngs2 0:36f6b91a8ff8 127 strcpy(name,"SELF_TEST");
youngs2 0:36f6b91a8ff8 128 break;
youngs2 0:36f6b91a8ff8 129 default:
youngs2 0:36f6b91a8ff8 130 printf("ERR\n\r");
youngs2 0:36f6b91a8ff8 131 }
youngs2 0:36f6b91a8ff8 132 printf("%x: %s = %x\n\r", i, name, regval);
youngs2 0:36f6b91a8ff8 133
youngs2 0:36f6b91a8ff8 134 }
youngs2 0:36f6b91a8ff8 135 return(0);
youngs2 0:36f6b91a8ff8 136 }
youngs2 0:36f6b91a8ff8 137
youngs2 0:36f6b91a8ff8 138
youngs2 0:36f6b91a8ff8 139
youngs2 0:36f6b91a8ff8 140 int main() {
youngs2 0:36f6b91a8ff8 141 adxl362.reset();
youngs2 0:36f6b91a8ff8 142 wait_ms(600); // we need to wait at least 500ms after ADXL362 reset
youngs2 0:36f6b91a8ff8 143 adxl362.set_mode(ADXL362::MEASUREMENT);
youngs2 0:36f6b91a8ff8 144 while(1) {
youngs2 0:36f6b91a8ff8 145 int return_val = adxl362_reg_print(0, 0);
youngs2 0:36f6b91a8ff8 146 //add scans to ask user input
youngs2 0:36f6b91a8ff8 147 }
youngs2 0:36f6b91a8ff8 148
youngs2 0:36f6b91a8ff8 149 /*int8_t x,y,z;
youngs2 0:36f6b91a8ff8 150
youngs2 0:36f6b91a8ff8 151 while(1) {
youngs2 0:36f6b91a8ff8 152 x=adxl362.scanx_u8();
youngs2 0:36f6b91a8ff8 153 y=adxl362.scany_u8();
youngs2 0:36f6b91a8ff8 154 z=adxl362.scanz_u8();
youngs2 0:36f6b91a8ff8 155 //printf("x = %d y = %d z = %d\r\n",x,y,z);
youngs2 0:36f6b91a8ff8 156 wait_ms(100);
youngs2 0:36f6b91a8ff8 157 }*/
youngs2 0:36f6b91a8ff8 158 }