LIS3DH Propeller C library  v1.0.0
Propeller C Library for the Parallax LIS3DH 3 Axis Accelerometer with ADC module
Data Structures | Macros | Typedefs | Functions
lis3dh.h File Reference

Simplifies reading Parallax LIS3DH 3-Axis Accelerometer Module with ADC. More...

#include "simpletools.h"

Go to the source code of this file.

Data Structures

struct  lis3dh_st
 

Macros

#define LIS3DH_STATUS_REG_AUX   0x07
 
#define LIS3DH_OUT_ADC1_L   0x08
 
#define LIS3DH_OUT_ADC1_H   0x09
 
#define LIS3DH_OUT_ADC2_L   0x0A
 
#define LIS3DH_OUT_ADC2_H   0x0B
 
#define LIS3DH_OUT_ADC3_L   0x0C
 
#define LIS3DH_OUT_ADC3_H   0x0D
 
#define LIS3DH_WHO_AM_I   0x0F
 
#define LIS3DH_WHO_AM_I_REPLY   0x33
 
#define LIS3DH_CTRL_REG0   0x1E
 
#define LIS3DH_TEMP_CFG_REG   0x1F
 
#define LIS3DH_CTRL_REG1   0x20
 
#define LIS3DH_CTRL_REG2   0x21
 
#define LIS3DH_CTRL_REG3   0x22
 
#define LIS3DH_CTRL_REG4   0x23
 
#define LIS3DH_CTRL_REG5   0x24
 
#define LIS3DH_CTRL_REG6   0x25
 
#define LIS3DH_REFERENCE   0x26
 
#define LIS3DH_STATUS_REG   0x27
 
#define LIS3DH_OUT_X_L   0x28
 
#define LIS3DH_OUT_X_H   0x29
 
#define LIS3DH_OUT_Y_L   0x2A
 
#define LIS3DH_OUT_Y_H   0x2B
 
#define LIS3DH_OUT_Z_L   0x2C
 
#define LIS3DH_OUT_Z_H   0x2D
 
#define LIS3DH_FIFO_CTRL_REG   0x2E
 
#define LIS3DH_FIFO_SRC_REG   0x2F
 
#define LIS3DH_INT1_CFG   0x30
 
#define LIS3DH_INT1_SRC   0x31
 
#define LIS3DH_INT1_THS   0x32
 
#define LIS3DH_INT1_DURATION   0x33
 
#define LIS3DH_INT2_CFG   0x34
 
#define LIS3DH_INT2_SRC   0x35
 
#define LIS3DH_INT2_THS   0x36
 
#define LIS3DH_INT2_DURATION   0x37
 
#define LIS3DH_CLICK_CFG   0x38
 
#define LIS3DH_CLICK_SRC   0x39
 
#define LIS3DH_CLICK_THS   0x3A
 
#define LIS3DH_TIME_LIMIT   0x3B
 
#define LIS3DH_TIME_LATENCY   0x3C
 
#define LIS3DH_TIME_WINDOW   0x3D
 
#define LIS3DH_ACT_THS   0x3E
 
#define LIS3DH_ACT_DUR   0x3F
 
#define LIS3DH_MASK_READSINGLE   0x80
 
#define LIS3DH_MASK_READREPEAT   0xC0
 
#define LIS3DH_MASK_BDUMODE   0x80
 
#define LIS3DH_MASK_SPIMODE   0x01
 
#define LIS3DH_RANGE_16   0x03
 
#define LIS3DH_RANGE_8   0x02
 
#define LIS3DH_RANGE_4   0x01
 
#define LIS3DH_RANGE_2   0x00
 
#define LIS3DH_AXIS_X   0b01
 
#define LIS3DH_AXIS_Y   0b10
 
#define LIS3DH_AXIS_Z   0b11
 
#define LIS3DH_ADC_1   0b01
 
#define LIS3DH_ADC_2   0b10
 
#define LIS3DH_ADC_3   0b11
 
#define LIS3DH_SPIMODE_3   0b01
 
#define LIS3DH_SPIMODE_4   0b00
 
#define LIS3DH_BDUMODE_CONTINUOUS   0b01
 
#define LIS3DH_BDUMODE_CONSISTENT   0b00
 

Typedefs

typedef struct lis3dh_st lis3dh_t
 
typedef lis3dh_t lis3dh
 

Functions

lis3dh_tlis3dh_init (int pinSCK, int pinSDI, int pinCS)
 Initialize the sensor with typical configuration for reading axis and adc. Uses 3-Wire SPI mode. More...
 
lis3dh_tlis3dh_init4wire (int pinSCK, int pinSDI, int pinSDO, int pinCS)
 Initialize the sensor with typical configuration for reading axis and adc. Uses 4-Wire SPI mode. More...
 
void lis3dh_shutdown (lis3dh_t *device)
 Shutdown the sensor, set configuration defaults with sensor disabled and clear buffers. More...
 
int lis3dh_getWhoAmI (lis3dh_t *device)
 Reads the sensor identification register (WhoAmI). More...
 
void lis3dh_setResolution (lis3dh_t *device, int bits)
 Sets the bit resolution for the sensor readings. 8-bit, 10-bit or 12-bit. More...
 
int lis3dh_getResolution (lis3dh_t *device)
 Reads the bit resolution setting from the sensor. 8-bit, 10-bit or 12-bit. More...
 
void lis3dh_setRange (lis3dh_t *device, int range)
 Sets the g measurement range to +/- 2, +/-4, +/- 8, +- 16 g. More...
 
int lis3dh_getRange (lis3dh_t *device)
 Reads the g measurement range; one of +/- 2, +/-4, +/- 8, +- 16 g. More...
 
void lis3dh_setSPImode (lis3dh_t *device, int mode)
 Sets the SPI mode to either 3-wire or 4-wire. More...
 
int lis3dh_getSPImode (lis3dh_t *device)
 Read the SPI mode currently configured in the LIS3DH module; either 3-wire or 4-wire. More...
 
void lis3dh_setBDUmode (lis3dh_t *device, int mode)
 Sets the sensor BDU (Block Data Update) mode. More...
 
void lis3dh_setADCmode (lis3dh_t *device, int adcEnable, int tempEnable)
 Sets ADC mode for the Parallax LIS3DH 3-Axis Accelerometer Module. More...
 
void lis3dh_adc (lis3dh_t *device, int *ad1, int *ad2, int *ad3)
 Gets raw adc measurements from all three ADC channels. More...
 
int lis3dh_getADC (lis3dh_t *device, int channel)
 Gets raw adc measurement from a single ADC channel. More...
 
void lis3dh_adc_mV (lis3dh_t *device, int *ad1, int *ad2, int *ad3)
 Gets mV adc measurements from all three ADC channels. More...
 
int lis3dh_getADC_mV (lis3dh_t *device, int channel)
 Gets mV adc measurement from a single ADC channel. More...
 
void lis3dh_adcCal_mV (lis3dh_t *device, int mV_L, int mV_H, int value_L, int value_H)
 Sets the adc calibration values for adc mV reading on AD1. More...
 
void lis3dh_tempCal_C (lis3dh_t *device, int actualTempC)
 Sets the actual temperature to provide a reference for the relative temperature sensor. More...
 
void lis3dh_tempCal_F (lis3dh_t *device, int actualTempF)
 Sets the actual temperature to provide a reference for the relative temperature sensor. More...
 
int lis3dh_tempRaw (lis3dh_t *device)
 Reads the raw relative temperature value from the sensor. More...
 
int lis3dh_temp_C (lis3dh_t *device)
 Reads the calibrated (referenced) temperature value from the sensor. More...
 
int lis3dh_temp_F (lis3dh_t *device)
 Reads the calibrated (referenced) temperature value from the sensor. More...
 
int lis3dh_accel (lis3dh_t *device, int *x, int *y, int *z)
 Gets raw accelerometer measurements from all three axis (x, y, z). More...
 
int lis3dh_getAccel (lis3dh_t *device, int axis)
 Gets raw accelerometer measurements for a single axis (x, y, or z). More...
 
int lis3dh_accel_mg (lis3dh_t *device, int *xmg, int *ymg, int *zmg)
 Gets mg (milli-g's) accelerometer measurements from all three axis (x, y, z). More...
 
int lis3dh_getAccel_mg (lis3dh_t *device, int axis)
 Gets mg (milli-g's) accelerometer measurements from a single axis (x, y, or z). More...
 
int lis3dh_tilt (lis3dh_t *device, int *ax, int *ay, int *az, int *motion)
 Gets tilt angle measurements for each axis, and magnitude of motion. More...
 
int lis3dh_tiltConfig (lis3dh_t *device, int avg_factor)
 Optional configuration for tilt sensor. More...
 
void lis3dh_writeByte (lis3dh_t *device, unsigned char address, unsigned char value)
 write a byte value to an LIS3DH register More...
 
unsigned char lis3dh_readByte (lis3dh_t *device, unsigned char address)
 Read a value from an LIS3DH register. More...
 

Detailed Description

Simplifies reading Parallax LIS3DH 3-Axis Accelerometer Module with ADC.

Author
Michael Mulholland
Version
1.0.1