RegForge

All parts / LIS3DH

LIS3DH register map

3-axis MEMS accelerometer with FIFO, click and 4D detection — STMicroelectronics

40 registers I2C, SPI I²C 0x18, 0x19 8-bit reg addresses 80% bit coverage not yet human-verified

Get it as a C header

pip install regforge
regforge gen LIS3DH --out ./src --driver --tests

Writes lis3dh_regs.h with every address, mask and shift below, a bus-agnostic driver skeleton, and a file of compile-time assertions that make your compiler check the bit arithmetic. No API key needed — this part ships inside the package.

Not yet human-verified. Transcribed and mechanically validated — no overlapping fields, no out-of-range bits, reset values consistent with their fields — but not yet checked line-by-line against the datasheet. Verifying it is a useful half hour.

Registers

AddrRegisterAccessWidthResetDescription
0x07STATUS_REG_AUXRO8—ADC data-ready and overrun flags
0x08OUT_ADC1_LRO8—ADC channel 1, low byte
0x09OUT_ADC1_HRO8—ADC channel 1, high byte
0x0AOUT_ADC2_LRO8—ADC channel 2, low byte
0x0BOUT_ADC2_HRO8—ADC channel 2, high byte
0x0COUT_ADC3_LRO8—ADC channel 3, low byte
0x0DOUT_ADC3_HRO8—ADC channel 3, high byte
0x0FWHO_AM_IRO80x33Device identification. Always reads 0x33.
0x1ECTRL_REG0RW80x10SDO/SA0 pull-up control. The reserved bits must be written as 0b0010000.
0x1FTEMP_CFG_REGRW80x00Temperature sensor and ADC enable
0x20CTRL_REG1RW80x07Output data rate, low-power mode and axis enables. Note the reset value: all three axes are enabled but ODR is power-down, so the part produces nothing until you set a rate.
0x21CTRL_REG2RW80x00High-pass filter configuration
0x22CTRL_REG3RW80x00INT1 pin routing
0x23CTRL_REG4RW80x00Scale, resolution and SPI mode
0x24CTRL_REG5RW80x00Memory reboot, FIFO and interrupt latching
0x25CTRL_REG6RW80x00INT2 pin routing and interrupt polarity
0x26REFERENCERW80x00Reference value for interrupt generation
0x27STATUS_REGRO80x00Acceleration data status
0x28OUT_X_LRO8—X-axis acceleration, low byte
0x29OUT_X_HRO8—X-axis acceleration, high byte
0x2AOUT_Y_LRO8—Y-axis acceleration, low byte
0x2BOUT_Y_HRO8—Y-axis acceleration, high byte
0x2COUT_Z_LRO8—Z-axis acceleration, low byte
0x2DOUT_Z_HRO8—Z-axis acceleration, high byte
0x2EFIFO_CTRL_REGRW80x00FIFO mode and threshold
0x2FFIFO_SRC_REGRO8—FIFO status
0x30INT1_CFGRW80x00Interrupt 1 configuration
0x31INT1_SRCRO80x00Interrupt 1 source. Cleared on read.
0x32INT1_THSRW80x00Interrupt 1 threshold
0x33INT1_DURATIONRW80x00Interrupt 1 duration
0x34INT2_CFGRW80x00Interrupt 2 configuration
0x35INT2_SRCRO80x00Interrupt 2 source. Cleared on read.
0x36INT2_THSRW80x00Interrupt 2 threshold
0x37INT2_DURATIONRW80x00Interrupt 2 duration
0x38CLICK_CFGRW80x00Click detection configuration
0x39CLICK_SRCRO80x00Click detection source
0x3ACLICK_THSRW80x00Click threshold
0x3BTIME_LIMITRW80x00Click time limit
0x3CTIME_LATENCYRW80x00Click time latency
0x3DTIME_WINDOWRW80x00Click time window

Bit layouts

Drawn MSB-first, the way the datasheet draws them. [7:5] means shift 5, width 3, mask 0xE0 — this is the notation that costs people a day when they read it backwards.

CTRL_REG0  @  0x1E  —  1 fields
SDO_PU_DISC[7]
—6
—5
—4
—3
—2
—1
—0
BitsFieldAccessMaskResetDescription
[7]SDO_PU_DISCRW0x800x001 disconnects the SDO/SA0 pull-up
TEMP_CFG_REG  @  0x1F  —  2 fields
ADC_EN[7]
TEMP_EN[6]
—5
—4
—3
—2
—1
—0
BitsFieldAccessMaskResetDescription
[7]ADC_ENRW0x800x00Enable the auxiliary ADC
[6]TEMP_ENRW0x400x00Enable the temperature sensor
CTRL_REG1  @  0x20  —  5 fields
ODR[7:4]
LPEN[3]
ZEN[2]
YEN[1]
XEN[0]
BitsFieldAccessMaskResetDescription
[7:4]ODRRW0xF00x00Output data rate
[3]LPENRW0x080x00Low-power mode enable (8-bit data)
[2]ZENRW0x040x01Z-axis enable
[1]YENRW0x020x01Y-axis enable
[0]XENRW0x010x01X-axis enable

CTRL_REG1.ODR values

ValueNameMeaning
0x00POWER_DOWNPower down (default)
0x01HZ_11 Hz
0x02HZ_1010 Hz
0x03HZ_2525 Hz
0x04HZ_5050 Hz
0x05HZ_100100 Hz
0x06HZ_200200 Hz
0x07HZ_400400 Hz
0x08LP_16201.62 kHz, low-power mode only
0x09HZ_53765.376 kHz low-power / 1.344 kHz normal
CTRL_REG2  @  0x21  —  6 fields
HPM[7:6]
HPCF[5:4]
FDS[3]
HPCLICK[2]
HP_IA2[1]
HP_IA1[0]
BitsFieldAccessMaskResetDescription
[7:6]HPMRW0xC00x00High-pass filter mode
[5:4]HPCFRW0x300x00High-pass filter cutoff frequency
[3]FDSRW0x080x00Filtered data selection
[2]HPCLICKRW0x040x00High-pass filter enabled for click
[1]HP_IA2RW0x020x00High-pass filter enabled for interrupt 2
[0]HP_IA1RW0x010x00High-pass filter enabled for interrupt 1
CTRL_REG3  @  0x22  —  7 fields
I1_CLICK[7]
I1_IA1[6]
I1_IA2[5]
I1_ZYXDA[4]
I1_321DA[3]
I1_WTM[2]
I1_OVERRUN[1]
—0
BitsFieldAccessMaskResetDescription
[7]I1_CLICKRW0x800x00Click interrupt on INT1
[6]I1_IA1RW0x400x00IA1 interrupt on INT1
[5]I1_IA2RW0x200x00IA2 interrupt on INT1
[4]I1_ZYXDARW0x100x00Data ready on INT1
[3]I1_321DARW0x080x00ADC data ready on INT1
[2]I1_WTMRW0x040x00FIFO watermark on INT1
[1]I1_OVERRUNRW0x020x00FIFO overrun on INT1
CTRL_REG4  @  0x23  —  6 fields
BDU[7]
BLE[6]
FS[5:4]
HR[3]
ST[2:1]
SIM[0]
BitsFieldAccessMaskResetDescription
[7]BDURW0x800x00Block data update. Set it, or the high and low bytes of a sample can come from different measurements.
[6]BLERW0x400x00Big/little endian selection
[5:4]FSRW0x300x00Full-scale selection
[3]HRRW0x080x00High-resolution output mode (12-bit)
[2:1]STRW0x060x00Self-test enable
[0]SIMRW0x010x00SPI serial interface mode. 1 = 3-wire.

CTRL_REG4.FS values

ValueNameMeaning
0x00G_2+/-2 g (default)
0x01G_4+/-4 g
0x02G_8+/-8 g
0x03G_16+/-16 g
CTRL_REG5  @  0x24  —  6 fields
BOOT[7]
FIFO_EN[6]
—5
—4
LIR_INT1[3]
D4D_INT1[2]
LIR_INT2[1]
D4D_INT2[0]
BitsFieldAccessMaskResetDescription
[7]BOOTW1P0x800x00Reboot memory content; self-clearing
[6]FIFO_ENRW0x400x00FIFO enable
[3]LIR_INT1RW0x080x00Latch interrupt request on INT1
[2]D4D_INT1RW0x040x004D detection enabled on INT1
[1]LIR_INT2RW0x020x00Latch interrupt request on INT2
[0]D4D_INT2RW0x010x004D detection enabled on INT2
CTRL_REG6  @  0x25  —  6 fields
I2_CLICK[7]
I2_IA1[6]
I2_IA2[5]
I2_BOOT[4]
I2_ACT[3]
—2
INT_POLARITY[1]
—0
BitsFieldAccessMaskResetDescription
[7]I2_CLICKRW0x800x00Click interrupt on INT2
[6]I2_IA1RW0x400x00IA1 interrupt on INT2
[5]I2_IA2RW0x200x00IA2 interrupt on INT2
[4]I2_BOOTRW0x100x00Boot status on INT2
[3]I2_ACTRW0x080x00Activity interrupt on INT2
[1]INT_POLARITYRW0x020x000 = active high, 1 = active low
STATUS_REG  @  0x27  —  8 fields
ZYXOR[7]
ZOR[6]
YOR[5]
XOR_[4]
ZYXDA[3]
ZDA[2]
YDA[1]
XDA[0]
BitsFieldAccessMaskResetDescription
[7]ZYXORRO0x800x00X, Y and Z data overrun
[6]ZORRO0x400x00Z data overrun
[5]YORRO0x200x00Y data overrun
[4]XOR_RO0x100x00X data overrun
[3]ZYXDARO0x080x00X, Y and Z new data available
[2]ZDARO0x040x00Z new data available
[1]YDARO0x020x00Y new data available
[0]XDARO0x010x00X new data available
FIFO_CTRL_REG  @  0x2E  —  3 fields
FM[7:6]
TR[5]
FTH[4:0]
BitsFieldAccessMaskResetDescription
[7:6]FMRW0xC00x00FIFO mode
[5]TRRW0x200x00Trigger selection. 0 = INT1, 1 = INT2.
[4:0]FTHRW0x1F0x00FIFO threshold

FIFO_CTRL_REG.FM values

ValueNameMeaning
0x00BYPASSBypass mode (default)
0x01FIFOFIFO mode
0x02STREAMStream mode
0x03STREAM_TO_FIFOStream-to-FIFO mode
FIFO_SRC_REG  @  0x2F  —  4 fields
WTM[7]
OVRN_FIFO[6]
EMPTY[5]
FSS[4:0]
BitsFieldAccessMaskResetDescription
[7]WTMRO0x80—Watermark level reached
[6]OVRN_FIFORO0x40—FIFO overrun
[5]EMPTYRO0x20—FIFO is empty
[4:0]FSSRO0x1F—Number of unread samples

Generated C header

What regforge gen LIS3DH writes for STATUS_REG:

/* ------------------------------------------------------------------------ */
/* STATUS_REG @ 0x27u  ro  8-bit  reset 0x00u */
/* Acceleration data status */
/* ------------------------------------------------------------------------ */

#define LIS3DH_STATUS_REG                              0x27u
#define LIS3DH_STATUS_REG_WIDTH                        8u
#define LIS3DH_STATUS_REG_RESET                        0x00u

/*   ZYXOR bits [7] ro reset 0x00u -- X, Y and Z data overrun */
#define LIS3DH_STATUS_REG_ZYXOR_SHIFT                  7u
#define LIS3DH_STATUS_REG_ZYXOR_WIDTH                  1u
#define LIS3DH_STATUS_REG_ZYXOR_MASK                   0x80u
#define LIS3DH_STATUS_REG_ZYXOR_GET(reg)               (((uint8_t)(reg) & 0x80u) >> 7u)
#define LIS3DH_STATUS_REG_ZYXOR_SET(reg, val)          (((uint8_t)(reg) & (uint8_t)~0x80u) | (((uint8_t)(val) << 7u) & 0x80u))

/*   ZOR bits [6] ro reset 0x00u -- Z data overrun */
#define LIS3DH_STATUS_REG_ZOR_SHIFT                    6u
#define LIS3DH_STATUS_REG_ZOR_WIDTH                    1u
#define LIS3DH_STATUS_REG_ZOR_MASK                     0x40u
#define LIS3DH_STATUS_REG_ZOR_GET(reg)                 (((uint8_t)(reg) & 0x40u) >> 6u)
#define LIS3DH_STATUS_REG_ZOR_SET(reg, val)            (((uint8_t)(reg) & (uint8_t)~0x40u) | (((uint8_t)(val) << 6u) & 0x40u))

/*   YOR bits [5] ro reset 0x00u -- Y data overrun */
#define LIS3DH_STATUS_REG_YOR_SHIFT                    5u
#define LIS3DH_STATUS_REG_YOR_WIDTH                    1u
#define LIS3DH_STATUS_REG_YOR_MASK                     0x20u
#define LIS3DH_STATUS_REG_YOR_GET(reg)                 (((uint8_t)(reg) & 0x20u) >> 5u)
#define LIS3DH_STATUS_REG_YOR_SET(reg, val)            (((uint8_t)(reg) & (uint8_t)~0x20u) | (((uint8_t)(val) << 5u) & 0x20u))

/*   XOR_ bits [4] ro reset 0x00u -- X data overrun */
#define LIS3DH_STATUS_REG_XOR_SHIFT                    4u
#define LIS3DH_STATUS_REG_XOR_WIDTH                    1u
#define LIS3DH_STATUS_REG_XOR_MASK                     0x10u
#define LIS3DH_STATUS_REG_XOR_GET(reg)                 (((uint8_t)(reg) & 0x10u) >> 4u)
#define LIS3DH_STATUS_REG_XOR_SET(reg, val)            (((uint8_t)(reg) & (uint8_t)~0x10u) | (((uint8_t)(val) << 4u) & 0x10u))

/*   ZYXDA bits [3] ro reset 0x00u -- X, Y and Z new data available */
#define LIS3DH_STATUS_REG_ZYXDA_SHIFT                  3u
#define LIS3DH_STATUS_REG_ZYXDA_WIDTH                  1u
#define LIS3DH_STATUS_REG_ZYXDA_MASK                   0x08u
#define LIS3DH_STATUS_REG_ZYXDA_GET(reg)               (((uint8_t)(reg) & 0x08u) >> 3u)
#define LIS3DH_STATUS_REG_ZYXDA_SET(reg, val)          (((uint8_t)(reg) & (uint8_t)~0x08u) | (((uint8_t)(val) << 3u) & 0x08u))

Compared with

Related parts

ADXL345
Analog Devices
30 registers
DS1307
Analog Devices
8 registers
DS3231
Analog Devices
19 registers

Source

Transcribed from ST LIS3DH datasheet (hand-transcribed) (hand-transcribed). Hand-authored seed entry, not machine-extracted. Multi-byte reads require the MSB of the sub-address to be set for auto-increment; that is a bus-protocol detail rather than a register and is not modelled here. Check against the datasheet before trusting it, then mark it verified.

Raw JSON · Report an error