Embedded System Design 2 - Project
ADXL362.h File Reference

All code for the ADXL362 accelerometer. More...

#include <stdint.h>
#include <stdbool.h>

Go to the source code of this file.

Typedefs

typedef enum adxl_range ADXL_Range_t
 
typedef enum adxl_odr ADXL_ODR_t
 

Enumerations

enum  adxl_range { ADXL_RANGE_2G, ADXL_RANGE_4G, ADXL_RANGE_8G }
 
enum  adxl_odr {
  ADXL_ODR_12_5_HZ, ADXL_ODR_25_HZ, ADXL_ODR_50_HZ, ADXL_ODR_100_HZ,
  ADXL_ODR_200_HZ, ADXL_ODR_400_HZ
}
 

Functions

void initADXL (void)
 Initialize the accelerometer. More...
 
void ADXL_setTriggered (bool triggered)
 Setter for the ADXL_triggered variable. More...
 
bool ADXL_getTriggered (void)
 Getter for the ADXL_triggered variable. More...
 
void ADXL_ackInterrupt (void)
 Acknowledge the interrupt from the accelerometer. More...
 
uint16_t ADXL_getCounter (void)
 Getter for the ADXL_triggercounter variable. More...
 
void ADXL_clearCounter (void)
 Method to set the ADXL_triggercounter variable back to zero. More...
 
void ADXL_enableSPI (bool enabled)
 Enable or disable the SPI pins and USART0/1 clock and peripheral to the accelerometer. More...
 
void ADXL_enableMeasure (bool enabled)
 Enable or disable measurement mode. More...
 
void ADXL_configRange (ADXL_Range_t givenRange)
 Configure the measurement range and store the selected one in a global variable for later (internal) use. More...
 
void ADXL_configODR (ADXL_ODR_t givenODR)
 Configure the Output Data Rate (ODR). More...
 
void ADXL_configActivity (uint8_t gThreshold)
 Configure the accelerometer to work in (referenced) activity threshold mode. More...
 
void ADXL_readValues (void)
 Read and display "g" values forever with a 100ms interval. More...
 
void testADXL (void)
 This method goes through all of the ODR settings to see the influence they have on power usage. The measurement range is the default one (+-2g). More...
 

Detailed Description

All code for the ADXL362 accelerometer.

Version
3.1
Author
Brecht Van Eeckhoudt

License

Copyright (C) 2019 - Brecht Van Eeckhoudt

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

A copy of the GNU General Public License can be found in the LICENSE file along with this source code.


Some methods use code obtained from examples from Silicon Labs' GitHub. These sections are licensed under the Silabs License Agreement. See the file "Silabs_License_Agreement.txt" for details. Before using this software for any purpose, you must agree to the terms of that agreement.

Definition in file ADXL362.h.

Typedef Documentation

◆ ADXL_ODR_t

typedef enum adxl_odr ADXL_ODR_t

Enum type for the ODR

◆ ADXL_Range_t

typedef enum adxl_range ADXL_Range_t

Enum type for the measurement range

Enumeration Type Documentation

◆ adxl_odr

enum adxl_odr

Enum type for the ODR

Enumerator
ADXL_ODR_12_5_HZ 
ADXL_ODR_25_HZ 
ADXL_ODR_50_HZ 
ADXL_ODR_100_HZ 
ADXL_ODR_200_HZ 
ADXL_ODR_400_HZ 

Definition at line 55 of file ADXL362.h.

56 {
57  ADXL_ODR_12_5_HZ, /* 12.5 Hz */
58  ADXL_ODR_25_HZ, /* 25 Hz */
59  ADXL_ODR_50_HZ, /* 50 Hz */
60  ADXL_ODR_100_HZ, /* 100 Hz (reset default) */
61  ADXL_ODR_200_HZ, /* 200 Hz */
62  ADXL_ODR_400_HZ /* 400 Hz */
63 } ADXL_ODR_t;
enum adxl_odr ADXL_ODR_t

◆ adxl_range

enum adxl_range

Enum type for the measurement range

Enumerator
ADXL_RANGE_2G 
ADXL_RANGE_4G 
ADXL_RANGE_8G 

Definition at line 47 of file ADXL362.h.

48 {
49  ADXL_RANGE_2G, /* +- 2g (reset default) */
50  ADXL_RANGE_4G, /* +- 4g */
51  ADXL_RANGE_8G /* +- 8g */
52 } ADXL_Range_t;
enum adxl_range ADXL_Range_t

Function Documentation

◆ ADXL_ackInterrupt()

void ADXL_ackInterrupt ( void  )

Acknowledge the interrupt from the accelerometer.

Read a certain register (necessary if the accelerometer is not in linked-loop mode) and clear the variable.

Definition at line 230 of file ADXL362.c.

231 {
233  ADXL_triggered = false;
234 }
#define ADXL_REG_STATUS
Definition: ADXL362.c:90
static uint8_t readADXL(uint8_t address)
Read an SPI byte from the accelerometer (8 bits) using a given address.
Definition: ADXL362.c:782
volatile bool ADXL_triggered
Definition: ADXL362.c:104

◆ ADXL_clearCounter()

void ADXL_clearCounter ( void  )

Method to set the ADXL_triggercounter variable back to zero.

Definition at line 188 of file ADXL362.c.

189 {
191 }
volatile uint16_t ADXL_triggercounter
Definition: ADXL362.c:105

◆ ADXL_configActivity()

void ADXL_configActivity ( uint8_t  gThreshold)

Configure the accelerometer to work in (referenced) activity threshold mode.

Route activity detector to INT1 pin using INTMAP1, isolate bits and write settings to both threshold registers.

Referenced means that during the initialization a reference acceleration gets measured (like for example 1 g on a certain axis) and stored internally. This value always gets internally subtracted from a measured acceleration value to calculate the final value and check if it exceeds the set threshold:

  • ABS(acceleration - reference) > threshold
Parameters
[in]gThresholdThreshold [g].

Definition at line 468 of file ADXL362.c.

469 {
470  /* Map activity detector to INT1 pin */
471  writeADXL(ADXL_REG_INTMAP1, 0b00010000); /* Bit 4 selects activity detector */
472 
473  /* Enable referenced activity threshold mode (last two bits) */
474  writeADXL(ADXL_REG_ACT_INACT_CTL, 0b00000011);
475 
476  /* Convert g value to "codes"
477  * THRESH_ACT [codes] = Threshold Value [g] × Scale Factor [LSB per g] */
478  uint8_t threshold;
479 
480  if (range == ADXL_RANGE_2G) threshold = gThreshold * 1000;
481  else if (range == ADXL_RANGE_4G) threshold = gThreshold * 500;
482  else if (range == ADXL_RANGE_8G) threshold = gThreshold * 250;
483  else
484  {
485 
486 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
487  dbcrit("Range wrong, can't set gThreshold!");
488 #endif /* DEBUG_DBPRINT */
489 
490  error(26);
491 
492  /* Exit function */
493  return;
494  }
495 
496  /* Isolate bits using masks and shifting */
497  uint8_t low = (threshold & 0b0011111111);
498  uint8_t high = (threshold & 0b1100000000) >> 8;
499 
500  /* Set threshold register values (total: 11bit unsigned) */
501  writeADXL(ADXL_REG_THRESH_ACT_L, low); /* 7:0 bits used */
502  writeADXL(ADXL_REG_THRESH_ACT_H, high); /* 2:0 bits used */
503 
504 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
505  dbinfoInt("ADXL362: Activity configured: ", gThreshold, "g");
506 #endif /* DEBUG_DBPRINT */
507 
508 }
static void writeADXL(uint8_t address, uint8_t data)
Write an SPI byte to the accelerometer (8 bits) using a given address and specified data...
Definition: ADXL362.c:816
void dbinfoInt(char *message1, int32_t value, char *message2)
Print an info value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:567
#define ADXL_REG_THRESH_ACT_L
Definition: ADXL362.c:94
#define ADXL_REG_THRESH_ACT_H
Definition: ADXL362.c:95
ADXL_Range_t range
Definition: ADXL362.c:107
void error(uint8_t number)
Error method.
Definition: util.c:131
#define ADXL_REG_INTMAP1
Definition: ADXL362.c:97
#define ADXL_REG_ACT_INACT_CTL
Definition: ADXL362.c:96
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
Definition: dbprint.c:539

◆ ADXL_configODR()

void ADXL_configODR ( ADXL_ODR_t  givenODR)

Configure the Output Data Rate (ODR).

Parameters
[in]givenODRThe selected ODR.

Definition at line 411 of file ADXL362.c.

412 {
413  /* Get value in register */
414  uint8_t reg = readADXL(ADXL_REG_FILTER_CTL);
415 
416  /* AND with mask to keep the bits we don't want to change */
417  reg &= 0b11111000;
418 
419  /* Set ODR (OR with new setting bits, last three bits) */
420  if (givenODR == ADXL_ODR_12_5_HZ) writeADXL(ADXL_REG_FILTER_CTL, (reg | 0b00000000));
421  else if (givenODR == ADXL_ODR_25_HZ) writeADXL(ADXL_REG_FILTER_CTL, (reg | 0b00000001));
422  else if (givenODR == ADXL_ODR_50_HZ) writeADXL(ADXL_REG_FILTER_CTL, (reg | 0b00000010));
423  else if (givenODR == ADXL_ODR_100_HZ) writeADXL(ADXL_REG_FILTER_CTL, (reg | 0b00000011));
424  else if (givenODR == ADXL_ODR_200_HZ) writeADXL(ADXL_REG_FILTER_CTL, (reg | 0b00000100));
425  else if (givenODR == ADXL_ODR_400_HZ) writeADXL(ADXL_REG_FILTER_CTL, (reg | 0b00000101));
426  else
427  {
428 
429 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
430  dbcrit("Non-existing ODR selected!");
431 #endif /* DEBUG_DBPRINT */
432 
433  error(25);
434 
435  /* Exit function */
436  return;
437  }
438 
439 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
440  if (givenODR == ADXL_ODR_12_5_HZ) dbinfo("ADXL362: ODR set at 12.5 Hz");
441  else if (givenODR == ADXL_ODR_25_HZ) dbinfo("ADXL362: ODR set at 25 Hz");
442  else if (givenODR == ADXL_ODR_50_HZ) dbinfo("ADXL362: ODR set at 50 Hz");
443  else if (givenODR == ADXL_ODR_100_HZ) dbinfo("ADXL362: ODR set at 100 Hz");
444  else if (givenODR == ADXL_ODR_200_HZ) dbinfo("ADXL362: ODR set at 200 Hz");
445  else if (givenODR == ADXL_ODR_400_HZ) dbinfo("ADXL362: ODR set at 400 Hz");
446 #endif /* DEBUG_DBPRINT */
447 
448 }
static void writeADXL(uint8_t address, uint8_t data)
Write an SPI byte to the accelerometer (8 bits) using a given address and specified data...
Definition: ADXL362.c:816
#define ADXL_REG_FILTER_CTL
Definition: ADXL362.c:99
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
Definition: dbprint.c:503
void error(uint8_t number)
Error method.
Definition: util.c:131
static uint8_t readADXL(uint8_t address)
Read an SPI byte from the accelerometer (8 bits) using a given address.
Definition: ADXL362.c:782
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
Definition: dbprint.c:539

◆ ADXL_configRange()

void ADXL_configRange ( ADXL_Range_t  givenRange)

Configure the measurement range and store the selected one in a global variable for later (internal) use.

When a range of, for example "2g" is selected, the real range is "+-2g".

Parameters
[in]givenRangeThe selected range.

Definition at line 358 of file ADXL362.c.

359 {
360  /* Get value in register */
361  uint8_t reg = readADXL(ADXL_REG_FILTER_CTL);
362 
363  /* AND with mask to keep the bits we don't want to change */
364  reg &= 0b00111111;
365 
366  /* Set measurement range (OR with new setting bits, first two bits) */
367  if (givenRange == ADXL_RANGE_2G)
368  {
369  writeADXL(ADXL_REG_FILTER_CTL, (reg | 0b00000000));
371  }
372  else if (givenRange == ADXL_RANGE_4G)
373  {
374  writeADXL(ADXL_REG_FILTER_CTL, (reg | 0b01000000));
376  }
377  else if (givenRange == ADXL_RANGE_8G)
378  {
379  writeADXL(ADXL_REG_FILTER_CTL, (reg | 0b10000000));
381  }
382  else
383  {
384 
385 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
386  dbcrit("Non-existing range selected!");
387 #endif /* DEBUG_DBPRINT */
388 
389  error(24);
390 
391  /* Exit function */
392  return;
393  }
394 
395 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
396  if (range == ADXL_RANGE_2G) dbinfo("ADXL362: Measurement mode +- 2g selected");
397  else if (range == ADXL_RANGE_4G) dbinfo("ADXL362: Measurement mode +- 4g selected");
398  else if (range == ADXL_RANGE_8G) dbinfo("ADXL362: Measurement mode +- 8g selected");
399 #endif /* DEBUG_DBPRINT */
400 
401 }
static void writeADXL(uint8_t address, uint8_t data)
Write an SPI byte to the accelerometer (8 bits) using a given address and specified data...
Definition: ADXL362.c:816
#define ADXL_REG_FILTER_CTL
Definition: ADXL362.c:99
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
Definition: dbprint.c:503
ADXL_Range_t range
Definition: ADXL362.c:107
void error(uint8_t number)
Error method.
Definition: util.c:131
static uint8_t readADXL(uint8_t address)
Read an SPI byte from the accelerometer (8 bits) using a given address.
Definition: ADXL362.c:782
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
Definition: dbprint.c:539

◆ ADXL_enableMeasure()

void ADXL_enableMeasure ( bool  enabled)

Enable or disable measurement mode.

Parameters
[in]enabled
  • true - Enable measurement mode.
  • false - Disable measurement mode (standby).

Definition at line 310 of file ADXL362.c.

311 {
312  if (enabled)
313  {
314  /* Get value in register */
315  uint8_t reg = readADXL(ADXL_REG_POWER_CTL);
316 
317  /* AND with mask to keep the bits we don't want to change */
318  reg &= 0b11111100;
319 
320  /* Enable measurements (OR with new setting bits) */
321  writeADXL(ADXL_REG_POWER_CTL, reg | 0b00000010); /* Last 2 bits are measurement mode */
322 
323 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
324  dbinfo("ADXL362: Measurement enabled");
325 #endif /* DEBUG_DBPRINT */
326 
327  }
328  else
329  {
330  /* Get value in register */
331  uint8_t reg = readADXL(ADXL_REG_POWER_CTL);
332 
333  /* AND with mask to keep the bits we don't want to change */
334  reg &= 0b11111100;
335 
336  /* Disable measurements (OR with new setting bits) */
337  writeADXL(ADXL_REG_POWER_CTL, reg | 0b00000000); /* Last 2 bits are measurement mode */
338 
339 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
340  dbinfo("ADXL362: Measurement disabled (standby)");
341 #endif /* DEBUG_DBPRINT */
342 
343  }
344 }
static void writeADXL(uint8_t address, uint8_t data)
Write an SPI byte to the accelerometer (8 bits) using a given address and specified data...
Definition: ADXL362.c:816
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
Definition: dbprint.c:503
#define ADXL_REG_POWER_CTL
Definition: ADXL362.c:100
static uint8_t readADXL(uint8_t address)
Read an SPI byte from the accelerometer (8 bits) using a given address.
Definition: ADXL362.c:782

◆ ADXL_enableSPI()

void ADXL_enableSPI ( bool  enabled)

Enable or disable the SPI pins and USART0/1 clock and peripheral to the accelerometer.

Parameters
[in]enabled
  • true - Enable the SPI pins and USART0/1 clock and peripheral to the accelerometer.
  • false - Disable the SPI pins and USART0/1 clock and peripheral to the accelerometer.

Definition at line 245 of file ADXL362.c.

246 {
247  if (enabled)
248  {
249  /* Enable USART clock and peripheral */
250  if (ADXL_SPI == USART0) CMU_ClockEnable(cmuClock_USART0, true);
251  else if (ADXL_SPI == USART1) CMU_ClockEnable(cmuClock_USART1, true);
252  else
253  {
254 
255 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
256  dbcrit("Wrong peripheral selected!");
257 #endif /* DEBUG_DBPRINT */
258 
259  error(22);
260 
261  /* Exit function */
262  return;
263  }
264 
265  USART_Enable(ADXL_SPI, usartEnable);
266 
267  /* In the case of gpioModePushPull", the last argument directly sets the pin state */
268  GPIO_PinModeSet(ADXL_CLK_PORT, ADXL_CLK_PIN, gpioModePushPull, 0); /* US0_CLK is push pull */
269  GPIO_PinModeSet(ADXL_NCS_PORT, ADXL_NCS_PIN, gpioModePushPull, 1); /* US0_CS is push pull */
270  GPIO_PinModeSet(ADXL_MOSI_PORT, ADXL_MOSI_PIN, gpioModePushPull, 1); /* US0_TX (MOSI) is push pull */
271  GPIO_PinModeSet(ADXL_MISO_PORT, ADXL_MISO_PIN, gpioModeInput, 1); /* US0_RX (MISO) is input */
272  }
273  else
274  {
275  /* Disable USART clock and peripheral */
276  if (ADXL_SPI == USART0) CMU_ClockEnable(cmuClock_USART0, false);
277  else if (ADXL_SPI == USART1) CMU_ClockEnable(cmuClock_USART1, false);
278  else
279  {
280 
281 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
282  dbcrit("Wrong peripheral selected!");
283 #endif /* DEBUG_DBPRINT */
284 
285  error(23);
286 
287  /* Exit function */
288  return;
289  }
290 
291  USART_Enable(ADXL_SPI, usartDisable);
292 
293  /* gpioModeDisabled: Pull-up if DOUT is set. */
294  GPIO_PinModeSet(ADXL_CLK_PORT, ADXL_CLK_PIN, gpioModeDisabled, 0);
295  GPIO_PinModeSet(ADXL_NCS_PORT, ADXL_NCS_PIN, gpioModeDisabled, 1);
296  GPIO_PinModeSet(ADXL_MOSI_PORT, ADXL_MOSI_PIN, gpioModeDisabled, 1);
297  GPIO_PinModeSet(ADXL_MISO_PORT, ADXL_MISO_PIN, gpioModeDisabled, 1);
298  }
299 }
#define ADXL_CLK_PORT
Definition: pin_mapping.h:72
#define ADXL_NCS_PIN
Definition: pin_mapping.h:75
#define ADXL_SPI
Definition: pin_mapping.h:66
#define ADXL_CLK_PIN
Definition: pin_mapping.h:73
#define ADXL_MOSI_PORT
Definition: pin_mapping.h:68
#define ADXL_NCS_PORT
Definition: pin_mapping.h:74
#define ADXL_MISO_PIN
Definition: pin_mapping.h:71
void error(uint8_t number)
Error method.
Definition: util.c:131
#define ADXL_MOSI_PIN
Definition: pin_mapping.h:69
#define ADXL_MISO_PORT
Definition: pin_mapping.h:70
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
Definition: dbprint.c:539

◆ ADXL_getCounter()

uint16_t ADXL_getCounter ( void  )

Getter for the ADXL_triggercounter variable.

Returns
The value of ADXL_triggercounter.

Definition at line 178 of file ADXL362.c.

179 {
180  return (ADXL_triggercounter);
181 }
volatile uint16_t ADXL_triggercounter
Definition: ADXL362.c:105

◆ ADXL_getTriggered()

bool ADXL_getTriggered ( void  )

Getter for the ADXL_triggered variable.

Returns
The value of ADXL_triggered.

Definition at line 216 of file ADXL362.c.

217 {
218  return (ADXL_triggered);
219 }
volatile bool ADXL_triggered
Definition: ADXL362.c:104

◆ ADXL_readValues()

void ADXL_readValues ( void  )

Read and display "g" values forever with a 100ms interval.

Definition at line 515 of file ADXL362.c.

516 {
517  uint32_t counter = 0;
518 
519  /* Enable measurement mode */
520  ADXL_enableMeasure(true);
521 
522  /* Infinite loop */
523  while (1)
524  {
525  led(true); /* Enable LED */
526 
527  readADXL_XYZDATA(); /* Read XYZ sensor data */
528 
529 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
530  /* Print XYZ sensor data */
531  dbprint("\r[");
532  dbprintInt(counter);
533  dbprint("] X: ");
535  dbprint(" mg | Y: ");
537  dbprint(" mg | Z: ");
539  dbprint(" mg "); /* Extra spacing is to overwrite other data if it's remaining (see \r) */
540 #endif /* DEBUG_DBPRINT */
541 
542  led(false); /* Disable LED */
543 
544  counter++;
545 
546  delay(100);
547  }
548 }
void dbprint(char *message)
Print a string (char array) to USARTx.
Definition: dbprint.c:373
void ADXL_enableMeasure(bool enabled)
Enable or disable measurement mode.
Definition: ADXL362.c:310
int8_t XYZDATA[3]
Definition: ADXL362.c:106
static void readADXL_XYZDATA(void)
Read the X-Y-Z data registers in the XYZDATA[] field using burst reads.
Definition: ADXL362.c:842
static int32_t convertGRangeToGValue(int8_t sensorValue)
Convert sensor value in +-g range to mg value.
Definition: ADXL362.c:939
void delay(uint32_t msDelay)
Wait for a certain amount of milliseconds in EM2/3.
Definition: delay.c:124
void dbprintInt(int32_t value)
Print a number in decimal notation to USARTx.
Definition: dbprint.c:738
void led(bool enabled)
Enable or disable the LED.
Definition: util.c:103

◆ ADXL_setTriggered()

void ADXL_setTriggered ( bool  triggered)

Setter for the ADXL_triggered variable.

Parameters
[in]triggered
  • true - Set ADXL_triggered to true.
  • false - Set ADXL_triggered to false.

Definition at line 202 of file ADXL362.c.

203 {
204  ADXL_triggered = triggered;
206 }
volatile uint16_t ADXL_triggercounter
Definition: ADXL362.c:105
volatile bool ADXL_triggered
Definition: ADXL362.c:104

◆ initADXL()

void initADXL ( void  )

Initialize the accelerometer.

This method calls all the other internal necessary functions. Clock enable functionality is gathered here instead of in lower (static) functions.

Definition at line 132 of file ADXL362.c.

133 {
134  /* Enable necessary clocks (just in case) */
135  CMU_ClockEnable(cmuClock_HFPER, true); /* GPIO and USART0/1 are High Frequency Peripherals */
136  CMU_ClockEnable(cmuClock_GPIO, true);
137 
138  /* Initialize and power VDD pin */
139  powerADXL(true);
140 
141  /* Power-up delay of 40 ms */
142  delay(40);
143 
144  /* Enable necessary clock (just in case) */
145  if (ADXL_SPI == USART0) CMU_ClockEnable(cmuClock_USART0, true);
146  else if (ADXL_SPI == USART1) CMU_ClockEnable(cmuClock_USART1, true);
147  else
148  {
149 
150 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
151  dbcrit("Wrong peripheral selected!");
152 #endif /* DEBUG_DBPRINT */
153 
154  /* Disable power to the VDD pin */
155  powerADXL(false);
156 
157  error(21);
158 
159  /* Exit function */
160  return;
161  }
162 
163  /* Initialize USART0/1 as SPI slave (also initialize CS pin) */
164  initADXL_SPI();
165 
166  /* Soft reset ADXL handler */
168 }
#define ADXL_SPI
Definition: pin_mapping.h:66
static void resetHandlerADXL(void)
Soft reset accelerometer handler.
Definition: ADXL362.c:697
void error(uint8_t number)
Error method.
Definition: util.c:131
static void powerADXL(bool enabled)
Enable or disable the power to the accelerometer.
Definition: ADXL362.c:875
static void initADXL_SPI(void)
Initialize USARTx in SPI mode according to the settings required by the accelerometer.
Definition: ADXL362.c:647
void delay(uint32_t msDelay)
Wait for a certain amount of milliseconds in EM2/3.
Definition: delay.c:124
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
Definition: dbprint.c:539

◆ testADXL()

void testADXL ( void  )

This method goes through all of the ODR settings to see the influence they have on power usage. The measurement range is the default one (+-2g).

To get the "correct" currents the delay method puts the MCU to EM2/3 sleep and the SPI lines are disabled. The order of the test is:

  • Wait 5 seconds
  • Soft reset the accelerometer
  • One second in "standby" mode
  • Enable "measurement" mode
  • One second in ODR 12.5 Hz
  • One second in ODR 25 Hz
  • One second in ODR 50 Hz
  • One second in ODR 100 Hz
  • One second in ODR 200 Hz
  • One second in ODR 400 Hz
  • Soft reset the accelerometer

Definition at line 571 of file ADXL362.c.

572 {
573  delay(5000);
574 
575  /* Soft reset ADXL */
576  softResetADXL();
577 
578  /* Standby */
579  ADXL_enableSPI(false); /* Disable SPI functionality */
580  delay(1000);
581  ADXL_enableSPI(true); /* Enable SPI functionality */
582 
583  /* ODR 12,5Hz */
584  writeADXL(ADXL_REG_FILTER_CTL, 0b00010000); /* last 3 bits are ODR */
585 
586  /* Enable measurements */
587  writeADXL(ADXL_REG_POWER_CTL, 0b00000010); /* last 2 bits are measurement mode */
588 
589  ADXL_enableSPI(false); /* Disable SPI functionality */
590  delay(1000);
591  ADXL_enableSPI(true); /* Enable SPI functionality */
592 
593  /* ODR 25Hz */
594  writeADXL(ADXL_REG_FILTER_CTL, 0b00010001); /* last 3 bits are ODR */
595 
596  ADXL_enableSPI(false); /* Disable SPI functionality */
597  delay(1000);
598  ADXL_enableSPI(true); /* Enable SPI functionality */
599 
600  /* ODR 50Hz */
601  writeADXL(ADXL_REG_FILTER_CTL, 0b00010010); /* last 3 bits are ODR */
602 
603  ADXL_enableSPI(false); /* Disable SPI functionality */
604  delay(1000);
605  ADXL_enableSPI(true); /* Enable SPI functionality */
606 
607  /* ODR 100Hz (default) */
608  writeADXL(ADXL_REG_FILTER_CTL, 0b00010011); /* last 3 bits are ODR */
609 
610  ADXL_enableSPI(false); /* Disable SPI functionality */
611  delay(1000);
612  ADXL_enableSPI(true); /* Enable SPI functionality */
613 
614  /* ODR 200Hz */
615  writeADXL(ADXL_REG_FILTER_CTL, 0b00010100); /* last 3 bits are ODR */
616 
617  ADXL_enableSPI(false); /* Disable SPI functionality */
618  delay(1000);
619  ADXL_enableSPI(true); /* Enable SPI functionality */
620 
621  /* ODR 400Hz */
622  writeADXL(ADXL_REG_FILTER_CTL, 0b00010101); /* last 3 bits are ODR */
623 
624  ADXL_enableSPI(false); /* Disable SPI functionality */
625  delay(1000);
626  ADXL_enableSPI(true); /* Enable SPI functionality */
627 
628  /* Soft reset ADXL */
629  softResetADXL();
630 }
static void writeADXL(uint8_t address, uint8_t data)
Write an SPI byte to the accelerometer (8 bits) using a given address and specified data...
Definition: ADXL362.c:816
#define ADXL_REG_FILTER_CTL
Definition: ADXL362.c:99
#define ADXL_REG_POWER_CTL
Definition: ADXL362.c:100
void delay(uint32_t msDelay)
Wait for a certain amount of milliseconds in EM2/3.
Definition: delay.c:124
void ADXL_enableSPI(bool enabled)
Enable or disable the SPI pins and USART0/1 clock and peripheral to the accelerometer.
Definition: ADXL362.c:245
static void softResetADXL(void)
Soft reset accelerometer.
Definition: ADXL362.c:901