Device driver interface for the LIS3DH accelerometer. More...

Detailed Description

#include <stdint.h>
#include "periph/spi.h"
#include "periph/gpio.h"
+ Include dependency graph for lis3dh.h:

Go to the source code of this file.

Data Structures

struct  lis3dh_params_t
 Configuration parameters for LIS3DH devices. More...
 
struct  lis3dh_t
 Device descriptor for LIS3DH sensors. More...
 
struct  lis3dh_data_t
 Result vector for accelerometer measurement. More...
 

Macros

#define LIS3DH_WHO_AM_I_RESPONSE   (0b00110011)
 The WHO_AM_I register should contain this value in order to correctly identify the chip.
 
#define LIS3DH_CTRL_REG1_LPEN_MASK   (1 << 3)
 Low power mode enable. More...
 
#define LIS3DH_CTRL_REG1_ZEN_SHIFT   (2)
 Z enable bit offset.
 
#define LIS3DH_CTRL_REG1_ZEN_MASK   (1 << LIS3DH_CTRL_REG1_ZEN_SHIFT)
 Z axis enable. More...
 
#define LIS3DH_CTRL_REG1_YEN_SHIFT   (1)
 Y enable bit offset.
 
#define LIS3DH_CTRL_REG1_YEN_MASK   (1 << LIS3DH_CTRL_REG1_YEN_SHIFT)
 Y axis enable. More...
 
#define LIS3DH_CTRL_REG1_XEN_SHIFT   (0)
 X enable bit offset.
 
#define LIS3DH_CTRL_REG1_XEN_MASK   (1 << LIS3DH_CTRL_REG1_XEN_SHIFT)
 X axis enable. More...
 
#define LIS3DH_CTRL_REG1_XYZEN_SHIFT   (0)
 XYZ enable bitfield offset.
 
#define LIS3DH_CTRL_REG1_XYZEN_MASK
 X, Y, Z enable bitfield mask. More...
 
#define LIS3DH_CTRL_REG2_FDS_MASK   (1 << 3)
 Filtered data selection. More...
 
#define LIS3DH_CTRL_REG2_HPCLICK_MASK   (1 << 2)
 High pass filter enabled for CLICK function. More...
 
#define LIS3DH_CTRL_REG4_HR_MASK   (1 << 3)
 High resolution output mode. More...
 
#define LIS3DH_CTRL_REG4_SIM_MASK   (1 << 0)
 SPI serial interface mode selection. More...
 
#define LIS3DH_CTRL_REG5_REBOOT_MASK   (1 << 7)
 Reboot memory content. More...
 
#define LIS3DH_CTRL_REG5_FIFO_EN_MASK   (1 << 6)
 FIFO enable. More...
 
#define LIS3DH_CTRL_REG5_LIR_I1_MASK   (1 << 3)
 Latch interrupt request on INT1. More...
 
#define LIS3DH_CTRL_REG5_D4D_I1_MASK   (1 << 2)
 4D enable More...
 
#define LIS3DH_ADC_DATA_SIZE   (2)
 Length of scalar measurement data in bytes.
 
TEMP_CFG_REG bitfield macros
#define LIS3DH_TEMP_CFG_REG_ADC_PD_MASK   (1 << 7)
 ADC enable. More...
 
#define LIS3DH_TEMP_CFG_REG_TEMP_EN_MASK   (1 << 6)
 Temperature sensor (T) enable. More...
 
Output data rate selection bitfield macros

Default value: 0000

0000: Power down; Others: Refer to data sheet

See also
LIS3DH data sheet Table 25, “Data rate configuration”
#define LIS3DH_CTRL_REG1_ODR_SHIFT   (4)
 
#define LIS3DH_CTRL_REG1_ODR3_MASK   (1 << (LIS3DH_CTRL_REG1_ODR_SHIFT + 3))
 
#define LIS3DH_CTRL_REG1_ODR2_MASK   (1 << (LIS3DH_CTRL_REG1_ODR_SHIFT + 2))
 
#define LIS3DH_CTRL_REG1_ODR1_MASK   (1 << (LIS3DH_CTRL_REG1_ODR_SHIFT + 1))
 
#define LIS3DH_CTRL_REG1_ODR0_MASK   (1 << LIS3DH_CTRL_REG1_ODR_SHIFT)
 
#define LIS3DH_CTRL_REG1_ODR_MASK
 
Axis selection macros

Use these when calling lis3dh_set_axes()

#define LIS3DH_AXES_X   (LIS3DH_CTRL_REG1_XEN_MASK)
 enable X axis
 
#define LIS3DH_AXES_Y   (LIS3DH_CTRL_REG1_YEN_MASK)
 enable Y axis
 
#define LIS3DH_AXES_Z   (LIS3DH_CTRL_REG1_ZEN_MASK)
 enable Z axis
 
#define LIS3DH_AXES_XYZ   (LIS3DH_CTRL_REG1_XYZEN_MASK)
 Convenience macro for enabling all axes.
 
High pass filter mode selection

Default value: 00

See also
Refer to Table 29, "High pass filter mode configuration"
#define LIS3DH_CTRL_REG2_HPM1_MASK   (1 << 7)
 
#define LIS3DH_CTRL_REG2_HPM0_MASK   (1 << 6)
 
High pass filter cut off frequency selection
#define LIS3DH_CTRL_REG2_HPCF2_MASK   (1 << 5)
 
#define LIS3DH_CTRL_REG2_HPCF1_MASK   (1 << 4)
 
High pass filter enabled for AOI function on interrupt 2

0.

filter bypassed

  1. filter enabled
#define LIS3DH_CTRL_REG2_HPIS2_MASK   (1 << 1)
 
#define LIS3DH_CTRL_REG2_HPIS1_MASK   (1 << 0)
 
CTRL_REG3 bitfield macros
#define LIS3DH_CTRL_REG3_I1_CLICK_MASK   (1 << 7)
 CLICK interrupt on INT1. More...
 
#define LIS3DH_CTRL_REG3_I1_AOI1_MASK   (1 << 6)
 AOI1 interrupt on INT1. More...
 
#define LIS3DH_CTRL_REG3_I1_AOI2_MASK   (1 << 5)
 AOI2 interrupt on INT1. More...
 
#define LIS3DH_CTRL_REG3_I1_DRDY1_MASK   (1 << 4)
 DRDY1 interrupt on INT1. More...
 
#define LIS3DH_CTRL_REG3_I1_DRDY2_MASK   (1 << 3)
 DRDY2 interrupt on INT1. More...
 
#define LIS3DH_CTRL_REG3_I1_WTM_MASK   (1 << 2)
 FIFO Watermark interrupt on INT1. More...
 
#define LIS3DH_CTRL_REG3_I1_OVERRUN_MASK   (1 << 1)
 FIFO Overrun interrupt on INT1. More...
 
Block data update.

Default value: 0

0. continuous update

  1. output registers not updated until MSB and LSB reading
#define LIS3DH_CTRL_REG4_BDU_MASK   (1 << 7)
 BDU bit mask.
 
#define LIS3DH_CTRL_REG4_BDU_ENABLE   (LIS3DH_CTRL_REG4_BDU_MASK)
 BDU enable.
 
#define LIS3DH_CTRL_REG4_BDU_DISABLE   (0)
 BDU disable.
 
Big/little endian data selection

Default value 0.

0. Data LSB @ lower address

  1. Data MSB @ lower address
#define LIS3DH_CTRL_REG4_BLE_MASK   (1 << 6)
 BLE bit mask.
 
#define LIS3DH_CTRL_REG4_BLE_LITTLE_ENDIAN   (0)
 BLE little endian mode.
 
#define LIS3DH_CTRL_REG4_BLE_BIG_ENDIAN   (LIS3DH_CTRL_REG4_BLE_MASK)
 BLE big endian mode.
 
Full scale selection.

Default value: 00

  • 00: +/- 2G
  • 01: +/- 4G
  • 10: +/- 8G
  • 11: +/- 16G
#define LIS3DH_CTRL_REG4_FS1_MASK   (1 << 5)
 
#define LIS3DH_CTRL_REG4_FS0_MASK   (1 << 4)
 
#define LIS3DH_CTRL_REG4_FS_MASK   (LIS3DH_CTRL_REG4_FS1_MASK | LIS3DH_CTRL_REG4_FS0_MASK)
 
Scale register values symbolic names
#define LIS3DH_CTRL_REG4_SCALE_2G   (0)
 Scale: +/- 2G.
 
#define LIS3DH_CTRL_REG4_SCALE_4G   (LIS3DH_CTRL_REG4_FS0_MASK)
 Scale: +/- 4G.
 
#define LIS3DH_CTRL_REG4_SCALE_8G   (LIS3DH_CTRL_REG4_FS1_MASK)
 Scale: +/- 8G.
 
#define LIS3DH_CTRL_REG4_SCALE_16G   (LIS3DH_CTRL_REG4_FS1_MASK | LIS3DH_CTRL_REG4_FS0_MASK)
 Scale: +/- 16G.
 
Self test enable

Default value: 00

  • 00: Self test disabled
  • Other: See Table 34
See also
Table 34
#define LIS3DH_CTRL_REG4_ST1_MASK   (1 << 2)
 
#define LIS3DH_CTRL_REG4_ST0_MASK   (1 << 1)
 
STATUS_REG bitfield macros
#define LIS3DH_STATUS_REG_ZYXOR_MASK   (1 << 7)
 X, Y or Z axis data overrun. More...
 
#define LIS3DH_STATUS_REG_ZOR_MASK   (1 << 6)
 Z axis data overrun. More...
 
#define LIS3DH_STATUS_REG_YOR_MASK   (1 << 5)
 Y axis data overrun. More...
 
#define LIS3DH_STATUS_REG_XOR_MASK   (1 << 4)
 X axis data overrun. More...
 
#define LIS3DH_STATUS_REG_ZYXDA_MASK   (1 << 3)
 X, Y or Z axis new data available. More...
 
#define LIS3DH_STATUS_REG_ZDA_MASK   (1 << 2)
 Z axis new data available. More...
 
#define LIS3DH_STATUS_REG_YDA_MASK   (1 << 1)
 Y axis new data available. More...
 
#define LIS3DH_STATUS_REG_XDA_MASK   (1 << 0)
 X axis new data available. More...
 
FIFO_CTRL_REG bitfield macros
#define LIS3DH_FIFO_CTRL_REG_FM_SHIFT   (6)
 
#define LIS3DH_FIFO_CTRL_REG_FM1_MASK   (1 << 7)
 
#define LIS3DH_FIFO_CTRL_REG_FM0_MASK   (1 << 6)
 
#define LIS3DH_FIFO_CTRL_REG_FM_MASK
 
#define LIS3DH_FIFO_CTRL_REG_TR_MASK   (1 << 5)
 
#define LIS3DH_FIFO_CTRL_REG_FTH4_MASK   (1 << 4)
 
#define LIS3DH_FIFO_CTRL_REG_FTH3_MASK   (1 << 3)
 
#define LIS3DH_FIFO_CTRL_REG_FTH2_MASK   (1 << 2)
 
#define LIS3DH_FIFO_CTRL_REG_FTH1_MASK   (1 << 1)
 
#define LIS3DH_FIFO_CTRL_REG_FTH0_MASK   (1 << 0)
 
#define LIS3DH_FIFO_CTRL_REG_FTH_SHIFT   (0)
 
#define LIS3DH_FIFO_CTRL_REG_FTH_MASK
 
FIFO_SRC_REG bitfield macros
#define LIS3DH_FIFO_SRC_REG_WTM_MASK   (1 << 7)
 
#define LIS3DH_FIFO_SRC_REG_OVRN_FIFO_MASK   (1 << 6)
 
#define LIS3DH_FIFO_SRC_REG_EMPTY_MASK   (1 << 5)
 
#define LIS3DH_FIFO_SRC_REG_FSS4_MASK   (1 << 4)
 
#define LIS3DH_FIFO_SRC_REG_FSS3_MASK   (1 << 3)
 
#define LIS3DH_FIFO_SRC_REG_FSS2_MASK   (1 << 2)
 
#define LIS3DH_FIFO_SRC_REG_FSS1_MASK   (1 << 1)
 
#define LIS3DH_FIFO_SRC_REG_FSS0_MASK   (1 << 0)
 
#define LIS3DH_FIFO_SRC_REG_FSS_SHIFT   (0)
 
#define LIS3DH_FIFO_SRC_REG_FSS_MASK
 
Register address bitfield macros
#define LIS3DH_SPI_WRITE_MASK   (0 << 7)
 Write to register.
 
#define LIS3DH_SPI_READ_MASK   (1 << 7)
 The READ bit must be set when reading.
 
#define LIS3DH_SPI_MULTI_MASK   (1 << 6)
 Multi byte transfers must assert this bit when writing the address.
 
#define LIS3DH_SPI_SINGLE_MASK   (0 << 6)
 Opposite of LIS3DH_SPI_MULTI_MASK.
 
#define LIS3DH_SPI_ADDRESS_MASK   (0x3F)
 Mask of the address bits in the address byte during transfers.
 
Output Data Rates (ODR)

Use these when calling lis3dh_set_odr(odr).

#define LIS3DH_ODR_POWERDOWN   (0x00 << LIS3DH_CTRL_REG1_ODR_SHIFT)
 
#define LIS3DH_ODR_1Hz   (0x01 << LIS3DH_CTRL_REG1_ODR_SHIFT)
 
#define LIS3DH_ODR_10Hz   (0x02 << LIS3DH_CTRL_REG1_ODR_SHIFT)
 
#define LIS3DH_ODR_25Hz   (0x03 << LIS3DH_CTRL_REG1_ODR_SHIFT)
 
#define LIS3DH_ODR_50Hz   (0x04 << LIS3DH_CTRL_REG1_ODR_SHIFT)
 
#define LIS3DH_ODR_100Hz   (0x05 << LIS3DH_CTRL_REG1_ODR_SHIFT)
 
#define LIS3DH_ODR_200Hz   (0x06 << LIS3DH_CTRL_REG1_ODR_SHIFT)
 
#define LIS3DH_ODR_400Hz   (0x07 << LIS3DH_CTRL_REG1_ODR_SHIFT)
 
#define LIS3DH_ODR_LP1600Hz   (0x08 << LIS3DH_CTRL_REG1_ODR_SHIFT)
 
#define LIS3DH_ODR_NP1250Hz   (0x09 << LIS3DH_CTRL_REG1_ODR_SHIFT)
 
#define LIS3DH_ODR_LP5000HZ   (0x09 << LIS3DH_CTRL_REG1_ODR_SHIFT)
 
FIFO modes.

Used when calling lis3dh_set_fifo()

#define LIS3DH_FIFO_MODE_BYPASS   (0x00 << LIS3DH_FIFO_CTRL_REG_FM_SHIFT)
 FIFO mode: Bypass.
 
#define LIS3DH_FIFO_MODE_FIFO   (0x01 << LIS3DH_FIFO_CTRL_REG_FM_SHIFT)
 FIFO mode: FIFO.
 
#define LIS3DH_FIFO_MODE_STREAM   (0x02 << LIS3DH_FIFO_CTRL_REG_FM_SHIFT)
 FIFO mode: Stream.
 
#define LIS3DH_FIFO_MODE_STREAM_TO_FIFO   (0x03 << LIS3DH_FIFO_CTRL_REG_FM_SHIFT)
 FIFO mode: Stream to FIFO.
 

Enumerations

enum  lis3dh_reg_t {
  LIS3DH_REG_STATUS_AUX = 0x07, LIS3DH_REG_OUT_AUX_ADC1_L = 0x08, LIS3DH_REG_OUT_AUX_ADC1_H = 0x09, LIS3DH_REG_OUT_AUX_ADC2_L = 0x0A,
  LIS3DH_REG_OUT_AUX_ADC2_H = 0x0B, LIS3DH_REG_OUT_AUX_ADC3_L = 0x0C, LIS3DH_REG_OUT_AUX_ADC3_H = 0x0D, LIS3DH_REG_INT_COUNTER_REG = 0x0E,
  LIS3DH_REG_WHO_AM_I = 0x0F, LIS3DH_REG_TEMP_CFG_REG = 0x1F, LIS3DH_REG_CTRL_REG1 = 0x20, LIS3DH_REG_CTRL_REG2 = 0x21,
  LIS3DH_REG_CTRL_REG3 = 0x22, LIS3DH_REG_CTRL_REG4 = 0x23, LIS3DH_REG_CTRL_REG5 = 0x24, LIS3DH_REG_CTRL_REG6 = 0x25,
  LIS3DH_REG_REFERENCE = 0x26, LIS3DH_REG_STATUS_REG = 0x27, LIS3DH_REG_OUT_X_L = 0x28, LIS3DH_REG_OUT_X_H = 0x29,
  LIS3DH_REG_OUT_Y_L = 0x2A, LIS3DH_REG_OUT_Y_H = 0x2B, LIS3DH_REG_OUT_Z_L = 0x2C, LIS3DH_REG_OUT_Z_H = 0x2D,
  LIS3DH_REG_FIFO_CTRL_REG = 0x2E, LIS3DH_REG_FIFO_SRC_REG = 0x2F, LIS3DH_REG_INT1_CFG = 0x30, LIS3DH_REG_INT1_SOURCE = 0x31,
  LIS3DH_REG_INT1_THS = 0x32, LIS3DH_REG_INT1_DURATION = 0x33, LIS3DH_REG_CLICK_CFG = 0x38, LIS3DH_REG_CLICK_SRC = 0x39,
  LIS3DH_REG_CLICK_THS = 0x3A, LIS3DH_REG_TIME_LIMIT = 0x3B, LIS3DH_REG_TIME_LATENCY = 0x3C, LIS3DH_REG_TIME_WINDOW = 0x3D
}
 LIS3DH hardware register addresses.
 

Functions

int lis3dh_init (lis3dh_t *dev, const lis3dh_params_t *params)
 Initialize a LIS3DH sensor instance. More...
 
int lis3dh_read_xyz (const lis3dh_t *dev, lis3dh_data_t *acc_data)
 Read 3D acceleration data from the accelerometer. More...
 
int lis3dh_read_aux_adc1 (const lis3dh_t *dev, int16_t *out)
 Read auxiliary ADC channel 1 data from the accelerometer. More...
 
int lis3dh_read_aux_adc2 (const lis3dh_t *dev, int16_t *out)
 Read auxiliary ADC channel 2 data from the accelerometer. More...
 
int lis3dh_read_aux_adc3 (const lis3dh_t *dev, int16_t *out)
 Read auxiliary ADC channel 3 data from the accelerometer. More...
 
int lis3dh_set_aux_adc (const lis3dh_t *dev, const uint8_t enable, const uint8_t temperature)
 Turn on/off power to the auxiliary ADC in LIS3DH. More...
 
int lis3dh_set_axes (const lis3dh_t *dev, const uint8_t axes)
 Enable/disable accelerometer axes. More...
 
int lis3dh_set_fifo (const lis3dh_t *dev, const uint8_t mode, const uint8_t watermark)
 Enable/disable the FIFO. More...
 
int lis3dh_set_odr (const lis3dh_t *dev, const uint8_t odr)
 Set the output data rate of the sensor. More...
 
int lis3dh_set_scale (lis3dh_t *dev, const uint8_t scale)
 Set the full scale range of the sensor. More...
 
int lis3dh_set_int1 (const lis3dh_t *dev, const uint8_t mode)
 Set INT1 pin function. More...
 
int lis3dh_get_fifo_level (const lis3dh_t *dev)
 Get the current number of elements in the FIFO. More...
 

Macro Definition Documentation

◆ LIS3DH_CTRL_REG2_FDS_MASK

#define LIS3DH_CTRL_REG2_FDS_MASK   (1 << 3)

Default value: 0

0. internal filter bypassed

  1. data from internal filter sent to output register and FIFO

Definition at line 240 of file lis3dh.h.

◆ LIS3DH_CTRL_REG2_HPCLICK_MASK

#define LIS3DH_CTRL_REG2_HPCLICK_MASK   (1 << 2)

0. filter bypassed

  1. filter enabled

Definition at line 248 of file lis3dh.h.

◆ LIS3DH_CTRL_REG3_I1_AOI1_MASK

#define LIS3DH_CTRL_REG3_I1_AOI1_MASK   (1 << 6)

Default value 0.

0. Disable

  1. Enable

Definition at line 284 of file lis3dh.h.

◆ LIS3DH_CTRL_REG3_I1_AOI2_MASK

#define LIS3DH_CTRL_REG3_I1_AOI2_MASK   (1 << 5)

Default value 0.

0. Disable

  1. Enable

Definition at line 293 of file lis3dh.h.

◆ LIS3DH_CTRL_REG3_I1_CLICK_MASK

#define LIS3DH_CTRL_REG3_I1_CLICK_MASK   (1 << 7)

Default value 0.

0. Disable

  1. Enable

Definition at line 274 of file lis3dh.h.

◆ LIS3DH_CTRL_REG3_I1_DRDY1_MASK

#define LIS3DH_CTRL_REG3_I1_DRDY1_MASK   (1 << 4)

Default value 0.

0. Disable

  1. Enable

Definition at line 302 of file lis3dh.h.

◆ LIS3DH_CTRL_REG3_I1_DRDY2_MASK

#define LIS3DH_CTRL_REG3_I1_DRDY2_MASK   (1 << 3)

Default value 0.

0. Disable

  1. Enable

Definition at line 311 of file lis3dh.h.

◆ LIS3DH_CTRL_REG3_I1_OVERRUN_MASK

#define LIS3DH_CTRL_REG3_I1_OVERRUN_MASK   (1 << 1)

Default value 0.

0. Disable

  1. Enable

Definition at line 329 of file lis3dh.h.

◆ LIS3DH_CTRL_REG3_I1_WTM_MASK

#define LIS3DH_CTRL_REG3_I1_WTM_MASK   (1 << 2)

Default value 0.

0. Disable

  1. Enable

Definition at line 320 of file lis3dh.h.

◆ LIS3DH_CTRL_REG4_HR_MASK

#define LIS3DH_CTRL_REG4_HR_MASK   (1 << 3)

Default value: 0

0. High resolution disable

  1. High resolution enable

Definition at line 408 of file lis3dh.h.

◆ LIS3DH_CTRL_REG4_SIM_MASK

#define LIS3DH_CTRL_REG4_SIM_MASK   (1 << 0)

Default value: 0

0. 4-wire interface

  1. 3-wire interface

Definition at line 433 of file lis3dh.h.

◆ LIS3DH_CTRL_REG5_D4D_I1_MASK

#define LIS3DH_CTRL_REG5_D4D_I1_MASK   (1 << 2)

4D detection is enabled on INT1 when 6D bit on INT1_CFG is set to 1.

Definition at line 473 of file lis3dh.h.

◆ LIS3DH_CTRL_REG5_FIFO_EN_MASK

#define LIS3DH_CTRL_REG5_FIFO_EN_MASK   (1 << 6)

Default value: 0

0. FIFO disable

  1. FIFO enable

Definition at line 453 of file lis3dh.h.

◆ LIS3DH_CTRL_REG5_LIR_I1_MASK

#define LIS3DH_CTRL_REG5_LIR_I1_MASK   (1 << 3)

Latch interrupt request on INT1_SRC register, with INT1_SRC register cleared by reading INT1_SRC itself.

Default value: 0

0. interrupt request not latched

  1. interrupt request latched

Definition at line 466 of file lis3dh.h.

◆ LIS3DH_CTRL_REG5_REBOOT_MASK

#define LIS3DH_CTRL_REG5_REBOOT_MASK   (1 << 7)

Default value: 0

0. normal mode

  1. reboot memory content

Definition at line 443 of file lis3dh.h.

◆ LIS3DH_FIFO_CTRL_REG_FM_MASK

#define LIS3DH_FIFO_CTRL_REG_FM_MASK
Value:
(LIS3DH_FIFO_CTRL_REG_FM1_MASK | \
LIS3DH_FIFO_CTRL_REG_FM0_MASK)

Definition at line 570 of file lis3dh.h.

◆ LIS3DH_FIFO_CTRL_REG_FTH_MASK

#define LIS3DH_FIFO_CTRL_REG_FTH_MASK
Value:
(LIS3DH_FIFO_CTRL_REG_FTH0_MASK | \
LIS3DH_FIFO_CTRL_REG_FTH1_MASK | \
LIS3DH_FIFO_CTRL_REG_FTH2_MASK | \
LIS3DH_FIFO_CTRL_REG_FTH3_MASK | \
LIS3DH_FIFO_CTRL_REG_FTH4_MASK)

Definition at line 580 of file lis3dh.h.

◆ LIS3DH_FIFO_SRC_REG_FSS_MASK

#define LIS3DH_FIFO_SRC_REG_FSS_MASK
Value:
(LIS3DH_FIFO_SRC_REG_FSS0_MASK | \
LIS3DH_FIFO_SRC_REG_FSS1_MASK | \
LIS3DH_FIFO_SRC_REG_FSS2_MASK | \
LIS3DH_FIFO_SRC_REG_FSS3_MASK | \
LIS3DH_FIFO_SRC_REG_FSS4_MASK)

Definition at line 601 of file lis3dh.h.

◆ LIS3DH_STATUS_REG_XDA_MASK

#define LIS3DH_STATUS_REG_XDA_MASK   (1 << 0)

Default value: 0

0. a new data for the X-axis is not yet available

  1. a new data for the X-axis is available

Definition at line 559 of file lis3dh.h.

◆ LIS3DH_STATUS_REG_XOR_MASK

#define LIS3DH_STATUS_REG_XOR_MASK   (1 << 4)

Default value: 0

0. no overrun has occurred

  1. a new data for the X-axis has overwritten the previous one

Definition at line 519 of file lis3dh.h.

◆ LIS3DH_STATUS_REG_YDA_MASK

#define LIS3DH_STATUS_REG_YDA_MASK   (1 << 1)

Default value: 0

0. a new data for the Y-axis is not yet available

  1. a new data for the Y-axis is available

Definition at line 549 of file lis3dh.h.

◆ LIS3DH_STATUS_REG_YOR_MASK

#define LIS3DH_STATUS_REG_YOR_MASK   (1 << 5)

Default value: 0

0. no overrun has occurred

  1. a new data for the Y-axis has overwritten the previous one

Definition at line 509 of file lis3dh.h.

◆ LIS3DH_STATUS_REG_ZDA_MASK

#define LIS3DH_STATUS_REG_ZDA_MASK   (1 << 2)

Default value: 0

0. a new data for the Z-axis is not yet available

  1. a new data for the Z-axis is available

Definition at line 539 of file lis3dh.h.

◆ LIS3DH_STATUS_REG_ZOR_MASK

#define LIS3DH_STATUS_REG_ZOR_MASK   (1 << 6)

Default value: 0

0. no overrun has occurred

  1. a new data for the Z-axis has overwritten the previous one

Definition at line 499 of file lis3dh.h.

◆ LIS3DH_STATUS_REG_ZYXDA_MASK

#define LIS3DH_STATUS_REG_ZYXDA_MASK   (1 << 3)

Default value: 0

0. a new set of data is not yet available

  1. a new set of data is available

Definition at line 529 of file lis3dh.h.

◆ LIS3DH_STATUS_REG_ZYXOR_MASK

#define LIS3DH_STATUS_REG_ZYXOR_MASK   (1 << 7)

Default value: 0

0. no overrun has occurred

  1. a new set of data has overwritten the previous ones

Definition at line 489 of file lis3dh.h.

Function Documentation

◆ lis3dh_get_fifo_level()

int lis3dh_get_fifo_level ( const lis3dh_t dev)
Parameters
[in]devDevice descriptor of sensor
Returns
number of elements in device FIFO on success
-1 on error

◆ lis3dh_init()

int lis3dh_init ( lis3dh_t dev,
const lis3dh_params_t params 
)
Parameters
[in]devDevice descriptor of sensor to initialize
[in]paramsConfiguration parameters
Returns
0 on success
-1 on error

◆ lis3dh_read_aux_adc1()

int lis3dh_read_aux_adc1 ( const lis3dh_t dev,
int16_t *  out 
)
Parameters
[in]devDevice descriptor of sensor
[out]outThe value of ADC1 (OUT_1_{L,H}) will be written to this buffer
Returns
0 on success
-1 on error

◆ lis3dh_read_aux_adc2()

int lis3dh_read_aux_adc2 ( const lis3dh_t dev,
int16_t *  out 
)
Parameters
[in]devDevice descriptor of sensor
[out]outThe value of ADC2 (OUT_2_{L,H}) will be written to this buffer
Returns
0 on success
-1 on error

◆ lis3dh_read_aux_adc3()

int lis3dh_read_aux_adc3 ( const lis3dh_t dev,
int16_t *  out 
)
Parameters
[in]devDevice descriptor of sensor
[out]outThe value of ADC3 (OUT_3_{L,H}) will be written to this buffer
Note
The internal temperature sensor is connected to the third channel on the auxiliary ADC when the TEMP_EN bit of TEMP_CFG_REG is set.
Returns
0 on success
-1 on error

◆ lis3dh_read_xyz()

int lis3dh_read_xyz ( const lis3dh_t dev,
lis3dh_data_t acc_data 
)
Parameters
[in]devDevice descriptor of sensor
[out]acc_dataAccelerometer data output buffer
Returns
0 on success
-1 on error

◆ lis3dh_set_aux_adc()

int lis3dh_set_aux_adc ( const lis3dh_t dev,
const uint8_t  enable,
const uint8_t  temperature 
)
Parameters
[in]devDevice descriptor of sensor
[in]enablePower state of the auxiliary ADC
[in]temperatureIf not zero, switch the ADC mux so that a temperature reading is available on OUT_3_L, OUT_3_H.
Note
This ADC is only used for the temperature reading and the external ADC pins. The accelerometer ADC is turned on by lis3dh_set_odr().
Returns
0 on success
-1 on error

◆ lis3dh_set_axes()

int lis3dh_set_axes ( const lis3dh_t dev,
const uint8_t  axes 
)
Parameters
[in]devDevice descriptor of sensor
[in]axesAn OR-ed combination of LIS3DH_AXES_X, LIS3DH_AXES_Y, LIS3DH_AXES_Z.
Note
The macro LIS3DH_AXES_XYZ is a convenience shortcut to enable all axes.
Returns
0 on success
-1 on error

◆ lis3dh_set_fifo()

int lis3dh_set_fifo ( const lis3dh_t dev,
const uint8_t  mode,
const uint8_t  watermark 
)
Parameters
[in]devDevice descriptor of sensor
[in]modeFIFO mode, see data sheet for details.
[in]watermarkWatermark level for FIFO level interrupts
Returns
0 on success
-1 on error

◆ lis3dh_set_int1()

int lis3dh_set_int1 ( const lis3dh_t dev,
const uint8_t  mode 
)

Set the bits of CTRL_REG3 for choosing sources for the INT1 pin.

Parameters
[in]devDevice descriptor of sensor
[in]modeCTRL_REG3 value, see data sheet for details.
Returns
0 on success
-1 on error

◆ lis3dh_set_odr()

int lis3dh_set_odr ( const lis3dh_t dev,
const uint8_t  odr 
)
Parameters
[in]devDevice descriptor of sensor
[in]odrChosen output data rate.
Returns
0 on success
-1 on error

◆ lis3dh_set_scale()

int lis3dh_set_scale ( lis3dh_t dev,
const uint8_t  scale 
)

Valid values for scale are 2, 4, 8, 16 and represents the full range of the sensor.

Parameters
[in]devDevice descriptor of sensor
[in]scaleThe chosen sensitivity scale.
Returns
0 on success
-1 on error