BERGSONNE

Sense.BP

ILPS22QS barometric pressure & temperature sensor.

Platform-agnostic driver for the ST ILPS22QS dual full-scale absolute pressure sensor (260–1260 hPa or 260–4060 hPa) with embedded temperature sensor, 128-sample FIFO, low-pass filter, and Qvar electrostatic sensing.

Datasheet

Examples

Quick start

  #include "core.h"
  #include "core_tiles.h"
  #include "tile_sense_bp.h"

  tile_t baro;
  sense_bp_cfg_t cfg = { .odr = SENSE_BP_ODR_25HZ };
  tile_sense_bp_init(core_tiles_pal(&core_i2c3), 0, &baro, &cfg);

  int32_t pressure_mhpa = tile_sense_bp_get_pressure_mhpa(&baro);
  int32_t temp_cdeg     = tile_sense_bp_get_temp_cdeg(&baro);

API reference

Initialization

tile_sense_bp_find

uint8_t tile_sense_bp_find(tiles_pal_t *hal, uint8_t instance)

Check if a Sense.BP is present on the bus.

hal
Platform HAL handle.
instance
0 = default address (0x5D), 1 = alternate (0x5C).

Returns 1 if device ACKs and WHO_AM_I matches, 0 otherwise.

tile_sense_bp_init

void tile_sense_bp_init(tiles_pal_t *hal, uint8_t instance, tile_t *tile, const sense_bp_cfg_t *cfg)

Probes the device, verifies WHO_AM_I, configures ODR/AVG/FS/LPF/BDU, disables AH/Qvar for lower power, and sets tile state to READY.

hal
Platform HAL handle.
instance
0 = default (0x5D), 1 = alternate (0x5C).
tile
Tile handle to initialise.
cfg
Configuration (NULL for defaults).

Lifecycle

tile_sense_bp_sleep

Studio
void tile_sense_bp_sleep(tile_t *tile)

Enter power-down mode (ODR = 0).

tile
Initialised tile handle.

tile_sense_bp_wake

Studio
void tile_sense_bp_wake(tile_t *tile)

Resume from power-down using cached ODR/AVG settings.

tile
Sleeping tile handle.

tile_sense_bp_reset

Studio
void tile_sense_bp_reset(tile_t *tile)

All registers return to defaults. Call init() again after reset.

tile
Tile handle.

Runtime

tile_sense_bp_get_pressure_raw

Studio
int32_t tile_sense_bp_get_pressure_raw(tile_t *tile)

Read the raw 24-bit pressure output (two's complement).

tile
Initialised tile handle.

Returns Raw 24-bit signed value, sign-extended to int32_t.

tile_sense_bp_get_pressure_mhpa

Studio
int32_t tile_sense_bp_get_pressure_mhpa(tile_t *tile)

Returns pressure * 1000 in mhPa units. For example, 1013250 = 1013.250 hPa. Accounts for the current full-scale mode setting.

tile
Initialised tile handle.

Returns Pressure in milli-hPa (mhPa).

tile_sense_bp_get_temp_raw

Studio
int16_t tile_sense_bp_get_temp_raw(tile_t *tile)

Read the raw 16-bit temperature output (two's complement).

tile
Initialised tile handle.

Returns Raw 16-bit signed value, sign-extended to int16_t.

tile_sense_bp_get_temp_cdeg

Studio
int32_t tile_sense_bp_get_temp_cdeg(tile_t *tile)

Returns temperature * 100. For example, 2534 = 25.34 °C. Sensor sensitivity is 100 LSB/°C, so this is (raw * 100) / 100 = raw.

tile
Initialised tile handle.

Returns Temperature in centi-°C.

tile_sense_bp_oneshot

Studio
void tile_sense_bp_oneshot(tile_t *tile)

ODR must be POWERDOWN. Sets the ONESHOT bit in CTRL_REG2. The bit self-clears when the measurement is complete.

tile
Tile handle in power-down mode.

tile_sense_bp_get_status

Studio
uint8_t tile_sense_bp_get_status(tile_t *tile)

Read the STATUS register.

tile
Initialised tile handle.

Returns Raw STATUS byte (use ILPS22QS_STATUS_* masks).

tile_sense_bp_pressure_ready

Studio
uint8_t tile_sense_bp_pressure_ready(tile_t *tile)

Check if new pressure data is available.

tile
Initialised tile handle.

Returns 1 if P_DA is set, 0 otherwise.

tile_sense_bp_temp_ready

Studio
uint8_t tile_sense_bp_temp_ready(tile_t *tile)

Check if new temperature data is available.

tile
Initialised tile handle.

Returns 1 if T_DA is set, 0 otherwise.

tile_sense_bp_is_boot_complete

Studio
uint8_t tile_sense_bp_is_boot_complete(tile_t *tile)

After VDD ramps, the ILPS22QS reloads its trim parameters from NVM. The BOOT_ON bit in INT_SOURCE reads 1 during this phase and 0 once the chip is ready to be configured. Reads of this getter are non-clearing (the BOOT_ON bit is preserved across the read; only the threshold/IA flags clear on read). Useful when interrogating the chip immediately after VDD comes up, or after software reset. A typical pattern: tile_sense_bp_reset(&baro); while (!tile_sense_bp_is_boot_complete(&baro)) core_delay_ms(1); // chip is now ready for re-configuration

tile
Initialised tile handle.

Returns 1 if boot complete (BOOT_ON cleared), 0 if still booting.

tile_sense_bp_read_altitude_mm

Studio
int32_t tile_sense_bp_read_altitude_mm(tile_t *tile, uint32_t sea_level_pa)

Pure-integer linear approximation around the reference pressure: h_mm = 8430 * (P0_pa - P_pa) / 100 which corresponds to ~8.43 mm of altitude per pascal of pressure decrease — the standard-atmosphere lapse-rate slope near sea level. Accuracy regime: this is a first-order linearisation valid for roughly ±1500 m around the supplied reference (i.e. the kind of range you care about for indoor floor detection, ascent-rate estimation, or short-baseline relative-altitude tracking). Error grows with the cube of altitude — at ±3000 m the underlying exponential law diverges from the linear fit by tens of metres, and outside the ILPS22QS's pressure range (260–1260 hPa or 260–4060 hPa depending on FS mode) the result is meaningless. For absolute geodetic altitude over wide ranges, use a full barometric-formula library on a host with floats. The reference is supplied in pascals (not hPa) for the convenience of callers that already have a recent QNH/QFE figure handy. Pass `101325` for the ICAO standard sea level reference. the reference. Negative when the measured pressure exceeds the reference (deeper than the reference altitude).

tile
Initialised tile handle.
sea_level_pa
Reference pressure in pascals (e.g. 101325).

Returns Altitude in millimetres above (positive) or below (negative)

tile_sense_bp_wait_for_pressure_change

Studio
uint8_t tile_sense_bp_wait_for_pressure_change(tile_t *tile, uint16_t threshold_hpa, uint32_t timeout_ms)

Captures the current pressure at call time, then polls at the chip's configured ODR cadence until either: - |pressure - baseline| >= threshold_hpa, or - timeout_ms elapses with no qualifying change. This is a blocking helper. The polling cadence is derived from the cached CTRL_REG1 ODR field — the function sleeps for one ODR period between samples (or 10 ms as a fallback if ODR is power-down or unrecognised). For one-shot users, configure a non-power-down ODR before calling. Useful for "tap-to-wake" altitude triggers, ascent/descent detection, or pressure-step-driven UI events — without committing to the full threshold-interrupt configuration in CTRL_REG3 / INTERRUPT_CFG.

tile
Initialised tile handle.
threshold_hpa
Absolute deviation that triggers return (hPa).
timeout_ms
Maximum wait in milliseconds.

Returns 1 if the threshold was crossed, 0 if the call timed out.

Config

tile_sense_bp_set_odr

Studio
void tile_sense_bp_set_odr(tile_t *tile, sense_bp_odr_t odr)

Set the output data rate.

tile
Initialised tile handle.
odr
Desired output data rate.

tile_sense_bp_set_avg

Studio
void tile_sense_bp_set_avg(tile_t *tile, sense_bp_avg_t avg)

Set the averaging filter depth.

tile
Initialised tile handle.
avg
Desired averaging.

tile_sense_bp_set_fullscale

Studio
void tile_sense_bp_set_fullscale(tile_t *tile, sense_bp_fs_t fs)

Set the full-scale mode.

tile
Initialised tile handle.
fs
Full-scale selection.

tile_sense_bp_set_lpf

Studio
void tile_sense_bp_set_lpf(tile_t *tile, uint8_t enable, sense_bp_lpf_bw_t bw)

Enable or disable the low-pass filter.

tile
Initialised tile handle.
enable
1 = enable, 0 = disable.
bw
Bandwidth selection (only used if enable = 1).

tile_sense_bp_set_threshold_hpa

Studio
void tile_sense_bp_set_threshold_hpa(tile_t *tile, uint16_t ths_hpa)

The threshold is applied to the differential pressure (P_DIFF_IN). Enable PHE/PLE bits in INTERRUPT_CFG to generate interrupts.

tile
Initialised tile handle.
ths_hpa
Threshold in hPa (unsigned, applied symmetrically).

tile_sense_bp_set_interrupt_cfg

Studio
void tile_sense_bp_set_interrupt_cfg(tile_t *tile, uint8_t cfg)

Configure the interrupt source register.

tile
Initialised tile handle.
cfg
Raw INTERRUPT_CFG byte (use ILPS22QS_INTCFG_* masks).

tile_sense_bp_get_int_source

Studio
uint8_t tile_sense_bp_get_int_source(tile_t *tile)

Read the interrupt source register (clears latched flags).

tile
Initialised tile handle.

Returns Raw INT_SOURCE byte (use ILPS22QS_INT_SRC_* masks).

tile_sense_bp_set_autozero

Studio
void tile_sense_bp_set_autozero(tile_t *tile)

Captures current pressure as REF_P. Output registers then show the difference from reference. Reset with reset_autozero().

tile
Initialised tile handle.

tile_sense_bp_reset_autozero

Studio
void tile_sense_bp_reset_autozero(tile_t *tile)

Reset autozero mode to normal operation.

tile
Initialised tile handle.

tile_sense_bp_set_autorefp

Studio
void tile_sense_bp_set_autorefp(tile_t *tile)

Captures current pressure as REF_P for interrupt threshold comparison. Output registers are not affected. Reset with reset_autorefp().

tile
Initialised tile handle.

tile_sense_bp_reset_autorefp

Studio
void tile_sense_bp_reset_autorefp(tile_t *tile)

Reset autorefp mode to normal operation.

tile
Initialised tile handle.

tile_sense_bp_set_pressure_offset

Studio
void tile_sense_bp_set_pressure_offset(tile_t *tile, int16_t offset)

The offset is in raw LSB units (signed 16-bit) and is subtracted from the measured pressure before output.

tile
Initialised tile handle.
offset
Raw offset value (two's complement).

tile_sense_bp_get_ref_pressure

Studio
int16_t tile_sense_bp_get_ref_pressure(tile_t *tile)

Read the reference pressure registers (REF_P).

tile
Initialised tile handle.

Returns 16-bit signed reference pressure value.

gapAnalog Hub / Qvar charge-variation sensingHardware-gated on Sense.BP rev a. The ILPS22QS reads charge variation on dedicated input pins (chip pins 5 = AH2/QVAR2 and 7 = AH1/QVAR1) that need an external electrode wired in. The current tile rev leaves tile pads 6/7/8 unconnected (per Sense-BP-a.json) — those chip pins are tied to GND on the PCB per the datasheet's "if not used" recommendation. Even with AH_QVAR_EN=1, no signal can reach the chip. Closing this gap requires a tile hardware revision that routes one or both AH pins to a tile pad with electrode access.

FIFO

tile_sense_bp_set_fifo_mode

Studio
void tile_sense_bp_set_fifo_mode(tile_t *tile, sense_bp_fifo_mode_t mode)

Configure the FIFO mode.

tile
Initialised tile handle.
mode
FIFO mode selection.

tile_sense_bp_set_fifo_watermark

Studio
void tile_sense_bp_set_fifo_watermark(tile_t *tile, uint8_t watermark)

Set the FIFO watermark threshold (0–127).

tile
Initialised tile handle.
watermark
Threshold level (0–127).

tile_sense_bp_get_fifo_level

Studio
uint8_t tile_sense_bp_get_fifo_level(tile_t *tile)

Read the number of unread FIFO samples.

tile
Initialised tile handle.

Returns Number of unread samples (0–128).

tile_sense_bp_get_fifo_status

Studio
uint8_t tile_sense_bp_get_fifo_status(tile_t *tile)

Read FIFO status flags.

tile
Initialised tile handle.

Returns Raw FIFO_STATUS2 byte (use ILPS22QS_FIFO_* masks).

tile_sense_bp_read_fifo_raw

Studio
int32_t tile_sense_bp_read_fifo_raw(tile_t *tile)

Read one raw 24-bit pressure sample from the FIFO.

tile
Initialised tile handle.

Returns Raw 24-bit signed pressure value, sign-extended to int32_t.

tile_sense_bp_read_fifo_batch

Studio
uint8_t tile_sense_bp_read_fifo_batch(tile_t *tile, int32_t *buf, uint8_t count)

24-bit signed values (sign-extended to int32_t). many samples and returns the actual count.

tile
Initialised tile handle.
buf
Caller-allocated buffer the driver fills with raw
count
Capacity of `buf` — the driver fills up to this

Returns Number of samples actually read.

Driver gaps · 1

Chip capabilities this driver doesn’t expose yet.

advancedAlternate bus modes (SPI / I3C)Ecosystem-gated. ILPS22QS supports 3-wire and 4-wire SPI (CS = pad 3 strap) and I3C SDR. The driver framework currently uses tiles_pal I²C calls exclusively; adding SPI requires plumbing hal->spi_* through the driver, and I3C requires a new bus abstraction in Studio that doesn't exist yet. Defer to a future multi-bus driver framework pass.

Enums

sense_bp_odr_t

Output data rate selection (CTRL_REG1 ODR[3:0], bits 6:3).

SENSE_BP_ODR_POWERDOWN
Power-down / one-shot
SENSE_BP_ODR_1HZ
1 Hz
SENSE_BP_ODR_4HZ
4 Hz
SENSE_BP_ODR_10HZ
10 Hz
SENSE_BP_ODR_25HZ
25 Hz
SENSE_BP_ODR_50HZ
50 Hz
SENSE_BP_ODR_75HZ
75 Hz
SENSE_BP_ODR_100HZ
100 Hz
SENSE_BP_ODR_200HZ
200 Hz

sense_bp_avg_t

Averaging selection (CTRL_REG1 AVG[2:0], bits 2:0).

SENSE_BP_AVG_4
4 samples
SENSE_BP_AVG_8
8 samples
SENSE_BP_AVG_16
16 samples
SENSE_BP_AVG_32
32 samples
SENSE_BP_AVG_64
64 samples
SENSE_BP_AVG_128
128 samples
SENSE_BP_AVG_512
512 samples

sense_bp_fs_t

Full-scale mode selection (CTRL_REG2 FS_MODE, bit 6).

SENSE_BP_FS_1260HPA
Mode 1: 260–1260 hPa, 4096 LSB/hPa
SENSE_BP_FS_4060HPA
Mode 2: 260–4060 hPa, 2048 LSB/hPa

sense_bp_lpf_bw_t

Low-pass filter bandwidth (CTRL_REG2 LFPF_CFG, bit 5).

SENSE_BP_LPF_ODR_4
Bandwidth = ODR/4
SENSE_BP_LPF_ODR_9
Bandwidth = ODR/9

sense_bp_fifo_mode_t

FIFO mode selection (FIFO_CTRL F_MODE[1:0] + TRIG_MODES).

SENSE_BP_FIFO_BYPASS
FIFO disabled
SENSE_BP_FIFO_FIFO
Stop when full
SENSE_BP_FIFO_CONTINUOUS
Dynamic stream, overwrites oldest
SENSE_BP_FIFO_BYP2FIFO
Bypass-to-FIFO on trigger
SENSE_BP_FIFO_BYP2CONT
Bypass-to-continuous on trigger
SENSE_BP_FIFO_CONT2FIFO
Continuous-to-FIFO on trigger

Constants

TILE_SENSE_BP_VERSION_MAJOR1
TILE_SENSE_BP_VERSION_MINOR2
TILE_SENSE_BP_VERSION_PATCH0
ILPS22QS_I2C_ADDR_DEFAULT0x5DAD0 float/high (default)
ILPS22QS_I2C_ADDR_ALT0x5CAD0 to GND
ILPS22QS_WHO_AM_I_VALUE0xB4