BMP085 Pressure Sensor Driver

I used Adafruit's version of the BMP185.

A Bosch BMP085 from Adafruit.


In December 2015, I wrote a low level C driver for the BMP085 Bosch Pressure sensor for use with the ARM STM32-F4 Discovery Board. The BMP085 is a temperature and pressure sensor which can be used for a variety projects such as IoT weather logging applications or even quad-copter drones and the like. There are quite a few BMP085 driver implementations out there which use polling in order to read data from it, however not many which utilize the EOC pin in conjunction with a hardware interrupt for faster data acquisition. This Driver will give you temperature, pressure, and altitude readings at roughly 39 Hz using a hardware interrupt. Not bad!

The state diagram for reading this sensor is as follows:

As you can see, reading the EOC pin in a timely way is pretty critical to maximizing the sensor update frequency. In my driver, I use pin PD0 for this purpose. Once a temperature or pressure reading is requested, the BMP085 will bring the EOC line low. Once the data is ready, the BMP085 will signal the microcontroller by bringing the EOC pin high. I set an external interrupt on pin PD0 set to be triggered on a rising edge, signaling it is now OK to read the data and increment the state machine.

On the scope, the behavior of the EOC line following a temperature request looks like this:
This sensor has a selection of oversampling modes to choose from. The more samples performed, the more accurate the sensor data, but this will increase the time it takes for a conversion to be ready (EOC high) and limit the number of readings you can perform per second.

The output of the driver should give you the following basic readings

The altitude reading is relative Altitude using a reference pressure at sea level. In theory, if you take a reading while on the ground, and then move the sensor some height above where it was and take the difference, you should be able to get a usable absolute altitude for a drone, plane, etc. This functionality was not the focus of this project and may require further adjustment (ie if the reference pressure at sea level is not exact for your area, that may require a different constant in the altitude calculation in the code). You can check the Bosch datasheet in the link down below for more info on this calculation. I converted to feet in the above display simply for general testing but there is no reason you can’t convert back to meters.

Basic Usage
See main.c for example usage. Extended documentation can be generated using the included Doxyfile with Doxygen.

-STM Standard Peripheral Library



BMP085 Pressure Sensor | (.pdf)

Source Code
Link | (Github)

Bookmark the permalink.

Leave a Reply