English
Language : 

AN2847 Datasheet, PDF (25/31 Pages) STMicroelectronics – This document provides application information for the low-voltage 3-axis digital output
AN2847
Interrupt generation
5.4.2
Using the HP filter
The code which follows provides a basic routine showing the practical use of the inertial
wake-up feature performed on high-pass filtered data. In particular, the device is configured
to recognize when the high-frequency component of the acceleration applied along either
the X, Y or Z axis exceeds a preset threshold (250 mg is used in the example). The event
which triggers the interrupt is latched inside the device and its occurrence is signalled
through the INT1 pin.
1
write 2Fh into CTRL_REG1
// Turn on the sensor, enable X, Y and Z
// ODR = 100 Hz
2
write 15h into CTRL_REG2
// High pass filter enabled on data and interrupt1
3
write 00h into CTRL_REG3
4
write 00h into CTRL_REG4
// Latched interrupt active high on INT1 pad
// FS = 2 g
5
write 00h into CTRL_REG5
// Sleep to Wake disabled
6
write10h into INT1_THS
// Threshold = 250 mg
7
write 00h into INT1_DURATION
// Duration = 0
8
read HP_FILTER_RESET
// Dummy read to force the HP filter to
// actual acceleration value
// (i.e. set reference acceleration/tilt value)
9
write 2Ah into INT1_CFG
// Configure desired wake-up event
// Poll INT1 pin waiting for the
10
poll INT1 pad; if INT1 = 0 then goto 9
// wake-up event
11
(Wake-up event has occurred; insert
your code here)
// Event handling
12
read INT1_SRC
// Return the event that has triggered the
// interrupt and clear interrupt
13
(Insert your code here)
// Event handling
14
goto 9
At step 8, a dummy read at the HP_FILTER_RESET register is performed to set the
current/reference acceleration/tilt state against which the device performed the threshold
comparison.
This read may be performed any time it is required to set the orientation/tilt of the device as
a reference state without waiting for the filter to settle.
5.5
Free-fall detection
Free-fall detection refers to a specific configuration of the INTx_CTRL registers that allows
the recognition of device free-fall: the acceleration measurements along all the axes go to
zero. In real cases, a “free-fall zone” is defined around the zero-g level, where all
accelerations are small enough to generate the interrupt (Figure 11).
Doc ID 15136 Rev 2
25/31