BMP388 - Absolute barometric pressure

Description

Library for interfacing Bosch Sensortec BMP388 pressure sensor

The BMP388 is an absolute barometric pressure sensor especially designed for mobile applications. -) I2C interface with communication speed up to 3.4 MHz -) Two user selectable addresses (chosen by chip pin) -) Pressure range: 300 to 1100hPa -) Temperature range : -40 to 85°C

OVERVIEW

BMP388_Abstract:
This library can be used to handle Bosch Sensortec BMP388 type absolute barometric pressure sensors.

Interfaces: 1x I2C

Key features of the BMP388
  • I2C interface with communication speed up to 3.4 MHz
  • Two user selectable addresses (chosen by chip pin)
  • Pressure range: 300 to 1100hPa
  • Temperature range: -40 to 85°C

  • For more information, see the Bosch Sensortec website
    BMP388_How_to_use:
    /* Hardware setup */ const { PORT_I2C = 0, // The first I2C interface should be used. CHIP_ADDR = BMP388_I2C_ADR0, // I2C Address of the chip // (depends on the logic level at the chip's SDO pin) } /* Handles for available sensors */ new hBMP[TBMP388_Handle]; // Handle to manage the BMP388 /* 1 sec. timer is used for the general program sequence */ #callback MainTimer() { new pres; // Pressure read from the BMP388 new temp; // Temperature read from the BMP388 catch(BMP388_Read(hBMP, pres, temp)); // Reads the measured values ​​from the BMP388 // Issues Pressure and Temperature via the watch panel #watch("pressure=%shPa, temperature=%s°C", s32ToStr(pres, 2), s32ToStr(temp, 2)); } main() { // Inits the I2C interface catch(rM2M_I2cInit(PORT_I2C, BMP388_CLOCK, 0)); // Initializes I2C communication with the BMP388 and prepares the BMP388 for use catch(BMP388_I2C_Init(hBMP, PORT_I2C, CHIP_ADDR)); /* Activates the BMP388 -) 1x Oversampling (Temperature and Pressure) -) Time between measurements: 320ms -) Periodic measurement of Temperature and Pressure -) Filter is off */ new iResult = BMP388_Enable( hBMP, BMP388_OSR_TEMP_1X | BMP388_OSR_PRESS_1X, BMP388_ODR_320_MS, BMP388_PWR_CTRL_MODE_NORMAL | BMP388_PWR_CTRL_TEMP_EN | BMP388_PWR_CTRL_PRESS_EN, BMP388_CONFIG_FILTER_OFF ); if (iResult == OK) { // Initialisation of a cyclic sec. timer setInterval(MainTimer, 1000); } else { #log("Error occured while initialising BMP388"); } }

    BASIC

    BMP388_CLOCK -

    typical I2C clock speed to be used

    BMP388_I2C_ADRx:

    Available BMP388 I2C addresses

    BMP388_I2C_ADR0 - Must be used if SDO (Pin 5) of the BMP388 is connected to ground
    BMP388_I2C_ADR1 - Must be used if SDO (Pin 5) of the BMP388 is connected to the interface supply voltage (VDDIO, Pin 1)
    BMP388_OSR_PRESS_x:

    Oversampling configuration for pressure measurement (BMP388_OSR_ADDR, Bit 0-2)

    BMP388_OSR_PRESS_1X - 0x00: no oversampling
    BMP388_OSR_PRESS_2X - 0x01: x2 oversampling
    BMP388_OSR_PRESS_4X - 0x02: x4 oversampling (default)
    BMP388_OSR_PRESS_8X - 0x03: x8 oversampling
    BMP388_OSR_PRESS_16X - 0x04: x16 oversampling
    BMP388_OSR_PRESS_32X - 0x05: x32 oversampling
    BMP388_OSR_PRESS_MASK - 0x07: Mask for pressure oversampling
    BMP388_OSR_TEMP_x:

    Oversampling configuration for temperature measurement (BMP388_OSR_ADDR, Bit 3-5)

    BMP388_OSR_TEMP_1X - (0x00 << 3): no oversampling (default)
    BMP388_OSR_TEMP_2X - (0x01 << 3): x2 oversampling
    BMP388_OSR_TEMP_4X - (0x02 << 3): x4 oversampling
    BMP388_OSR_TEMP_8X - (0x03 << 3): x8 oversampling
    BMP388_OSR_TEMP_16X - (0x04 << 3): x16 oversampling
    BMP388_OSR_TEMP_32X - (0x05 << 3): x32 oversampling
    BMP388_OSR_TEMP_MASK - (0x07 << 3): Mask for temperature oversampling
    BMP388_ODR_x:

    Standby time configuration (BMP388_ODR_ADDR, Bit 0-4)

    Sampling Period | Output Data Rates
    BMP388_ODR_5_MS - 0x00: 5ms | ODR 200Hz (default)
    BMP388_ODR_10_MS - 0x01: 10ms | ODR 100Hz
    BMP388_ODR_20_MS - 0x02: 20ms | ODR 50Hz
    BMP388_ODR_40_MS - 0x03: 40ms | ODR 25Hz
    BMP388_ODR_80_MS - 0x04: 80ms | ODR 25/2Hz
    BMP388_ODR_160_MS - 0x05: 160ms | ODR 25/4Hz
    BMP388_ODR_320_MS - 0x06: 320ms | ODR 25/8Hz
    BMP388_ODR_640_MS - 0x07: 640ms | ODR 25/16Hz
    BMP388_ODR_1_28_S - 0x08: 1.28s | ODR 25/32Hz
    BMP388_ODR_2_56_S - 0x09: 2.56s | ODR 25/64Hz
    BMP388_ODR_5_12_S - 0x0A: 5.12s | ODR 25/128Hz
    BMP388_ODR_10_24_S - 0x0B: 10.24s | ODR 25/256Hz
    BMP388_ODR_20_48_S - 0x0C: 20.48s | ODR 25/512Hz
    BMP388_ODR_40_96_S - 0x0D: 40.96s | ODR 25/1024Hz
    BMP388_ODR_81_92_S - 0x0E: 81.92s | ODR 25/2048Hz
    BMP388_ODR_163_84_S - 0x0F: 163.84s | ODR 25/4096Hz
    BMP388_ODR_327_68_S - 0x10: 327.68s | ODR 25/8192Hz
    BMP388_ODR_655_36_S - 0x11: 655.36s | ODR 25/16384Hz
    BMP388_ODR_MASK - 0x1F: Mask for output data rate configuration
    BMP388_PWR_CTRL_x:

    Available Power Control Modes (BMP388_PWR_CTRL_ADDR, Bit 0-1, 4-5)

    BMP388_PWR_CTRL_PRESS_EN - 0x01: Enables the pressure sensor.
    BMP388_PWR_CTRL_TEMP_EN - 0x02: Enables the temperature sensor.
    BMP388_PWR_CTRL_MODE_SLEEP - (0x00 << 4): Sleep mode is set by default after power on reset
  • No measurements are performed
  • Power consumption is at a minimum
  • BMP388_PWR_CTRL_MODE_FORCED - (0x01 << 4): A single measurement is performed according to selected measurement and filter options.After that the sensor returns to sleep mode and the measurement results can be obtained from the data registers.
    BMP388_PWR_CTRL_MODE_NORMAL - (0x03 << 4): Continuously cycles between an measurement period and an standby period, whose time is defined by BMP388_ODR_x.
    BMP388_PWR_CTRL_MODE_MASK - (0x03 << 4): Mask for power control mode
    BMP388_CONFIG_FILTER_x:

    Filter coefficient for IIR filter (BMP388_CONFIG_ADDR, Bit 1-3)

    BMP388_CONFIG_FILTER_OFF - (0x00 << 1): Filter coefficient is 0 -> bypass-mode (default)
    BMP388_CONFIG_FILTER_COEFF_1 - (0x01 << 1): Filter coefficient is 1
    BMP388_CONFIG_FILTER_COEFF_3 - (0x02 << 1): Filter coefficient is 3
    BMP388_CONFIG_FILTER_COEFF_7 - (0x03 << 1): Filter coefficient is 7
    BMP388_CONFIG_FILTER_COEFF_15 - (0x04 << 1): Filter coefficient is 15
    BMP388_CONFIG_FILTER_COEFF_31 - (0x05 << 1): Filter coefficient is 31
    BMP388_CONFIG_FILTER_COEFF_63 - (0x06 << 1): Filter coefficient is 63
    BMP388_CONFIG_FILTER_COEFF_127 - (0x07 << 1): Filter coefficient is 127
    BMP388_CONFIG_FILTER_MASK - (0x07 << 1): Mask for filter coefficient
    BMP388_I2C_Init(handle[TBMP388_Handle], i2c, addr)

    Initializes i2c communication with the BMP388 and prepares the BMP388 for use


    First reads the chip ID and checks if a chip supported by the library has been found. Afterwards, the calibration parameters are read out and stored in the transferred, empty device handle for a BMP388.

    handle : TBMP388_Handle - Empty device handle for a BMP388
    i2c : s32 - I2C interface where BMP388 is connected to
    The I2C interface must be initialisation before using rM2M_I2cInit().
    addr : s32 - I2C Address of the chip (depends on the logic level at the chip's SDO pin)
    Use only the addresses specified under BMP388_I2C_ADRx
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Chip ID could not be read
  • Found chip not supported by the library
  • Calibration parameters could not be read
  • BMP388_Enable(handle[TBMP388_Handle], osr, odr, pwr_ctrl, config)

    Activates the BMP388 by setting the "osr" , "odr", "pwr_ctrl" and "config" register


    Before activating, the BMP388 is set into sleep mode to establish a defined operating state

    handle : TBMP388_Handle - Device handle of a specific BMP388 (Initialized by BMP388_I2C_Init() )
    osr : s32 - Oversampling configuration (Oversampling Pressure / Oversampling Temperature)
    Use BMP388_OSR_PRESS_x | BMP388_OSR_TEMP_x
    odr : s32 - Output data rates configuration
    Use BMP388_ODR_x
    pwr_ctrl : s32 - Power mode and measurement control options (Power Mode / pressure measurement enable / temperature measurement enable)
    Use BMP388_PWR_CTRL_x
    config - Filter configuration (IIR Filter coefficient)
    Use BMP388_CONFIG_FILTER_x
    returns : s32
    OK - If successful
    ERROR - If an error occurs
    BMP388_Read(handle[TBMP388_Handle], &pres, &temp)

    reads the measured values ​​from the BMP388.

    handle : TBMP388_Handle - Device handle of a specific BMP388 (Initialized by BMP388_I2C_Init() )
    pres : s32 - [Pa] Buffer for storing the compensated pressure value
    temp : s32 - [0.01°C] Buffer for storing the compensated temperature value
    returns : s32
    OK - If successful
    ERROR - If an error occurs
    BMP388_Disable(handle[TBMP388_Handle])

    Sets the BMP388 into sleep mode (i.e. no measurements are performed) and thus grants minimum power consumption

    handle : TBMP388_Handle - Device handle of a specific BMP388 (Initialized by BMP388_I2C_Init() )
    returns : s32
    OK - If successful
    ERROR - If an error occurs

    EXPERT

    BMP388_CLOCK_MAX -

    absolute maximum I2C clock speed

    BMP388_REG_ADDR:

    BMP388 Register Addresses (Address | Default | Description)

    BMP388_CHIP_ID_ADDR - 0x00 | 0x50 | Chip identification number
    BMP388_ERR_REG_ADDR - 0x02 | 0x00 | Error Register (see BMP388_ERR_x)
    BMP388_STATUS_ADDR - 0x03 | 0x00 | Status Register (see BMP388_STATUS_x)
    BMP388_PRESS_DATA_0_ADDR - 0x04 | 0x00 | Pressure data, Bit 0-7 (use BMP388_Read())
    BMP388_PRESS_DATA_1_ADDR - 0x05 | 0x00 | Pressure data, Bit 8-15
    BMP388_PRESS_DATA_2_ADDR - 0x06 | 0x80 | Pressure data, Bit 16-23
    BMP388_TEMP_DATA_3_ADDR - 0x07 | 0x00 | Temperature data, Bit 0-7 (use BMP388_Read())
    BMP388_TEMP_DATA_4_ADDR - 0x08 | 0x00 | Temperature data, Bit 8-15
    BMP388_TEMP_DATA_5_ADDR - 0x09 | 0x80 | Temperature data, Bit 16-23
    BMP388_SENSORTIME_0_ADDR - 0x0C | 0x00 | Sensor time, Bit 0-7
    BMP388_SENSORTIME_1_ADDR - 0x0D | 0x00 | Sensor time, Bit 8-15
    BMP388_SENSORTIME_2_ADDR - 0x0E | 0x00 | Sensor time, Bit 16-23
    BMP388_EVENT_ADDR - 0x10 | 0x01 | Contains the sensor status flags (see BMP388_EVENT_x)
    BMP388_INT_STATUS_ADDR - 0x11 | 0x00 | Shows the interrupt status and is cleared after reading (see BMP388_INT_STATUS_x)
    BMP388_FIFO_LENGTH_0_ADDR - 0x12 | 0x00 | FIFO length, Bit 0-7
    BMP388_FIFO_LENGTH_1_ADDR - 0x13 | 0x00 | FIFO length, Bit 8
    BMP388_FIFO_DATA_ADDR - 0x14 | 0x00 | FIFO data output register
    BMP388_FIFO_WTM_0_ADDR - 0x15 | 0x01 | FIFO Watermark, Bit 0-7
    BMP388_FIFO_WTM_1_ADDR - 0x16 | 0x00 | FIFO Watermark, Bit 8
    BMP388_FIFO_CONFIG_1_ADDR - 0x17 | 0x02 | FIFO frame content configuration (see BMP388_FIFO_CFG1_x)
    BMP388_FIFO_CONFIG_2_ADDR - 0x18 | 0x02 | Extends the FIFO_CFG1 register
    BMP388_INT_CTRL_ADDR - 0x19 | 0x02 | Interrupt Control configuration (see BMP388_INT_CTRL_x)
    BMP388_IF_CONF_ADDR - 0x1A | 0x00 | Serial interface settings (see BMP388_IF_CONF_x)
    BMP388_PWR_CTRL_ADDR - 0x1B | 0x00 | Power mode and measurement control options (use BMP388_Enable())
    BMP388_OSR_ADDR - 0x1C | 0x02 | Oversampling configuration for temperature and pressure measurement (use BMP388_Enable())
    BMP388_ODR_ADDR - 0x1D | 0x00 | Output Data Rate (ODR) Configuration register (use BMP388_Enable())
    BMP388_CONFIG_ADDR - 0x1F | 0x00 | Filter Configuration Register (use BMP388_Enable())
    BMP388_CMD_ADDR - 0x7E | 0x00 | Command register (see BMP388_CMD_x)
    BMP388_ERR_x:

    Error Register values (BMP388_ERR_REG_ADDR, Bit 0-2)

    BMP388_ERR_FATAL - 0x01: Fatal error
    BMP388_ERR_CMD - 0x02: Command execution failed. Cleared on read.
    BMP388_ERR_CONF - 0x04: Sensor configuration error detected. Cleared on read.
    BMP388_STATUS_x:

    Status Register values (BMP388_STATUS_ADDR, Bit 4-6)

    BMP388_STATUS_CMD_READY - bit 4: CMD decoder status
    0 - Command in progress
    1 - Command decoder is ready to accept a new command
    BMP388_STATUS_DATA_READY_PRESS - bit 5: Data ready for pressure
    It gets reset, when one pressure DATA register is read out
    BMP388_STATUS_DATA_READY_TEMP - bit 6: Data ready for temperature
    It gets reset, when one temperature DATA register is read out
    BMP388_EVENT_x:

    Event Register values (BMP388_EVENT_ADDR, Bit 0)

    BMP388_EVENT_POR_DETECTED - 0x01: '1' after device power up or soft reset. Cleared on read.
    BMP388_INT_STATUS_x:

    Interrupt Status Register values (BMP388_INT_STATUS_ADDR, Bit 0-1, 3)

    BMP388_INT_STATUS_FIFO_WTM_INT - 0x01: FIFO Watermark Interrupt
    BMP388_INT_STATUS_FIFO_FULL_INT - 0x02: FIFO full Interrupt
    BMP388_INT_STATUS_DATA_RDY_INT - 0x08: Data ready Interrupt
    BMP388_FIFO_CFG1_x:

    FIFO Config 1 Register options (BMP388_FIFO_CONFIG_1_ADDR, Bit 0-4)

    BMP388_FIFO_CFG1_MODE_EN - bit 0: Enables or disables the FIFO
    0 - disable (default)
    1 - enable FIFO mode
    BMP388_FIFO_CFG1_STOP_ON_FULL - bit 1: Stop writing smaples into FIFO when FIFO is full
    0 - disable do not stop writing to FIFO when full
    1 - enable Stop writing into FIFO when full (default)
    BMP388_FIFO_CFG1_TIME_EN - bit 2: Return sensortime frame after the last valid data frame
    0 - disable do not return sensortime frame (default)
    1 - enable return sensortime frame
    BMP388_FIFO_CFG1_PRESS_EN - bit 3: Store pressure data in FIFO
    0 - disable no pressure data is stored (default)
    1 - enable pressure data is stored
    BMP388_FIFO_CFG1_TEMP_EN - bit 4: Store temperature data in FIFO
    0 - disable no temperature data is stored (default)
    1 - enable temperature data is stored
    BMP388_FIFO_CFG2_x:

    FIFO Config 2 Register options (BMP388_FIFO_CONFIG_2_ADDR, Bit 0-4)


    FIFO downsampling selection for pressure and temperature data
    BMP388_FIFO_CFG2_SUBSAMPL_0 - 0x00: No downsampling
    BMP388_FIFO_CFG2_SUBSAMPL_2 - 0x01: Downsampling factor 2 (default)
    BMP388_FIFO_CFG2_SUBSAMPL_4 - 0x02: Downsampling factor 4
    BMP388_FIFO_CFG2_SUBSAMPL_8 - 0x03: Downsampling factor 8
    BMP388_FIFO_CFG2_SUBSAMPL_MASK - 0x03: Mask for FIFO downsampling selection

    Select data source for pressure and temperature (compensated or uncompensated)
    BMP388_FIFO_CFG2_DSEL_UNFILT - (0x00 << 3): Unfiltered data (default)
    BMP388_FIFO_CFG2_DSEL_FILT - (0x01 << 3): Filtered data
    BMP388_FIFO_CFG2_DSEL_MASK - (0x03 << 3): Mask for data source selection
    BMP388_INT_CTRL_x:

    Interrupt Control Configuration Register options (BMP388_INT_CTRL_ADDR, Bit 0-4, 6)

    BMP388_INT_CTRL_OPEN_DRAIN - bit 0: Configure output: opend-rain or push-pull
    0 - push-pull (default)
    1 - open-drain
    BMP388_INT_CTRL_LEVEL_HIGH - bit 1: Level of INT pin
    0 - active low
    1 - active high (default)
    BMP388_INT_CTRL_LATCH_EN - bit 2: Latching of interrupts for INT pin and BMP388_INT_STATUS_ADDR register
    0 - disabled (default)
    1 - enabled
    BMP388_INT_CTRL_FIFO_WTM_EN - bit 3: Enable FIFO watermark reached interrupt for INT pin and BMP388_INT_STATUS_ADDR register
    0 - disabled (default)
    1 - enabled
    BMP388_INT_CTRL_FIFO_FULL_EN - bit 4: Enable FIFO full interrupt for INT pin and BMP388_INT_STATUS_ADDR register
    0 - disabled (default)
    1 - enabled
    BMP388_INT_CTRL_DATA_RDY_EN - bit 6: Enable temperature / pressure data ready interrupt for INT pin and BMP388_INT_STATUS_ADDR register
    0 - disabled (default)
    1 - enabled
    BMP388_IF_CONF_x:

    Serial Interface Settings Register options (BMP388_IF_CONF_ADDR, Bit 0-2)

    BMP388_IF_CONF_SPI3 - bit 0: Configure SPI Interface Mode for primary interface
    0 - SPI 4-wire mode (default)
    1 - SPI 3-wire mode
    BMP388_IF_CONF_I2C_WDT_EN - bit 1: Enable for the I2C Watchdog timer, backed by NVM
    0 - Watchdog disabled (default)
    1 - Watchdog enabled
    BMP388_IF_CONF_I2C_WDT_LONG - bit 2: Select timer period for I2C Watchdog, backed by NVM
    0 - I2C Watchdog timeout after 1.25ms (default)
    1 - I2C Watchdog timeout after 40ms
    BMP388_CMD_x:

    Available Commands for Command Register (BMP388_CMD_ADDR, Bit 0-7)

    BMP388_CMD_NOP - 0x00: Reserved. No command.
    BMP388_CMD_FIFO_FLUSH - 0xB0: Clears all data in the FIFO, does not change FIFO_CONFIG registers
    BMP388_CMD_SOFTRESET - 0xB6: Triggers a reset, all user configuration settings are overwritten with their default state
    BMP388_SoftReset(handle[TBMP388_Handle])

    Resets the BMP388 using the complete power-on-reset procedure

    The Startup time is 2ms -> must be managed within application
    handle : TBMP388_Handle - Device handle of a specific BMP388 (Initialized by BMP388_I2C_Init() )
    returns : s32
    OK - If successful
    ERROR - If an error occurs
    BMP388_Com(handle[TBMP388_Handle], aData{}, writeLen, readLen)

    Executes an I2C communication with the BMP388. Data is first of all sent and data is then received.

    handle : TBMP388_Handle - Device handle of a specific BMP388 (Initialized by BMP388_I2C_Init() )
    aData : {} - Array in which the data to be sent must initially be saved. Once the data has been sent, the array is used as a memory for the data to be received.
    writeLen : s32 - Number of bytes to be sent
    readLen : s32 - Number of bytes to be received
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Number of bytes to be sent >255
  • Number of bytes to be received >255
  • Another error occurs
  • DEBUG

    BMP388_Debug_Config:
    To configure debug mode add the following macro to the main.dde file.
    /** * Use this macro to configure the debug mode: * * 0: No debugging * >0: The raw values ​​and the compensated values ​​for pressure and temperature * are issued via the console each time BMP_Read() is called */ #define BMP388_DEBUG 0

    On this page

    BMP388 - Absolute barometric pressure