LIS3DH Propeller C library
v1.0.0
Propeller C Library for the Parallax LIS3DH 3 Axis Accelerometer with ADC module
|
Go to the documentation of this file.
18 #if defined(__cplusplus)
24 #include "simpletools.h"
35 #define LIS3DH_STATUS_REG_AUX 0x07 // r 07 000 0111 Output
36 #define LIS3DH_OUT_ADC1_L 0x08 // r 08 000 1000 Output
37 #define LIS3DH_OUT_ADC1_H 0x09 // r 09 000 1001 Output
38 #define LIS3DH_OUT_ADC2_L 0x0A // r 0A 000 1010 Output
39 #define LIS3DH_OUT_ADC2_H 0x0B // r 0B 000 1011 Output
40 #define LIS3DH_OUT_ADC3_L 0x0C // r 0C 000 1100 Output
41 #define LIS3DH_OUT_ADC3_H 0x0D // r 0D 000 1101 Output
42 #define LIS3DH_WHO_AM_I 0x0F // r 0F 000 1111 00110011 Device identification register
43 #define LIS3DH_WHO_AM_I_REPLY 0x33 // Expected reply to WHO_AM_I
44 #define LIS3DH_CTRL_REG0 0x1E // rw 1E 001 1110 00010000
45 #define LIS3DH_TEMP_CFG_REG 0x1F // rw 1F 001 1111 00000000
46 #define LIS3DH_CTRL_REG1 0x20 // rw 20 010 0000 00000111
47 #define LIS3DH_CTRL_REG2 0x21 // rw 21 010 0001 00000000
48 #define LIS3DH_CTRL_REG3 0x22 // rw 22 010 0010 00000000
49 #define LIS3DH_CTRL_REG4 0x23 // rw 23 010 0011 00000000
50 #define LIS3DH_CTRL_REG5 0x24 // rw 24 010 0100 00000000
51 #define LIS3DH_CTRL_REG6 0x25 // rw 25 010 0101 00000000
52 #define LIS3DH_REFERENCE 0x26 // rw 26 010 0110 00000000
53 #define LIS3DH_STATUS_REG 0x27 // r 27 010 0111 Output
54 #define LIS3DH_OUT_X_L 0x28 // r 28 010 1000 Output
55 #define LIS3DH_OUT_X_H 0x29 // r 29 010 1001 Output
56 #define LIS3DH_OUT_Y_L 0x2A // r 2A 010 1010 Output
57 #define LIS3DH_OUT_Y_H 0x2B // r 2B 010 1011 Output
58 #define LIS3DH_OUT_Z_L 0x2C // r 2C 010 1100 Output
59 #define LIS3DH_OUT_Z_H 0x2D // r 2D 010 1101 Output
60 #define LIS3DH_FIFO_CTRL_REG 0x2E // rw 2E 010 1110 00000000
61 #define LIS3DH_FIFO_SRC_REG 0x2F // r 2F 010 1111 Output
62 #define LIS3DH_INT1_CFG 0x30 // rw 30 011 0000 00000000
63 #define LIS3DH_INT1_SRC 0x31 // r 31 011 0001 Output
64 #define LIS3DH_INT1_THS 0x32 // rw 32 011 0010 00000000
65 #define LIS3DH_INT1_DURATION 0x33 // rw 33 011 0011 00000000
66 #define LIS3DH_INT2_CFG 0x34 // rw 34 011 0100 00000000
67 #define LIS3DH_INT2_SRC 0x35 // r 35 011 0101 Output
68 #define LIS3DH_INT2_THS 0x36 // rw 36 011 0110 00000000
69 #define LIS3DH_INT2_DURATION 0x37 // rw 37 011 0111 00000000
70 #define LIS3DH_CLICK_CFG 0x38 // rw 38 011 1000 00000000
71 #define LIS3DH_CLICK_SRC 0x39 // r 39 011 1001 Output
72 #define LIS3DH_CLICK_THS 0x3A // rw 3A 011 1010 00000000
73 #define LIS3DH_TIME_LIMIT 0x3B // rw 3B 011 1011 00000000
74 #define LIS3DH_TIME_LATENCY 0x3C // rw 3C 011 1100 00000000
75 #define LIS3DH_TIME_WINDOW 0x3D // rw 3D 011 1101 00000000
76 #define LIS3DH_ACT_THS 0x3E // rw 3E 011 1110 00000000
77 #define LIS3DH_ACT_DUR 0x3F // rw 3F 011 1111 00000000
89 #define LIS3DH_MASK_READSINGLE 0x80 // 0b10000000
90 #define LIS3DH_MASK_READREPEAT 0xC0 // 0b11000000
91 #define LIS3DH_MASK_BDUMODE 0x80 // 0b10000000
92 #define LIS3DH_MASK_SPIMODE 0x01 // 0b00000001
93 #define LIS3DH_RANGE_16 0x03 // 0b00000011
94 #define LIS3DH_RANGE_8 0x02 // 0b00000010
95 #define LIS3DH_RANGE_4 0x01 // 0b00000001
96 #define LIS3DH_RANGE_2 0x00 // 0b00000000
97 #define LIS3DH_AXIS_X 0b01 // Axis X mask
98 #define LIS3DH_AXIS_Y 0b10 // Axis Y mask
99 #define LIS3DH_AXIS_Z 0b11 // Axis Z mask
100 #define LIS3DH_ADC_1 0b01 // ADC 1 mask
101 #define LIS3DH_ADC_2 0b10 // ADC 2 mask
102 #define LIS3DH_ADC_3 0b11 // ADC 3 mask
103 #define LIS3DH_SPIMODE_3 0b01 // SPI Mode 3 mask
104 #define LIS3DH_SPIMODE_4 0b00 // SPI Mode 4 mask
105 #define LIS3DH_BDUMODE_CONTINUOUS 0b01 // BDU continuous mode mask
106 #define LIS3DH_BDUMODE_CONSISTENT 0b00 // BDU consistent mode mask
124 volatile int tempcalC;
126 volatile int adccal_m1000;
127 volatile int adccal_b1000;
129 volatile int tiltavgX;
130 volatile int tiltavgY;
131 volatile int tiltavgZ;
132 volatile int tiltavg_factor;
642 #if defined(__cplusplus)
void lis3dh_tempCal_C(lis3dh_t *device, int actualTempC)
Sets the actual temperature to provide a reference for the relative temperature sensor.
Definition: temp.c:66
lis3dh_t * lis3dh_init(int pinSCK, int pinSDI, int pinCS)
Initialize the sensor with typical configuration for reading axis and adc. Uses 3-Wire SPI mode.
Definition: init.c:21
void lis3dh_shutdown(lis3dh_t *device)
Shutdown the sensor, set configuration defaults with sensor disabled and clear buffers.
Definition: shutdown.c:21
int lis3dh_tiltConfig(lis3dh_t *device, int avg_factor)
Optional configuration for tilt sensor.
Definition: tilt.c:106
int lis3dh_getRange(lis3dh_t *device)
Reads the g measurement range; one of +/- 2, +/-4, +/- 8, +- 16 g.
Definition: getRange.c:21
void lis3dh_setRange(lis3dh_t *device, int range)
Sets the g measurement range to +/- 2, +/-4, +/- 8, +- 16 g.
Definition: setRange.c:21
void lis3dh_writeByte(lis3dh_t *device, unsigned char address, unsigned char value)
write a byte value to an LIS3DH register
Definition: writeByte.c:21
int lis3dh_getWhoAmI(lis3dh_t *device)
Reads the sensor identification register (WhoAmI).
Definition: getWhoAmI.c:21
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.
Definition: adc_mV.c:97
void lis3dh_setSPImode(lis3dh_t *device, int mode)
Sets the SPI mode to either 3-wire or 4-wire.
Definition: setSPImode.c:21
struct lis3dh_st lis3dh_t
void lis3dh_setADCmode(lis3dh_t *device, int adcEnable, int tempEnable)
Sets ADC mode for the Parallax LIS3DH 3-Axis Accelerometer Module.
Definition: setADCmode.c:21
int lis3dh_temp_F(lis3dh_t *device)
Reads the calibrated (referenced) temperature value from the sensor.
Definition: temp.c:57
int lis3dh_getAccel(lis3dh_t *device, int axis)
Gets raw accelerometer measurements for a single axis (x, y, or z).
Definition: accel.c:62
lis3dh_t * lis3dh_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.
Definition: init.c:29
void lis3dh_adc_mV(lis3dh_t *device, int *ad1, int *ad2, int *ad3)
Gets mV adc measurements from all three ADC channels.
Definition: adc_mV.c:35
void lis3dh_setBDUmode(lis3dh_t *device, int mode)
Sets the sensor BDU (Block Data Update) mode.
Definition: setBDUmode.c:21
int lis3dh_getADC_mV(lis3dh_t *device, int channel)
Gets mV adc measurement from a single ADC channel.
Definition: adc_mV.c:78
int lis3dh_tempRaw(lis3dh_t *device)
Reads the raw relative temperature value from the sensor.
Definition: temp.c:23
int lis3dh_getAccel_mg(lis3dh_t *device, int axis)
Gets mg (milli-g's) accelerometer measurements from a single axis (x, y, or z).
Definition: accel_mg.c:64
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.
Definition: tilt.c:51
void lis3dh_setResolution(lis3dh_t *device, int bits)
Sets the bit resolution for the sensor readings. 8-bit, 10-bit or 12-bit.
Definition: setResolution.c:21
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).
Definition: accel_mg.c:33
void lis3dh_adc(lis3dh_t *device, int *ad1, int *ad2, int *ad3)
Gets raw adc measurements from all three ADC channels.
Definition: adc.c:21
int lis3dh_getADC(lis3dh_t *device, int channel)
Gets raw adc measurement from a single ADC channel.
Definition: adc.c:48
void lis3dh_tempCal_F(lis3dh_t *device, int actualTempF)
Sets the actual temperature to provide a reference for the relative temperature sensor.
Definition: temp.c:76
unsigned char lis3dh_readByte(lis3dh_t *device, unsigned char address)
Read a value from an LIS3DH register.
Definition: readByte.c:21
int lis3dh_getResolution(lis3dh_t *device)
Reads the bit resolution setting from the sensor. 8-bit, 10-bit or 12-bit.
Definition: getResolution.c:21
int lis3dh_accel(lis3dh_t *device, int *x, int *y, int *z)
Gets raw accelerometer measurements from all three axis (x, y, z).
Definition: accel.c:25
int lis3dh_getSPImode(lis3dh_t *device)
Read the SPI mode currently configured in the LIS3DH module; either 3-wire or 4-wire.
Definition: getSPImode.c:21
int lis3dh_temp_C(lis3dh_t *device)
Reads the calibrated (referenced) temperature value from the sensor.
Definition: temp.c:48