# bmp180

Library functions for the BMP180 pressure sensor.

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

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()`

      Reset the BMP180 device.

- `bmp180_init()`

      Initialize the BMP180 library. The resoluton mode is set to
      BMP180_MODE_ULTRA_LOW_POWER. The IIC interface must be initialized.

- `bmp180_set_mode(byte in mode)`

      Set the resolution mode.

Private

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

      Write a byte to the given register of the BMP180 via the IIC interface.

### Functions

- `bmp180_get_pressure() return sdword`

      Get the current pressure. This is a blocking call. The delay is depending on
      the last selected resolution mode and can be larger than 31 ms. See datasheet.
      Pressure is returned in Pascal (Pa).

- `bmp180_get_mode() return byte`

      Get the resolution mode.

- `bmp180_get_temperature() return sword`

      Get the current temperature. This is a blocking call. The delay is depending
      on the last selected resolution mode and is at least 4.5 ms. See datasheet.
      Temperature is returned as a value of 0.1 degrees Celcius.

Private

- `_read_raw_temperature() return dword`

      Read a the raw temperaturee and return it.

- `_bmp180_read_data_byte(byte in register) return byte`

      Read a byte from the given register of the BMP180 via the IIC interface.

- `_read_raw_pressure() return dword`

      Read a the raw pressure and return it.

- `_bmp180_read_data_word(byte in register) return word`

      Read a word from the given register of the BMP180 via the IIC interface.
      The BMP180 has data stored with Most Significant Byte (MSB) first.

- `_bmp180_calculate_b5(sdword in raw_data) return sdword`

      Calculate the value of B5. We need this more than once. See datasheet figure 4.

## Related samples

Here are the list of samples which use this library:

16f1825 | 16f1825_bmp180.jal