# bmp180

Library functions for the BMP180 pressure sensor.

Author | Rob Jansen, Copyright © 2024..2025, all rights reserved.
Adapted-by |
Compiler | 2.5r9

Description

    Library functions for the BMP180 pressure sensor. The main
                 program has to setup the IIC communication using an IIC clock of
                 at most 3.4 MHz.

Sources

    Bosch BMP180 Datasheet version 2.5, document BST-BMP180-DS000-09.

Dependencies

No dependency found

## Summary

### Global variables/contants

- `const byte _BMP180_READ_PRESSURE_CMD = 0x34`
- `var sword _bmp180_ac1, _bmp180_ac2, _bmp180_ac3`
- `const byte BMP180_MODE_HIGH_RES = 2`
- `const byte BMP180_MODE_STANDARD = 1`
- `var byte _bmp180_oversampling`
- `const byte _BMP180_REG_AC5 = 0xB2`
- `var word _bmp180_ac4, _bmp180_ac5, _bmp180_ac6`
- `const byte _BMP180_REG_SOFT_RESET = 0xE0`
- `const byte _BMP180_REG_CTRL_MEAS = 0xF4`
- `const byte BMP180_MODE_ULTRA_LOW_POWER = 0`
- `const byte _BMP180_REG_MC = 0xBC`
- `const byte BMP180_MODE_ULTRA_HIGH_RES = 3`
- `const byte _BMP180_REG_AC4 = 0xB0`
- `const byte _BMP180_REG_B2 = 0xB8`
- `const byte _BMP180_REG_OUT_LSB = 0xF7`
- `const byte _BMP180_REG_ID = 0xD0`
- `const byte _BMP180_REG_MD = 0xBE`
- `const byte _BMP180_REG_OUT_XLSB = 0xF8`
- `const byte _BMP180_REG_AC6 = 0xB4`
- `const byte _BMP180_REG_AC1 = 0xAA`
- `const byte _BMP180_READ_TEMPERATURE_CMD = 0x2E`
- `const byte _BMP180_REG_B1 = 0xB6`
- `const byte _BMP180_IIC_ADDRESS = 0b1110_1110`
- `const byte _BMP180_REG_MB = 0xBA`
- `const byte _BMP180_REG_AC3 = 0xAE`
- `const byte _BMP180_REG_AC2 = 0xAC`
- `const byte _BMP180_REG_OUT_MSB = 0xF6`
- `var sword _bmp180_b1, _bmp180_b2, _bmp180_mb, _bmp180_mc, _bmp180_md`

### Procedures

- `bmp180_reset()`
- `bmp180_init()`
- `bmp180_set_mode(byte in mode)`

Private

- `_bmp180_write_data_byte(byte in register, byte in data)`

### Functions

- `bmp180_get_pressure() return sdword`
- `bmp180_get_mode() return byte`
- `bmp180_get_temperature() return sword`

Private

- `_read_raw_temperature() return dword`
- `_bmp180_read_data_byte(byte in register) return byte`
- `_read_raw_pressure() return dword`
- `_bmp180_read_data_word(byte in register) return word`
- `_bmp180_calculate_b5(sdword in raw_data) return sdword`

## API details

### Global variables/contants

- `const byte _BMP180_READ_PRESSURE_CMD = 0x34`

  No documentation found

- `var sword _bmp180_ac1, _bmp180_ac2, _bmp180_ac3`

      Calibration coefficients to be obtained from the EEPROM of the device.

- `const byte BMP180_MODE_HIGH_RES = 2`

  No documentation found

- `const byte BMP180_MODE_STANDARD = 1`

  No documentation found

- `var byte _bmp180_oversampling`

      Holds the resolution mode.

- `const byte _BMP180_REG_AC5 = 0xB2`

  No documentation found

- `var word _bmp180_ac4, _bmp180_ac5, _bmp180_ac6`

  No documentation found

- `const byte _BMP180_REG_SOFT_RESET = 0xE0`

  No documentation found

- `const byte _BMP180_REG_CTRL_MEAS = 0xF4`

  No documentation found

- `const byte BMP180_MODE_ULTRA_LOW_POWER = 0`

      Resolution modes and oversampling settings.

- `const byte _BMP180_REG_MC = 0xBC`

  No documentation found

- `const byte BMP180_MODE_ULTRA_HIGH_RES = 3`

  No documentation found

- `const byte _BMP180_REG_AC4 = 0xB0`

  No documentation found

- `const byte _BMP180_REG_B2 = 0xB8`

  No documentation found

- `const byte _BMP180_REG_OUT_LSB = 0xF7`

      Read only.

- `const byte _BMP180_REG_ID = 0xD0`

      Read only. Fixed value 0x55.

- `const byte _BMP180_REG_MD = 0xBE`

  No documentation found

- `const byte _BMP180_REG_OUT_XLSB = 0xF8`

      BMP180 register addresses.
      Control and data registers addresses. These are 8 bit addresses.

- `const byte _BMP180_REG_AC6 = 0xB4`

  No documentation found

- `const byte _BMP180_REG_AC1 = 0xAA`

      Calibration addressess This is a word address so register address is MSB.

- `const byte _BMP180_READ_TEMPERATURE_CMD = 0x2E`

      Commands.

- `const byte _BMP180_REG_B1 = 0xB6`

  No documentation found

- `const byte _BMP180_IIC_ADDRESS = 0b1110_1110`

      IIC write address (A0 = 0).

- `const byte _BMP180_REG_MB = 0xBA`

  No documentation found

- `const byte _BMP180_REG_AC3 = 0xAE`

  No documentation found

- `const byte _BMP180_REG_AC2 = 0xAC`

  No documentation found

- `const byte _BMP180_REG_OUT_MSB = 0xF6`

      Read only.

- `var sword _bmp180_b1, _bmp180_b2, _bmp180_mb, _bmp180_mc, _bmp180_md`

  No documentation found

### Procedures

- `bmp180_reset()`

      Description: Reset the BMP180 device
      Parameters:
       None

- `bmp180_init()`

      Description: Initialize the BMP180 library
       The resoluton mode is set to BMP180_MODE_ULTRA_LOW_POWER.
      Parameters:
       None
      Notes:
       The IIC interface must be initialized.

- `bmp180_set_mode(byte in mode)`

      Description: Set the resolution mode
      Parameters:
       mode - Resolution mode, see BMP180_MODE_xx.

Private

- `_bmp180_write_data_byte(byte in register, byte in data)`

      Description: Write a byte to the given BMP180 register
      Parameters:
       register - register to write to
       data     - data to be written

### Functions

- `bmp180_get_pressure() return sdword`

      Description: Get the current pressure
      Parameters:
       None
      Returns:
       Pressure in Pascal (Pa)
      Notes:
       This is a blocking call. The delay is depending on the last selected
       resolution mode and can be longer than 31 ms. See datasheet.

- `bmp180_get_mode() return byte`

      Description: Get the current resolution mode
      Parameters:
       None
      Returns:
       Resolution mode, see BMP180_MODE_xx.

- `bmp180_get_temperature() return sword`

      Description: Get the current temperature
      Parameters:
       None
      Returns:
       Temperature in 0.1 degrees Celcius
      Notes:
       This is a blocking call. The delay is depending on the last selected
       resolution mode and is at least 4.5 ms. See datasheet.

Private

- `_read_raw_temperature() return dword`

      Description: Read the raw temperature
      Parameters:
       None
      Returns:
       Raw temperature.

- `_bmp180_read_data_byte(byte in register) return byte`

      Description: Read a byte from the given BMP180 register
      Parameters:
       register - register to read from
      Returns:
       Data from register

- `_read_raw_pressure() return dword`

      Description: Read the raw pressure
      Parameters:
       None
      Returns:
       Raw pressure.

- `_bmp180_read_data_word(byte in register) return word`

      Description: Read a word from the given BMP180 register
      Parameters:
       register - register to read from
      Returns:
       Data from register
      Notes:
       The BMP180 stores data with Most Significant Byte (MSB) first.

- `_bmp180_calculate_b5(sdword in raw_data) return sdword`

      Description: Calculate the value of B5
      Parameters:
       raw_data - raw data
      Returns:
       Value of B5
      Notes:
       See datasheet figure 4.

## Related samples

Here are the list of samples which use this library:

16f1825 | 16f1825_bmp180.jal