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

Vibe Settings

What Studio’s Vibe interface lets you change on this tile, in plain language or from the tile inspector. Each one is an argument of a driver function below, so the same setting is available from Blocks, the DSL and C. Basic settings are shown by default; advanced ones sit behind the inspector’s Advanced toggle.

SettingTierValuesDefaultFunction
Output data ratebasic1 Hz, 4 Hz, 10 Hz, 25 Hz, 50 Hz, 75 Hz, 100 Hz, 200 Hz25 Hzset_odr(odr)
Averagingadvanced4 samples, 8 samples, 16 samples, 32 samples, 64 samples, 128 samples, 512 samples4 samplesset_avg(avg)
Pressure rangeadvancedMode 1: 260–1260 hPa, 4096 LSB/hPa, Mode 2: 260–4060 hPa, 2048 LSB/hPaMode 1: 260–1260 hPa, 4096 LSB/hPaset_fullscale(fs)
Low-pass filteradvancedon / offonset_lpf(enable)
Low-pass filter bandwidthadvancedBandwidth = ODR/4, Bandwidth = ODR/9 (Studio shows the resulting value in Hz)Bandwidth = ODR/4set_lpf(bw)

Rules Studio enforces

  • Averaging 512 samples limits the data rate to 25 Hz. Lower the data rate or the averaging.
  • Averaging 128 samples limits the data rate to 75 Hz. Lower the data rate or the averaging.
  • Averaging 64 samples limits the data rate to 100 Hz. Lower the data rate or the averaging.
  • A program may not read or stream faster than the data rate set here.

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, .lpf = 1, .bdu = 1 };
  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_sense_bp_wake

Studio
void tile_sense_bp_wake(tile_t *tile)

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

tile_sense_bp_reset

Studio
void tile_sense_bp_reset(tile_t *tile)

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

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).

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.

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).

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.

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_sense_bp_get_status

Studio
uint8_t tile_sense_bp_get_status(tile_t *tile)

Read the STATUS register.

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.

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.

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

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).

sea_level_pa
[26000..406000] Pa Reference pressure (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.

threshold_hpa
[1..4060] hPa Absolute deviation that triggers return.
timeout_ms
[0..600000] ms Maximum wait.

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)

SENSE_BP_ODR_POWERDOWN stops conversions (use oneshot() to take a reading), so Studio offers only the running rates. init() default: 25 Hz.

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)

Trades noise for current: at 25 Hz with the LPF at ODR/4 the pressure noise falls from 2.87 Pa RMS (4 samples) to 0.44 Pa (512), while the supply current rises from 23 µA to 784 µA (datasheet Tables 22, 24). init() default: 4 samples.

avg
Desired averaging.

tile_sense_bp_set_fullscale

Studio
void tile_sense_bp_set_fullscale(tile_t *tile, sense_bp_fs_t fs)

Mode 1 (up to 1260 hPa) has twice the resolution and about half the noise of mode 2 (up to 4060 hPa). init() default: mode 1.

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)

The filter on the pressure output (CTRL_REG2 EN_LPFP / LFPF_CFG) cuts the noise further at no current cost: at 25 Hz with 4-sample averaging, 4.26 Pa RMS unfiltered, 2.87 at ODR/4, 2.20 at ODR/9 (datasheet Table 24). init() default: on, at ODR/4.

enable
[0..1] 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), so it needs AUTOREFP or AUTOZERO. Enable PHE/PLE bits in INTERRUPT_CFG to generate interrupts. THS_P is 15 bits (hPa × 16 in mode 1, × 8 in mode 2); values past 2047 hPa (mode 1) / 4095 hPa (mode 2) saturate.

ths_hpa
[0..2047] hPa Threshold (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.

cfg
[0..255] 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).

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_sense_bp_reset_autozero

Studio
void tile_sense_bp_reset_autozero(tile_t *tile)

Reset autozero mode to normal operation.

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_sense_bp_reset_autorefp

Studio
void tile_sense_bp_reset_autorefp(tile_t *tile)

Reset autorefp mode to normal operation.

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.

offset
[-32768..32767] 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).

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.

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).

watermark
[0..127] Threshold level.

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.

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.

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.

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.

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_avg_t

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_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 @studio value=1
SENSE_BP_ODR_4HZ
4 Hz @studio value=4
SENSE_BP_ODR_10HZ
10 Hz @studio value=10
SENSE_BP_ODR_25HZ
25 Hz @studio value=25
SENSE_BP_ODR_50HZ
50 Hz @studio value=50
SENSE_BP_ODR_75HZ
75 Hz @studio value=75
SENSE_BP_ODR_100HZ
100 Hz @studio value=100
SENSE_BP_ODR_200HZ
200 Hz @studio value=200

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 @studio value=4
SENSE_BP_LPF_ODR_9
Bandwidth = ODR/9 @studio value=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_MINOR3
TILE_SENSE_BP_VERSION_PATCH0
ILPS22QS_I2C_ADDR_DEFAULT0x5DAD0 float/high (default)
ILPS22QS_I2C_ADDR_ALT0x5CAD0 to GND
ILPS22QS_WHO_AM_I_VALUE0xB4