Timo Karppinen / Mbed OS Pmod_ACL2_ADXL362_L432KC_OS6_tk1

Dependencies:   ADXL362

Committer:
timo_k2
Date:
Wed Apr 28 14:48:15 2021 +0000
Revision:
7:652e2c5ad650
Parent:
6:a0b604602460
Sensor reading is in a separate thread. The results can be used in the main thread.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
timo_k2 6:a0b604602460 1 /*
timo_k2 6:a0b604602460 2 * Copyright (c) 2006-2020 Arm Limited and affiliates.
timo_k2 6:a0b604602460 3 * SPDX-License-Identifier: Apache-2.0
timo_k2 6:a0b604602460 4 *******************************************************************************
timo_k2 6:a0b604602460 5 * Pmod_ACL2_ADXL362_L432KC_OS6
timo_k2 6:a0b604602460 6 *
timo_k2 6:a0b604602460 7 * Accelerations in 3D with Analog Devices ADXL362. The PmodACL2 was used but
timo_k2 6:a0b604602460 8 * should work with almost any sensor module with the ADXL362.
timo_k2 6:a0b604602460 9 * The ADXL362 connects with SPI. The library ADXL362 published by Analog Devises
timo_k2 6:a0b604602460 10 * includes the necessary methods for setting up the sensor and reading the
timo_k2 6:a0b604602460 11 * acceleration results.
timo_k2 6:a0b604602460 12 *
timo_k2 6:a0b604602460 13 * Hardware
timo_k2 6:a0b604602460 14 * ST NUCLEO L432KC or almost any other MbedOS microcontroller,
timo_k2 6:a0b604602460 15 * Digilent PmodACL2 sensor module with the ADXL362 acceleration sensor
timo_k2 6:a0b604602460 16 * A LED with 220 Ohm series resistor for indicating movement
timo_k2 6:a0b604602460 17 *
timo_k2 6:a0b604602460 18 * Connect:
timo_k2 6:a0b604602460 19 * L432KC D13 - ACL2 4 SCLK hardware defined for the SPI
timo_k2 6:a0b604602460 20 * L432KC D12 - ACL2 3 MISO hardware defined for the SPI
timo_k2 6:a0b604602460 21 * L432KC D11 - ACL2 2 MOSI
timo_k2 6:a0b604602460 22 * L432KC D5 - ACL2 1 CS or any other free
timo_k2 6:a0b604602460 23 * GND - ACL2 5 GND
timo_k2 6:a0b604602460 24 * Vcc - ACL2 6 Vcc
timo_k2 6:a0b604602460 25 * The ACL2 pins 7 and 8 will be connected if hardware interrupts will be used.
timo_k2 6:a0b604602460 26 * L432KC D1 - LED - 220 Ohm - GND
timo_k2 6:a0b604602460 27 *
timo_k2 6:a0b604602460 28 * Reference:
timo_k2 6:a0b604602460 29 * PmodACL2 https://reference.digilentinc.com/reference/pmod/pmodacl2/start
timo_k2 6:a0b604602460 30 * ADXL362 https://www.analog.com/en/products/adxl362.html
timo_k2 6:a0b604602460 31 * Datasheet for register reference
timo_k2 6:a0b604602460 32 * https://www.analog.com/media/en/technical-documentation/data-sheets/ADXL362.pdf
timo_k2 6:a0b604602460 33 *
timo_k2 6:a0b604602460 34 * Timo Karppinen 30.12.2020 Apache-2.0
timo_k2 6:a0b604602460 35 ******************************************************************************/
timo_k2 6:a0b604602460 36
jackclar 0:1ca806626aba 37 #include "mbed.h"
jackclar 0:1ca806626aba 38 #include "ADXL362.h"
timo_k2 7:652e2c5ad650 39 #include <cmath>
timo_k2 7:652e2c5ad650 40 #define BUFF_SIZE 6
timo_k2 5:4d6ef028eeae 41
jackclar 0:1ca806626aba 42 // ADXL362::ADXL362(PinName CS, PinName MOSI, PinName MISO, PinName SCK) :
timo_k2 5:4d6ef028eeae 43 ADXL362 ADXL362(D5,D11,D12,D13);
timo_k2 5:4d6ef028eeae 44
timo_k2 7:652e2c5ad650 45 //Threads
timo_k2 7:652e2c5ad650 46 Thread detect_thread;
timo_k2 7:652e2c5ad650 47
timo_k2 5:4d6ef028eeae 48 DigitalOut moveLed(D1);
jackclar 0:1ca806626aba 49
jackclar 2:3299365b3e3c 50 int ADXL362_reg_print(int start, int length);
timo_k2 7:652e2c5ad650 51 int ADXL362_movement_detect();
timo_k2 7:652e2c5ad650 52 int acceleration3D(int8_t ax,int8_t ay,int8_t az);
jackclar 0:1ca806626aba 53
timo_k2 7:652e2c5ad650 54 int8_t x,y,z;
timo_k2 7:652e2c5ad650 55 int movementDetected = 0;
timo_k2 7:652e2c5ad650 56 int i = 0;
timo_k2 7:652e2c5ad650 57
timo_k2 7:652e2c5ad650 58
timo_k2 7:652e2c5ad650 59 int main(){
timo_k2 7:652e2c5ad650 60
jackclar 2:3299365b3e3c 61 ADXL362.reset();
timo_k2 5:4d6ef028eeae 62 // we need to wait at least 500ms after ADXL362 reset
timo_k2 5:4d6ef028eeae 63 ThisThread::sleep_for(600ms);
jackclar 2:3299365b3e3c 64 ADXL362.set_mode(ADXL362::MEASUREMENT);
jackclar 4:a6069cbc4c71 65 ADXL362_reg_print(0, 0);
timo_k2 7:652e2c5ad650 66 detect_thread.start(ADXL362_movement_detect);
timo_k2 7:652e2c5ad650 67
timo_k2 7:652e2c5ad650 68 while(1){
timo_k2 7:652e2c5ad650 69 moveLed.write(movementDetected);
timo_k2 7:652e2c5ad650 70 if(movementDetected){
timo_k2 7:652e2c5ad650 71 i += 1;
timo_k2 7:652e2c5ad650 72 printf("i = %d\n", i);
timo_k2 7:652e2c5ad650 73 }
timo_k2 7:652e2c5ad650 74 printf("Acceleration 3D %d\n", acceleration3D(x,y,z));
timo_k2 7:652e2c5ad650 75 ThisThread::sleep_for(1s);
timo_k2 7:652e2c5ad650 76 }
jackclar 2:3299365b3e3c 77 }
jackclar 2:3299365b3e3c 78
timo_k2 7:652e2c5ad650 79 int ADXL362_movement_detect()
jackclar 2:3299365b3e3c 80 {
timo_k2 7:652e2c5ad650 81 int8_t x1,y1,z1,x2,y2,z2,dx,dy,dz;
timo_k2 7:652e2c5ad650 82 int detect;
timo_k2 7:652e2c5ad650 83 while(1){
timo_k2 7:652e2c5ad650 84 x1=ADXL362.scanx_u8();
timo_k2 7:652e2c5ad650 85 y1=ADXL362.scany_u8();
timo_k2 7:652e2c5ad650 86 z1=ADXL362.scanz_u8();
timo_k2 7:652e2c5ad650 87 ThisThread::sleep_for(10ms);
timo_k2 7:652e2c5ad650 88 x2=ADXL362.scanx_u8();
timo_k2 7:652e2c5ad650 89 y2=ADXL362.scany_u8();
timo_k2 7:652e2c5ad650 90 z2=ADXL362.scanz_u8();
jackclar 2:3299365b3e3c 91
timo_k2 7:652e2c5ad650 92 x=(x1 + x2)/2;
timo_k2 7:652e2c5ad650 93 y=(y1 + y2)/2;
timo_k2 7:652e2c5ad650 94 z=(z1 + z2)/2;
timo_k2 7:652e2c5ad650 95
timo_k2 7:652e2c5ad650 96 dx=abs(x1 - x2);
timo_k2 7:652e2c5ad650 97 dy=abs(y1 - y2);
timo_k2 7:652e2c5ad650 98 dz=abs(z1 - z2);
timo_k2 7:652e2c5ad650 99
timo_k2 7:652e2c5ad650 100 if (dx>10 || dy>10 || dz>10){
timo_k2 7:652e2c5ad650 101 detect = 1;
timo_k2 7:652e2c5ad650 102 }
timo_k2 7:652e2c5ad650 103 else{
timo_k2 7:652e2c5ad650 104 detect = 0;
timo_k2 7:652e2c5ad650 105 }
timo_k2 7:652e2c5ad650 106 movementDetected = detect;
timo_k2 7:652e2c5ad650 107 printf("x = %3d y = %3d z = %3d dx = %3d dy = %3d dz = %3d\r\n",x,y,z,dx,dy,dz);
timo_k2 7:652e2c5ad650 108 ThisThread::sleep_for(100ms);
timo_k2 7:652e2c5ad650 109 }
timo_k2 7:652e2c5ad650 110 }
timo_k2 7:652e2c5ad650 111
timo_k2 7:652e2c5ad650 112 int acceleration3D(int8_t ax,int8_t ay,int8_t az){
timo_k2 7:652e2c5ad650 113 float acc3D;
timo_k2 7:652e2c5ad650 114 static int count = 0;
timo_k2 7:652e2c5ad650 115 static int8_t x1[BUFF_SIZE];
timo_k2 7:652e2c5ad650 116 static int8_t y1[BUFF_SIZE];
timo_k2 7:652e2c5ad650 117 static int8_t z1[BUFF_SIZE];
timo_k2 7:652e2c5ad650 118 float averx;
timo_k2 7:652e2c5ad650 119 float avery;
timo_k2 7:652e2c5ad650 120 float averz;
timo_k2 7:652e2c5ad650 121
timo_k2 7:652e2c5ad650 122 if(count >= BUFF_SIZE){
timo_k2 7:652e2c5ad650 123 count = 0;
jackclar 2:3299365b3e3c 124 }
timo_k2 7:652e2c5ad650 125
timo_k2 7:652e2c5ad650 126 x1[count]=ax;
timo_k2 7:652e2c5ad650 127 y1[count]=ay;
timo_k2 7:652e2c5ad650 128 z1[count]=az;
timo_k2 7:652e2c5ad650 129
timo_k2 7:652e2c5ad650 130 count += 1;
timo_k2 7:652e2c5ad650 131
timo_k2 7:652e2c5ad650 132 averx=0.0;
timo_k2 7:652e2c5ad650 133 avery=0.0;
timo_k2 7:652e2c5ad650 134 averz=0.0;
timo_k2 7:652e2c5ad650 135 for(int k=0; k<BUFF_SIZE; k++){
timo_k2 7:652e2c5ad650 136 averx = averx+(float)x1[k];
timo_k2 7:652e2c5ad650 137 avery = avery+(float)y1[k];
timo_k2 7:652e2c5ad650 138 averz = averz+(float)z1[k];
timo_k2 7:652e2c5ad650 139 }
timo_k2 7:652e2c5ad650 140 averx=averx/BUFF_SIZE;
timo_k2 7:652e2c5ad650 141 avery=avery/BUFF_SIZE;
timo_k2 7:652e2c5ad650 142 averz=averz/BUFF_SIZE;
timo_k2 7:652e2c5ad650 143
timo_k2 7:652e2c5ad650 144 acc3D = sqrtf(pow(averx,2)+pow(avery,2)+pow(averz,2));
timo_k2 7:652e2c5ad650 145 //acc3D = sqrtf(pow(3.0,2) + pow(3.0,2) + pow(3.0,2));
timo_k2 7:652e2c5ad650 146 return((int)acc3D);
timo_k2 7:652e2c5ad650 147 }
jackclar 0:1ca806626aba 148
jackclar 2:3299365b3e3c 149 int ADXL362_reg_print(int start, int length)
timo_k2 5:4d6ef028eeae 150 /*
timo_k2 5:4d6ef028eeae 151 * The register bit allocations are explained in the datasheet
timo_k2 5:4d6ef028eeae 152 * https://www.analog.com/media/en/technical-documentation/data-sheets/ADXL362.pdf
timo_k2 5:4d6ef028eeae 153 * starting on page 23.
timo_k2 5:4d6ef028eeae 154 */
jackclar 0:1ca806626aba 155 {
jackclar 2:3299365b3e3c 156 uint8_t i;
timo_k2 5:4d6ef028eeae 157 char name[32];
timo_k2 5:4d6ef028eeae 158 char note[64];
timo_k2 5:4d6ef028eeae 159
jackclar 2:3299365b3e3c 160 ADXL362::ADXL362_register_t reg;
jackclar 4:a6069cbc4c71 161 if(start >= 0x00 && start <= 0x2E && length >= 0x00 && (ADXL362.read_reg(ADXL362.DEVID_AD) == 0xAD))
jackclar 0:1ca806626aba 162 {
jackclar 2:3299365b3e3c 163 if(length == 0)
jackclar 2:3299365b3e3c 164 {
jackclar 2:3299365b3e3c 165 start = 0;
jackclar 2:3299365b3e3c 166 length = 47;
jackclar 2:3299365b3e3c 167 }
jackclar 2:3299365b3e3c 168
jackclar 2:3299365b3e3c 169 for(i = start; i < start + length; i++)
jackclar 0:1ca806626aba 170 {
jackclar 2:3299365b3e3c 171 switch(i)
jackclar 2:3299365b3e3c 172 {
jackclar 2:3299365b3e3c 173 case 0x00:
timo_k2 5:4d6ef028eeae 174 snprintf(name, 32, "DEVID_AD" );
timo_k2 5:4d6ef028eeae 175 snprintf(note, 64, "default 0xAD = I am the ADXL362");
jackclar 2:3299365b3e3c 176 reg = ADXL362.DEVID_AD;
jackclar 2:3299365b3e3c 177 break;
jackclar 2:3299365b3e3c 178 case 0x01:
timo_k2 5:4d6ef028eeae 179 snprintf(name, 32, "DEVID_MST" );
timo_k2 5:4d6ef028eeae 180 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 181 reg = ADXL362.DEVID_MST;
jackclar 2:3299365b3e3c 182 break;
jackclar 2:3299365b3e3c 183 case 0x02:
timo_k2 5:4d6ef028eeae 184 snprintf(name, 32, "PARTID" );
timo_k2 5:4d6ef028eeae 185 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 186 reg = ADXL362.PARTID;
jackclar 2:3299365b3e3c 187 break;
jackclar 2:3299365b3e3c 188 case 0x03:
timo_k2 5:4d6ef028eeae 189 snprintf(name, 32, "REVID" );
timo_k2 5:4d6ef028eeae 190 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 191 reg = ADXL362.REVID;
jackclar 2:3299365b3e3c 192 break;
jackclar 2:3299365b3e3c 193 case 0x08:
timo_k2 5:4d6ef028eeae 194 snprintf(name, 32, "XDATA" );
timo_k2 5:4d6ef028eeae 195 snprintf(note, 63, "binary 8bit, two's complement");
jackclar 2:3299365b3e3c 196 reg = ADXL362.XDATA;
jackclar 2:3299365b3e3c 197 break;
jackclar 2:3299365b3e3c 198 case 0x09:
timo_k2 5:4d6ef028eeae 199 snprintf(name, 32, "YDATA" );
timo_k2 5:4d6ef028eeae 200 snprintf(note, 64, "binary 8bit, two's complement");
jackclar 2:3299365b3e3c 201 reg = ADXL362.YDATA;
jackclar 2:3299365b3e3c 202 break;
jackclar 2:3299365b3e3c 203 case 0x0A:
timo_k2 5:4d6ef028eeae 204 snprintf(name, 32, "ZDATA" );
timo_k2 5:4d6ef028eeae 205 snprintf(note, 64, "binary 8bit, two's complement");
jackclar 2:3299365b3e3c 206 reg = ADXL362.ZDATA;
jackclar 2:3299365b3e3c 207 break;
jackclar 2:3299365b3e3c 208 case 0x0B:
timo_k2 5:4d6ef028eeae 209 snprintf(name, 32, "STATUS" );
timo_k2 5:4d6ef028eeae 210 snprintf(note, 64, "typically 0x41, 4=awake, 1=data ready");
jackclar 2:3299365b3e3c 211 reg = ADXL362.STATUS;
jackclar 2:3299365b3e3c 212 break;
jackclar 2:3299365b3e3c 213 case 0x0C:
timo_k2 5:4d6ef028eeae 214 snprintf(name, 32, "FIFO_ENTRIES_L" );
timo_k2 5:4d6ef028eeae 215 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 216 reg = ADXL362.FIFO_ENTRIES_L;
jackclar 2:3299365b3e3c 217 break;
jackclar 2:3299365b3e3c 218 case 0x0D:
timo_k2 5:4d6ef028eeae 219 snprintf(name, 32, "FIFO_ENTRIES_H" );
timo_k2 5:4d6ef028eeae 220 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 221 reg = ADXL362.FIFO_ENTRIES_H;
jackclar 2:3299365b3e3c 222 break;
jackclar 2:3299365b3e3c 223 case 0x0E:
timo_k2 5:4d6ef028eeae 224 snprintf(name, 32, "XDATA_L" );
timo_k2 5:4d6ef028eeae 225 snprintf(note, 64, "binary 12bit, two's complement");
jackclar 2:3299365b3e3c 226 reg = ADXL362.XDATA_L;
jackclar 2:3299365b3e3c 227 break;
jackclar 2:3299365b3e3c 228 case 0x0F:
timo_k2 5:4d6ef028eeae 229 snprintf(name, 32, "XDATA_H" );
timo_k2 5:4d6ef028eeae 230 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 231 reg = ADXL362.XDATA_H;
jackclar 2:3299365b3e3c 232 break;
jackclar 2:3299365b3e3c 233 case 0x10:
timo_k2 5:4d6ef028eeae 234 snprintf(name, 32, "YDATA_L" );
timo_k2 5:4d6ef028eeae 235 snprintf(note, 64, "binary 12bit, two's complement");
jackclar 2:3299365b3e3c 236 reg = ADXL362.YDATA_L;
jackclar 2:3299365b3e3c 237 break;
jackclar 2:3299365b3e3c 238 case 0x11:
timo_k2 5:4d6ef028eeae 239 snprintf(name, 32, "YDATA_H" );
timo_k2 5:4d6ef028eeae 240 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 241 reg = ADXL362.YDATA_H;
jackclar 2:3299365b3e3c 242 break;
jackclar 2:3299365b3e3c 243 case 0x12:
timo_k2 5:4d6ef028eeae 244 snprintf(name, 32, "ZDATA_L" );
timo_k2 5:4d6ef028eeae 245 snprintf(note, 64, "binary 12bit, two's complement");
jackclar 2:3299365b3e3c 246 reg = ADXL362.ZDATA_L;
jackclar 2:3299365b3e3c 247 break;
jackclar 2:3299365b3e3c 248 case 0x13:
timo_k2 5:4d6ef028eeae 249 snprintf(name, 32, "ZDATA_H" );
timo_k2 5:4d6ef028eeae 250 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 251 reg = ADXL362.ZDATA_H;
jackclar 2:3299365b3e3c 252 break;
jackclar 2:3299365b3e3c 253 case 0x14:
timo_k2 5:4d6ef028eeae 254 snprintf(name, 32, "TEMP_L" );
timo_k2 5:4d6ef028eeae 255 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 256 reg = ADXL362.TEMP_L;
jackclar 2:3299365b3e3c 257 break;
jackclar 2:3299365b3e3c 258 case 0x15:
timo_k2 5:4d6ef028eeae 259 snprintf(name, 32, "TEMP_H" );
timo_k2 5:4d6ef028eeae 260 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 261 reg = ADXL362.TEMP_H;
jackclar 2:3299365b3e3c 262 break;
jackclar 2:3299365b3e3c 263 case 0x1F:
timo_k2 5:4d6ef028eeae 264 snprintf(name, 32, "SOFT_RESET" );
timo_k2 5:4d6ef028eeae 265 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 266 reg = ADXL362.SOFT_RESET;
jackclar 2:3299365b3e3c 267 break;
jackclar 2:3299365b3e3c 268 case 0x20:
timo_k2 5:4d6ef028eeae 269 snprintf(name, 32, "THRESH_ACT_L" );
timo_k2 5:4d6ef028eeae 270 snprintf(note, 64, "Activity threshold value, binary 16bit");
jackclar 2:3299365b3e3c 271 reg = ADXL362.THRESH_ACT_L;
jackclar 2:3299365b3e3c 272 break;
jackclar 2:3299365b3e3c 273 case 0x21:
timo_k2 5:4d6ef028eeae 274 snprintf(name, 32, "THRESH_ACT_H" );
timo_k2 5:4d6ef028eeae 275 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 276 reg = ADXL362.THRESH_ACT_H;
jackclar 2:3299365b3e3c 277 break;
jackclar 2:3299365b3e3c 278 case 0x22:
timo_k2 5:4d6ef028eeae 279 snprintf(name, 32, "TIME_ACT" );
timo_k2 5:4d6ef028eeae 280 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 281 reg = ADXL362.TIME_ACT;
jackclar 2:3299365b3e3c 282 break;
jackclar 2:3299365b3e3c 283 case 0x23:
timo_k2 5:4d6ef028eeae 284 snprintf(name, 32, "THRESH_INACT_L" );
timo_k2 5:4d6ef028eeae 285 snprintf(note, 64, "Inactivity threshold value, binary 16bit");
jackclar 2:3299365b3e3c 286 reg = ADXL362.THRESH_INACT_L;
jackclar 2:3299365b3e3c 287 break;
jackclar 2:3299365b3e3c 288 case 0x24:
timo_k2 5:4d6ef028eeae 289 snprintf(name, 32, "THRESH_INACT_H" );
timo_k2 5:4d6ef028eeae 290 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 291 reg = ADXL362.THRESH_INACT_H;
jackclar 2:3299365b3e3c 292 break;
jackclar 2:3299365b3e3c 293 case 0x25:
timo_k2 5:4d6ef028eeae 294 snprintf(name, 32, "TIME_INACT_L" );
timo_k2 5:4d6ef028eeae 295 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 296 reg = ADXL362.TIME_INACT_L;
jackclar 2:3299365b3e3c 297 break;
jackclar 2:3299365b3e3c 298 case 0x26:
timo_k2 5:4d6ef028eeae 299 snprintf(name, 32, "TIME_INACT_H" );
timo_k2 5:4d6ef028eeae 300 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 301 reg = ADXL362.TIME_INACT_H;
jackclar 2:3299365b3e3c 302 break;
jackclar 2:3299365b3e3c 303 case 0x27:
timo_k2 5:4d6ef028eeae 304 snprintf(name, 32, "ACT_INACT_CTL" );
timo_k2 5:4d6ef028eeae 305 snprintf(note, 64, "default 0x00 = disable, 0x01 = enable");
jackclar 2:3299365b3e3c 306 reg = ADXL362.ACT_INACT_CTL;
jackclar 2:3299365b3e3c 307 break;
jackclar 2:3299365b3e3c 308 case 0x28:
timo_k2 5:4d6ef028eeae 309 snprintf(name, 32, "FIFO_CONTROL" );
timo_k2 5:4d6ef028eeae 310 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 311 reg = ADXL362.FIFO_CONTROL;
jackclar 2:3299365b3e3c 312 break;
jackclar 2:3299365b3e3c 313 case 0x29:
timo_k2 5:4d6ef028eeae 314 snprintf(name, 32, "FIFO_SAMPLES" );
timo_k2 5:4d6ef028eeae 315 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 316 reg = ADXL362.FIFO_SAMPLES;
jackclar 2:3299365b3e3c 317 break;
jackclar 2:3299365b3e3c 318 case 0x2A:
timo_k2 5:4d6ef028eeae 319 snprintf(name, 32, "INTMAP1" );
timo_k2 5:4d6ef028eeae 320 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 321 reg = ADXL362.INTMAP1;
jackclar 2:3299365b3e3c 322 break;
jackclar 2:3299365b3e3c 323 case 0x2B:
timo_k2 5:4d6ef028eeae 324 snprintf(name, 32, "INTMAP2" );
timo_k2 5:4d6ef028eeae 325 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 326 reg = ADXL362.INTMAP2;
jackclar 2:3299365b3e3c 327 break;
jackclar 2:3299365b3e3c 328 case 0x2C:
timo_k2 5:4d6ef028eeae 329 snprintf(name, 32, "FILTER_CTL" );
timo_k2 5:4d6ef028eeae 330 snprintf(note, 64, "default 0x13, 1=half samplin freq, 3=freq 100 sampl/sec");
jackclar 2:3299365b3e3c 331 reg = ADXL362.FILTER_CTL;
jackclar 2:3299365b3e3c 332 break;
jackclar 2:3299365b3e3c 333 case 0x2D:
timo_k2 5:4d6ef028eeae 334 snprintf(name, 32, "POWER_CTL" );
timo_k2 5:4d6ef028eeae 335 snprintf(note, 64, "default 0x02 = measure 3D");
jackclar 2:3299365b3e3c 336 reg = ADXL362.POWER_CTL;
jackclar 2:3299365b3e3c 337 break;
jackclar 2:3299365b3e3c 338 case 0x2E:
timo_k2 5:4d6ef028eeae 339 snprintf(name, 32, "SELF_TEST" );
timo_k2 5:4d6ef028eeae 340 snprintf(note, 64, "-");
jackclar 2:3299365b3e3c 341 reg = ADXL362.SELF_TEST;
jackclar 2:3299365b3e3c 342 break;
jackclar 2:3299365b3e3c 343 }
timo_k2 5:4d6ef028eeae 344 // Printing register content as hexadecimal and the notes
timo_k2 5:4d6ef028eeae 345 printf("register %d %s %x %s\n", i, name, ADXL362.read_reg(reg), note);
jackclar 0:1ca806626aba 346 }
jackclar 0:1ca806626aba 347 }
jackclar 0:1ca806626aba 348 else
jackclar 0:1ca806626aba 349 {
timo_k2 5:4d6ef028eeae 350 printf("Error");
jackclar 2:3299365b3e3c 351 return(-1);
jackclar 2:3299365b3e3c 352 }
jackclar 2:3299365b3e3c 353 return(0);
timo_k2 5:4d6ef028eeae 354 }