83 #define ADXL_REG_DEVID_AD 0x00 84 #define ADXL_REG_DEVID_MST 0x01 85 #define ADXL_REG_PARTID 0x02 86 #define ADXL_REG_REVID 0x03 87 #define ADXL_REG_XDATA 0x08 88 #define ADXL_REG_YDATA 0x09 89 #define ADXL_REG_ZDATA 0x0A 90 #define ADXL_REG_STATUS 0x0B 91 #define ADXL_REG_TEMP_L 0x14 92 #define ADXL_REG_TEMP_H 0x15 93 #define ADXL_REG_SOFT_RESET 0x1F 94 #define ADXL_REG_THRESH_ACT_L 0x20 95 #define ADXL_REG_THRESH_ACT_H 0x21 96 #define ADXL_REG_ACT_INACT_CTL 0x27 97 #define ADXL_REG_INTMAP1 0x2A 98 #define ADXL_REG_INTMAP2 0x2B 99 #define ADXL_REG_FILTER_CTL 0x2C 100 #define ADXL_REG_POWER_CTL 0x2D 116 static uint8_t
readADXL (uint8_t address);
135 CMU_ClockEnable(cmuClock_HFPER,
true);
136 CMU_ClockEnable(cmuClock_GPIO,
true);
145 if (
ADXL_SPI == USART0) CMU_ClockEnable(cmuClock_USART0,
true);
146 else if (
ADXL_SPI == USART1) CMU_ClockEnable(cmuClock_USART1,
true);
150 #if DEBUG_DBPRINT == 1 151 dbcrit(
"Wrong peripheral selected!");
250 if (
ADXL_SPI == USART0) CMU_ClockEnable(cmuClock_USART0,
true);
251 else if (
ADXL_SPI == USART1) CMU_ClockEnable(cmuClock_USART1,
true);
255 #if DEBUG_DBPRINT == 1 256 dbcrit(
"Wrong peripheral selected!");
265 USART_Enable(
ADXL_SPI, usartEnable);
276 if (
ADXL_SPI == USART0) CMU_ClockEnable(cmuClock_USART0,
false);
277 else if (
ADXL_SPI == USART1) CMU_ClockEnable(cmuClock_USART1,
false);
281 #if DEBUG_DBPRINT == 1 282 dbcrit(
"Wrong peripheral selected!");
291 USART_Enable(
ADXL_SPI, usartDisable);
323 #if DEBUG_DBPRINT == 1 324 dbinfo(
"ADXL362: Measurement enabled");
339 #if DEBUG_DBPRINT == 1 340 dbinfo(
"ADXL362: Measurement disabled (standby)");
385 #if DEBUG_DBPRINT == 1 386 dbcrit(
"Non-existing range selected!");
395 #if DEBUG_DBPRINT == 1 429 #if DEBUG_DBPRINT == 1 430 dbcrit(
"Non-existing ODR selected!");
439 #if DEBUG_DBPRINT == 1 486 #if DEBUG_DBPRINT == 1 487 dbcrit(
"Range wrong, can't set gThreshold!");
497 uint8_t low = (threshold & 0b0011111111);
498 uint8_t high = (threshold & 0b1100000000) >> 8;
504 #if DEBUG_DBPRINT == 1 505 dbinfoInt(
"ADXL362: Activity configured: ", gThreshold,
"g");
517 uint32_t counter = 0;
529 #if DEBUG_DBPRINT == 1 657 USART_InitSync_TypeDef config = USART_INITSYNC_DEFAULT;
660 config.enable =
false;
662 config.baudrate = 4000000;
663 config.databits = usartDatabits8;
664 config.master =
true;
666 config.clockMode = usartClockMode0;
667 config.prsRxEnable =
false;
668 config.autoTx =
false;
669 config.autoCsEnable =
false;
675 ADXL_SPI->ROUTE = USART_ROUTE_CLKPEN | USART_ROUTE_CSPEN | USART_ROUTE_TXPEN | USART_ROUTE_RXPEN |
ADXL_SPI_LOC;
678 USART_Enable(
ADXL_SPI, usartEnable);
681 GPIO_PinOutSet(gpioPortE, 13);
747 #if DEBUG_DBPRINT == 1 748 dbcrit(
"ADXL362 initialization failed");
760 #if DEBUG_DBPRINT == 1 761 if (retries < 2)
dbinfoInt(
"ADXL362 initialized (", retries,
" soft reset retries)");
762 else dbwarnInt(
"ADXL362 initialized (had to \"hard reset\", ", retries,
" soft reset retries)");
791 USART_SpiTransfer(
ADXL_SPI, address);
792 response = USART_SpiTransfer(
ADXL_SPI, 0x00);
823 USART_SpiTransfer(
ADXL_SPI, address);
952 #if DEBUG_DBPRINT == 1 953 dbcrit(
"Range wrong, can't calculate mg value!");
void ADXL_ackInterrupt(void)
Acknowledge the interrupt from the accelerometer.
void dbprint(char *message)
Print a string (char array) to USARTx.
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...
void dbinfoInt(char *message1, int32_t value, char *message2)
Print an info value surrounded by two strings (char array) to USARTx.
#define ADXL_REG_THRESH_ACT_L
bool ADXL_getTriggered(void)
Getter for the ADXL_triggered variable.
static void resetHandlerADXL(void)
Soft reset accelerometer handler.
#define ADXL_REG_THRESH_ACT_H
All code for the ADXL362 accelerometer.
bool ADXL_VDD_initialized
void ADXL_readValues(void)
Read and display "g" values forever with a 100ms interval.
void ADXL_enableMeasure(bool enabled)
Enable or disable measurement mode.
void dbwarnInt(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
#define ADXL_REG_FILTER_CTL
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
void ADXL_configODR(ADXL_ODR_t givenODR)
Configure the Output Data Rate (ODR).
static void readADXL_XYZDATA(void)
Read the X-Y-Z data registers in the XYZDATA[] field using burst reads.
uint16_t ADXL_getCounter(void)
Getter for the ADXL_triggercounter variable.
static int32_t convertGRangeToGValue(int8_t sensorValue)
Convert sensor value in +-g range to mg value.
void ADXL_configActivity(uint8_t gThreshold)
Configure the accelerometer to work in (referenced) activity threshold mode.
void error(uint8_t number)
Error method.
void testADXL(void)
This method goes through all of the ODR settings to see the influence they have on power usage...
#define ADXL_REG_POWER_CTL
static void powerADXL(bool enabled)
Enable or disable the power to the accelerometer.
volatile uint16_t ADXL_triggercounter
static void initADXL_SPI(void)
Initialize USARTx in SPI mode according to the settings required by the accelerometer.
The pin definitions for the regular and custom Happy Gecko board.
void ADXL_configRange(ADXL_Range_t givenRange)
Configure the measurement range and store the selected one in a global variable for later (internal) ...
Enable or disable printing to UART with dbprint.
void delay(uint32_t msDelay)
Wait for a certain amount of milliseconds in EM2/3.
void dbprintInt(int32_t value)
Print a number in decimal notation to USARTx.
void ADXL_clearCounter(void)
Method to set the ADXL_triggercounter variable back to zero.
#define ADXL_REG_DEVID_AD
enum adxl_range ADXL_Range_t
#define ADXL_REG_ACT_INACT_CTL
static uint8_t readADXL(uint8_t address)
Read an SPI byte from the accelerometer (8 bits) using a given address.
#define ADXL_REG_SOFT_RESET
void initADXL(void)
Initialize the accelerometer.
void ADXL_setTriggered(bool triggered)
Setter for the ADXL_triggered variable.
volatile bool ADXL_triggered
void ADXL_enableSPI(bool enabled)
Enable or disable the SPI pins and USART0/1 clock and peripheral to the accelerometer.
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
void led(bool enabled)
Enable or disable the LED.
static bool checkID_ADXL(void)
Check if the ID is correct.
static void softResetADXL(void)
Soft reset accelerometer.