Envorimental Monitoring
Loading...
Searching...
No Matches
bmp180.h File Reference

Driver interface for the BMP180 barometric pressure and temperature sensor. More...

#include "stdint.h"
#include "stddef.h"

Go to the source code of this file.

Data Structures

struct  BMP180_CalibrationData_t
 BMP180 factory calibration coefficients. More...
struct  BMP180_HandleTypeDef
 BMP180 driver handle. More...
union  BMP180_CtrlMeas_t
 Bit-field overlay for the BMP180 ctrl_meas register (0xF4). More...

Macros

#define BMP180_CALIB_DATA_SIZE   22
#define BMP180_ADDRESS   0xEE
#define BMP180_REG_CALIB_DATA_START   0xAA
#define BMP180_REG_CALIB_DATA_END   0xBF
#define BMP180_REG_OUT_XLSB   0xF8
#define BMP180_REG_OUT_LSB   0xF7
#define BMP180_REG_OUT_MSB   0xF6
#define BMP180_REG_CTRL_MEAS   0xF4
#define BMP180_REG_SOFT_RST   0xE0
#define BMP180_REG_CHIP_ID   0xD0
#define BMP180_MEASURE_TEMP   0x0E
#define BMP180_MEASURE_PRESSURE   0x14

Typedefs

typedef int8_t(* BMP180_I2C_Read_Func) (uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len)
 Function pointer type for platform I2C read.
typedef int8_t(* BMP180_I2C_Write_Func) (uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len)
 Function pointer type for platform I2C write.
typedef void(* BMP180_Delay_Func) (uint32_t ms)
 Function pointer type for platform millisecond delay.

Functions

int8_t BMP180_Init (BMP180_HandleTypeDef *dev)
 Initialises the BMP180 sensor and reads calibration data.
int8_t BMP180_Read (BMP180_HandleTypeDef *dev)
 Reads both temperature and pressure from the BMP180.
int8_t BMP180_Read_Temperature (BMP180_HandleTypeDef *dev)
 Reads only the temperature from the BMP180.
int8_t BMP180_get_ut (BMP180_HandleTypeDef *dev, int32_t *ut_result)
 Triggers and reads the raw (uncompensated) temperature ADC value.
int8_t BMP180_get_up (BMP180_HandleTypeDef *dev, int32_t *up_result)
 Triggers and reads the raw (uncompensated) pressure ADC value.
void BMP180_calc_temperature (BMP180_HandleTypeDef *dev, int32_t ut)
 Converts a raw temperature ADC value to degrees Celsius.
void BMP180_calc_pressure (BMP180_HandleTypeDef *dev, int32_t up)
 Converts a raw pressure ADC value to Pascals.

Detailed Description

Driver interface for the BMP180 barometric pressure and temperature sensor.

The BMP180 uses a fixed I2C address of 0x77 and requires a one-time read of 11 factory calibration coefficients stored in non-volatile memory. These coefficients are used in a multi-step integer compensation algorithm specified by Bosch to convert raw ADC values into temperature (°C) and pressure (Pa).

The oversampling setting (oss) controls the trade-off between conversion time and noise: 0 = ultra-low power, 3 = ultra-high resolution.

Platform independence is achieved through injected I2C and delay function pointers, identical in style to the AHT20 and BH1750 drivers.

Author
Şule Nur Demirdaş
Date
April 2026

Macro Definition Documentation

◆ BMP180_ADDRESS

#define BMP180_ADDRESS   0xEE

8-bit I2C address (0x77 << 1).

◆ BMP180_CALIB_DATA_SIZE

#define BMP180_CALIB_DATA_SIZE   22

Size of the calibration data block in bytes.

◆ BMP180_MEASURE_PRESSURE

#define BMP180_MEASURE_PRESSURE   0x14

ctrl_meas value to start a pressure read.

◆ BMP180_MEASURE_TEMP

#define BMP180_MEASURE_TEMP   0x0E

ctrl_meas value to start a temperature read.

◆ BMP180_REG_CALIB_DATA_END

#define BMP180_REG_CALIB_DATA_END   0xBF

Last calibration register address.

◆ BMP180_REG_CALIB_DATA_START

#define BMP180_REG_CALIB_DATA_START   0xAA

First calibration register address.

◆ BMP180_REG_CHIP_ID

#define BMP180_REG_CHIP_ID   0xD0

Chip ID register (expected value: 0x55).

◆ BMP180_REG_CTRL_MEAS

#define BMP180_REG_CTRL_MEAS   0xF4

Control/measurement register.

◆ BMP180_REG_OUT_LSB

#define BMP180_REG_OUT_LSB   0xF7

ADC output LSB register.

◆ BMP180_REG_OUT_MSB

#define BMP180_REG_OUT_MSB   0xF6

ADC output MSB register.

◆ BMP180_REG_OUT_XLSB

#define BMP180_REG_OUT_XLSB   0xF8

ADC output XLSB register.

◆ BMP180_REG_SOFT_RST

#define BMP180_REG_SOFT_RST   0xE0

Soft-reset register.

Function Documentation

◆ BMP180_calc_pressure()

void BMP180_calc_pressure ( BMP180_HandleTypeDef * dev,
int32_t up )

Converts a raw pressure ADC value to Pascals.

Implements the full Bosch pressure compensation algorithm. BMP180_calc_temperature() must be called first to populate dev->b5.

Parameters
[in,out]devPointer to an initialised BMP180_HandleTypeDef.
[in]upRaw uncompensated pressure value from BMP180_get_up().

◆ BMP180_calc_temperature()

void BMP180_calc_temperature ( BMP180_HandleTypeDef * dev,
int32_t ut )

Converts a raw temperature ADC value to degrees Celsius.

Uses the Bosch compensation algorithm. Also computes and stores dev->b5 which is required by BMP180_calc_pressure().

Parameters
[in,out]devPointer to an initialised BMP180_HandleTypeDef.
[in]utRaw uncompensated temperature value from BMP180_get_ut().

◆ BMP180_get_up()

int8_t BMP180_get_up ( BMP180_HandleTypeDef * dev,
int32_t * up_result )

Triggers and reads the raw (uncompensated) pressure ADC value.

Parameters
[in,out]devPointer to an initialised BMP180_HandleTypeDef.
[out]up_resultPointer to store the raw pressure value.
Returns
0 on success, -1 on I2C error.

◆ BMP180_get_ut()

int8_t BMP180_get_ut ( BMP180_HandleTypeDef * dev,
int32_t * ut_result )

Triggers and reads the raw (uncompensated) temperature ADC value.

Parameters
[in,out]devPointer to an initialised BMP180_HandleTypeDef.
[out]ut_resultPointer to store the raw temperature value.
Returns
0 on success, -1 on I2C error.

◆ BMP180_Init()

int8_t BMP180_Init ( BMP180_HandleTypeDef * dev)

Initialises the BMP180 sensor and reads calibration data.

Verifies the chip ID (0x55) and reads all 11 calibration coefficients from the sensor's EEPROM into dev->calib.

Parameters
[in,out]devPointer to a BMP180_HandleTypeDef with function pointers set.
Returns
0 on success.
-1 if a function pointer is NULL, the chip ID read fails, or calibration data cannot be read.
-2 if the chip ID value is not 0x55.

◆ BMP180_Read()

int8_t BMP180_Read ( BMP180_HandleTypeDef * dev)

Reads both temperature and pressure from the BMP180.

Calls BMP180_get_ut(), BMP180_calc_temperature(), BMP180_get_up() and BMP180_calc_pressure() in sequence. Results are stored in dev->temperature_C and dev->pressure_Pa.

Parameters
[in,out]devPointer to an initialised BMP180_HandleTypeDef.
Returns
0 on success.
-1 if the uncompensated temperature read fails.
-2 if the uncompensated pressure read fails.

◆ BMP180_Read_Temperature()

int8_t BMP180_Read_Temperature ( BMP180_HandleTypeDef * dev)

Reads only the temperature from the BMP180.

Parameters
[in,out]devPointer to an initialised BMP180_HandleTypeDef.
Returns
0 on success, -1 on I2C error.