Library 37- BMP180 pressure sensor for STM32F4

BMP180 is a digital pressure sensor, with builtin temperature sensor. Its range is between 300 and 1100 hPa (0.3 to 1.1Bar). In relating to the sea level, this is +9000 to -500 meters.

Sensor works with I2C communication at 100kHz.

If you want sensor from ebay, here is one link.

Sensor is quite bad created, because if you want to read pressure, you first need to read current temperature for pressure calculation. To read temperature you have to wait at least 4.5ms. After that, you first have to read temperature and then you can start with pressure measurement. Time for pressure measurement depends on mode you select. After pressure is measured, you can read uncompensated data from device. This is because device has one register for control temperature and pressure, and also one register for data. So both, temperature and  pressure can not be measured at same time.

This takes about at least 10ms for every stuff to be done. At the end a lot of calculations are needed to get valid pressure from device.

Because veeery long time for STM32F4, I split things into several functions, to start temp, read temp, start pressure, read pressure, etc.

I have also added possibility, that you calculate pressure right above the sea from known pressure at known altitude.

Sequency for reading useful data is:

  • Start temperature measurement
    • Wait 4.5ms at least
  • Read temperature
  • Start pressure measurement
    • Delay depends on measurement mode you select
  • Read pressure
  • Use pressure data

Library

Features

  • Read BMP180 temperature sensor
  • Read BMP180 pressure sensor
  • Calculate sea level pressure at from given know pressure and altitude
    • If you are at ex 1000meters and there si pressure 98000Pascals, then you can calculate pressure at sea level from this values

Dependencies

  • CMSIS
    • STM32F4xx
    • STM32F4xx RCC
    • STM32F4xx GPIO
    • STM32F4xx I2C
  • TM
    • TM I2C
    • defines.h
BMP180 STM32F4 Description
SCL PA8 I2C3 Serial clock
SDA PC9 I2C3 Serial data

You can change I2C settings. Open defines.h file, copy lines below and edit them.

Like I said on beginning, different modes for reading pressure can be used. Modes differ in number of samples, conversion time and noise. You select your mode each time you start pressure measurement. For temperature, there is no possible to select mode.

Mode Internal number of samples Conversion time [us] RMS noise [Pascals] RMS noise [meters]
Ultra Low Power 1 4500 6 0.5
Standard 2 7500 5 0.4
High Resolution 4 13500 4 0.3
Ultra High Resolution 8 25500 3 0.25

Functions and enumerations

Example

Example below takes measurements from device and sends data to USART1, TX pin on PB6 at 115200 bauds. You should get result something like on image below.

BMP180 pressure sensor USART result

BMP180 pressure sensor USART result



Project is available at my Github account.

tilz0R

Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...