Using LPS22HH and LIS2DW12 Sensors
This application note describes how to configure LPS22HH and LIS2DW12 sensors on the SOM-NRF9151 baseboard in Zephyr BSP and use them in the user application.
The LPS22HH device is declared in nrf9151som_nrf9151_ns.dts as a child node of the i2c2 bus:
&i2c2 {
status = "okay";
lps22hh: lps22hh@5c {
compatible = "st,lps22hh";
reg = <0x5c>;
drdy-gpios = <&gpio0 5 GPIO_ACTIVE_HIGH>;
};
};This node configures the following parameters:
Parameter | Value | Description |
|---|---|---|
|
| Enables the |
|
| LPS22HH slave address on the I2C bus, which will be used by the driver to communicate with the barometer. |
|
| Host SoC GPIO, that will be used for LPS22HH interrupts. |
The LIS2DW12 device is declared in nrf9151som_nrf9151_ns.dts as a child node of the i2c2 bus:
&i2c2 {
status = "okay";
lis2dw12: lis2dw12@19 {
compatible = "st,lis2dw12";
reg = <0x19>;
irq-gpios = <&gpio0 7 GPIO_ACTIVE_HIGH>, <&gpio0 6 GPIO_ACTIVE_HIGH>;
int-pin = <1>;
tap-threshold = <1>, <1>, <1>;
};
};This node configures the following parameters:
Parameter | Value | Description |
|---|---|---|
|
| Enables the |
|
| LIS2DW12 slave address on the I2C bus, which will be used by the driver to communicate with the IMU. |
|
| Host SoC GPIO, that will be used for LIS2DW12 interrupts. |
|
| Select DRDY pin number (1 or 2). This number represents which of the two interrupt pins (INT1 or INT2) the drdy line is attached to. This property is not mandatory and if not present it defaults to 1 which is the configuration at power-up. |
|
| Tap X/Y/Z axes threshold. Default is power-up configuration. Thresholds to start the tap-event detection procedure on the X/Y/Z axes. For example, if you want to set the threshold for X to 12, for Z to 14 and want to disable tap detection on Y, you should specify in Device Tree, which is equivalent to X = 12 * 2g/32 = 750mg and Z = 14 * 2g/32 = 875mg. |
The Customized Asset Tracker v2 application makes use of the Zephyr Sensor API, which is defined in zephyr/drivers/sensor.h:
Function | Description | Comments |
| Set an attribute for a sensor. |
Returns 0 if successful, negative errno code if failure. |
| Get an attribute for a sensor. |
Returns 0 if successful, negative errno code if failure. |
| Fetch a sample from the sensor and store it in an internal driver buffer. |
Returns 0 if successful, negative errno code if failure. Read all of a sensor's active channels and, if necessary, perform any additional operations necessary to make the values useful. The user may then get individual channel values by calling The function blocks until the fetch operation is complete. Since the function communicates with the sensor device, it is unsafe to call it in an ISR if the device is connected via I2C or SPI. |
| Fetch a sample from the sensor and store it in an internal driver buffer. |
Returns 0 if successful, negative errno code if failure. Read and compute compensation for one type of sensor data (magnetometer, accelerometer, etc). The user may then get individual channel values by This is mostly implemented by multi function devices enabling reading at different sampling rates. The function blocks until the fetch operation is complete. Since the function communicates with the sensor device, it is unsafe to call it in an ISR if the device is connected via I2C or SPI. |
| Get a reading from a sensor device. |
Return a useful value for a particular channel, from the driver's internal data. Before calling this function, a sample must be obtained by calling |
| Activate a sensor's trigger and set the trigger handle. |
Returns 0 if successful, negative errno code if failure. The handler will be called from a thread, so I2C or SPI operations are safe. However, the thread's stack is limited and defined by the driver. It is currently up to the caller to ensure that the handler does not overflow the stack. The user-allocated trigger will be stored by the driver as a pointer, rather than a copy, and passed back to the handler. This enables the handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct and requires that the trigger is not allocated on the stack. |