BMP280 - Absolute barometric pressure

Description

Library for interfacing Bosch Sensortec BMP280 pressure sensor

The BMP280 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 (equiv. to +9000...-500 m above/below sea level) -) Temperature range : -40 to 85°C

OVERVIEW

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

Interfaces: 1x I2C

Key y parameters of the BMP280
  • I2C interface with communication speed up to 3.4 MHz
  • Two user selectable addresses (chosen by chip pin)
  • Pressure range: 300 to 1100hPa (equiv. to +9000...-500 m above/below sea level)
  • Temperature range : -40 to 85°C

  • For more information, see the Bosch Sensortec website
    BMP280_How_to_use:
    /* Hardware setup */ const { PORT_I2C = 0, // The first I2C interface should be used. CHIP_ADDR = BMP280_I2C_ADR0, // I2C Address of the chip // (depends on the logic level at the chip's SDO pin) } /* Handles for available sensors */ new hBMP[TBMP280_Handle]; // Handle to manage the BMP280 /* 1 sec. timer is used for the general program sequence */ #callback MainTimer() { new pres; // Pressure read from the BMP280 new temp; // Temperature read from the BMP280 catch(BMP280_Read(hBMP, pres, temp)); // reads the measured values ​​from the BMP280 // Issues pressure and temperature via the watch panel #watch("pres=%.2fhPa, temp=%.1f°C", pres/100.0, temp/100.0); } main(){ // Inits the I2C interface catch( rM2M_I2cInit( PORT_I2C, BMP280_CLOCK, 0)); // IInitializes i2c communication with the BMP280 and prepares the BMP280 for use catch(BMP280_I2C_Init(hBMP, PORT_I2C, BMP280_I2C_ADR0)); /* Activates the BMP280 -) 1x Oversampling (Temperature and Pressure) -) Periodic measurement -) Time between measurements: 250ms -) Filter is off */ catch (BMP280_Enable( hBMP, BMP280_OS_T_1X | BMP280_OS_P_1X | BMP280_NORMAL_MODE, BMP280_ODR_250_MS | BMP280_FILTER_OFF )); // Initialisation of a cyclic sec. timer setInterval(MainTimer, 1000); }

    BASIC

    BMP280_CLOCK -

    typical I2C clock speed to be used

    BMP280_I2C_ADRx:

    Available BMP280 I2C addresses

    BMP280_I2C_ADR0 - Must be used if SDO (Pin 5) of the BMP280 is connected to Ground
    BMP280_I2C_ADR1 - Must be used if SDO (pin 5) of the BMP280 is connected to the interface supply voltage (VDDIO, Pin 6)
    BMP280_POWER_MODE_x:

    Available Power Modes (BMP280_CTRL_MEAS_ADDR, Bit 0-1)

    BMP280_SLEEP_MODE - 0x00: Sleep mode is set by default after power on reset
  • No measurements are performed
  • Power consumption is at a minimum
  • BMP280_FORCED_MODE - 0x01: 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.
    BMP280_NORMAL_MODE - 0x03: Continuously cycles between an measurement period and an standby period, whose time is defined by BMP280_ODR_x.
    BMP280_OS_P_x:

    Oversampling configuration for pressure data (BMP280_CTRL_MEAS_ADDR, Bit 2-4)

    BMP280_OS_P_NONE - (0x00): Pressure measurement disabled (output set to 0x80000)
    Presure oversampling | Typ. pressure resolution | Recommended temperature oversampling
    BMP280_OS_P_1X - (0x01 << 2): x1 | 16 bit / 2.62 Pa | ×1
    BMP280_OS_P_2X - (0x02 << 2): x2 | 17 bit / 1.31 Pa | ×1
    BMP280_OS_P_4X - (0x03 << 2): x4 | 18 bit / 0.66 Pa | ×1
    BMP280_OS_P_8X - (0x04 << 2): x8 | 19 bit / 0.33 Pa | ×1
    BMP280_OS_P_16X - (0x05 << 2): x16 | 20 bit / 0.16 Pa | ×2
    BMP280_OS_T_x:

    Oversampling configuration for temperature data (BMP280_CTRL_MEAS_ADDR, Bit 5-7)

    BMP280_OS_T_NONE - (0x00): Temperature measurement disabled (output set to 0x80000)
    Temperature oversampling | Typ. temperature resolution
    BMP280_OS_T_1X - (0x01 << 5): x1 | 16 bit / 0.0050 °C
    BMP280_OS_T_2X - (0x02 << 5): x2 | 17 bit / 0.0025 °C
    BMP280_OS_T_4X - (0x03 << 5): x4 | 18 bit / 0.0012 °C
    BMP280_OS_T_8X - (0x04 << 5): x8 | 19 bit / 0.0006 °C
    BMP280_OS_T_16X - (0x05 << 5): x16 | 20 bit / 0.0003 °C
    BMP280_ODR_x:

    Standby time (i.e. inactive time) in normal mode (BMP280_CONFIG_ADDR, Bit 5-7)

    BMP280_ODR_0_5_MS - (0x00): 0.5ms
    BMP280_ODR_62_5_MS - (0x01 << 5): 62.5ms
    BMP280_ODR_125_MS - (0x02 << 5): 125ms
    BMP280_ODR_250_MS - (0x03 << 5): 250ms
    BMP280_ODR_500_MS - (0x04 << 5): 500ms
    BMP280_ODR_1000_MS - (0x05 << 5): 1000ms
    BMP280_ODR_2000_MS - (0x06 << 5): 2000ms
    BMP280_ODR_4000_MS - (0x07 << 5): 4000ms
    BMP280_FILTER_x:

    Filter coefficient options (BMP280_CONFIG_ADDR, Bit 2-4)

    BMP280_FILTER_OFF - 0x00 1 Sample to reach >= 75% of step response
    BMP280_FILTER_COEFF_2 - (0x01 << 2) 2 Samples to reach >= 75% of step response
    BMP280_FILTER_COEFF_4 - (0x02 << 2) 5 Samples to reach >= 75% of step response
    BMP280_FILTER_COEFF_8 - (0x03 << 2) 11 Samples to reach >= 75% of step response
    BMP280_FILTER_COEFF_16 - (0x04 << 2) 22 Samples to reach >= 75% of step response
    BMP280_I2C_Init(handle[TBMP280_Handle], i2c, addr)

    Initializes i2c communication with the BMP280 and prepares the BMP280 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 BMP280.

    handle : TBMP280_Handle - Empty device handle for a BMP280
    i2c : s32 - I2C interface where BMP280 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 BMP280_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
  • BMP280_Enable(handle[TBMP280_Handle], ctrl_meas, config)

    Activates the BMP280 by setting the "ctrl_meas" register and the "config" register


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

    handle : TBMP280_Handle - Device handle of a specific BMP280 (Initialized by BMP280_I2C_Init() )
    ctrl_meas : s32 - Data acquisition configuration ( Oversampling Temperatur / Oversampling pressure / Power Mode)
    Use BMP280_OS_T_x | BMP280_OS_P_x | BMP280_POWER_MODE_x
    config - Rate and Filter configuration (Standby time / Filter coefficient)
    Use BMP280_ODR_x | BMP280_FILTER_x
    returns : s32
    OK - If successful
    ERROR - If an error occurs
    BMP280_Read(handle[TBMP280_Handle], &pres, &temp)

    reads the measured values ​​from the BMP280.

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

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

    handle : TBMP280_Handle - Device handle of a specific BMP280 (Initialized by BMP280_I2C_Init() )
    returns : s32
    OK - If successful
    ERROR - If an error occurs

    EXPERT

    BMP280_CLOCK_MAX -

    absolute maximum I2C clock speed

    BMP280_REG_ADDR:

    BMP280 Register Addresses (Address | Default | Description)

    BMP280_CHIP_ID_ADDR - 0xD0 | 0x58 | Chip identification number
    BMP280_SOFT_RESET_ADDR - 0xE0 | 0x00 | Performs a soft reset (use BMP280_SoftReset() )
    BMP280_STATUS_ADDR - 0xF3 | 0x00 | Status of the device (see BMP280_STATUS_x)
    BMP280_CTRL_MEAS_ADDR - 0xF4 | 0x00 | Data acquisition options of the device (use BMP280_Enable())
    BMP280_CONFIG_ADDR - 0xF5 | 0x00 | Rate, filter and interface options of the device (use BMP280_Enable())
    BMP280_PRES_MSB_ADDR - 0xF7 | 0x80 | Raw pressure Bit 19-12 (use BMP280_Read())
    BMP280_PRES_LSB_ADDR - 0xF8 | 0x00 | Raw pressure Bit 11-4
    BMP280_PRES_XLSB_ADDR - 0xF9 | 0x00 | Raw pressure Bit 3-0
    BMP280_TEMP_MSB_ADDR - 0xFA| 0x80 | Raw temperature Bit 19-12 (use BMP280_Read())
    BMP280_TEMP_LSB_ADDR - 0xFB | 0x00 | Raw temperature Bit 11-4
    BMP280_TEMP_XLSB_ADDR - 0xFC | 0x00 | Raw temperature Bit 3-0
    Many more registers available. See datasheet for more information.
    BMP280_STATUS_x:

    Flags contained in the status register

    BMP280_STATUS_MEAS - bit 3: Status of the measurement
    0 - results have been transferred to the data registers
    1 - conversion is running
    BMP280_STATUS_IM_UPDATE - bit 0: Status of the NVM data copying process
    0 - copying is done
    1 - NVM data are being copied to image registers
    BMP280_SoftReset(handle[TBMP280_Handle])

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

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

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

    handle : TBMP280_Handle - Device handle of a specific BMP280 (Initialized by BMP280_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

    BMP280_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 BMP280_DEBUG 0

    On this page

    BMP280 - Absolute barometric pressure