Bosch Digital pressure sensor common definitions.
This module defines registers, constants, data structures, and global function prototypes that are common to multiple Bosch sensor drivers, in particular those for BMP085 and BMP180 devices.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include "bmp.h"
Data Structures | |
struct | bmp_caldata_t |
BMP085 & BMP180 calibration coeffs. More... | |
Macros | |
#define | AC1 (caldata.ac1) |
#define | AC2 (caldata.ac2) |
#define | AC3 (caldata.ac3) |
#define | AC4 (caldata.ac4) |
#define | AC5 (caldata.ac5) |
#define | AC6 (caldata.ac6) |
#define | B1 (caldata.b1) |
#define | B2 (caldata.b2) |
#define | BMP_RESOLUTION (24 - (8 - sensor_oss)) |
#define | Mb (caldata.mb) |
#define | Mc (caldata.mc) |
#define | Md (caldata.md) |
Enumerations | |
enum | osrs_t { OSS_LOW_POWER = 0, OSS_STANDARD = 1, OSS_HIGH = 2, OSS_ULTRA_HIGH = 3 } |
BMP "oversampling_setting" mode values. More... | |
Functions | |
bool | bmp085_init (sensor_t *sensor, int resvd) |
Bosch BMP085 barometric sensor driver initialization. More... | |
bool | bmp180_init (sensor_t *sensor, int resvd) |
Bosch BMP180 barometric sensor driver initialization. More... | |
static bool | bmp_device_id (sensor_hal_t *hal, sensor_data_t *data) |
Read sensor device ID and revision numbers. More... | |
static void | bmp_eoc_wait (sensor_hal_t *hal) |
Wait for completion of sensor analog-to-digital conversion. More... | |
static bool | bmp_get_cal_param (sensor_hal_t *hal) |
Read BMP085 / BMP180 calibration coefficients. More... | |
static bool | bmp_get_pressure (sensor_hal_t *hal, sensor_data_t *data) |
Get a pressure sensor sample. More... | |
static bool | bmp_get_temperature (sensor_hal_t *hal, sensor_data_t *data) |
Get a temperature sensor sample. More... | |
static int32_t | bmp_get_up (sensor_hal_t *hal) |
Get an uncompensated pressure (UP) reading. More... | |
static int32_t | bmp_get_ut (sensor_hal_t *hal) |
Get an uncompensated temperature (UT) reading. More... | |
static bool | bmp_ioctl (sensor_t *sensor, sensor_command_t cmd, void *arg) |
BMP085 / BMP180 ioctl control entry point. More... | |
static bool | bmp_read (sensor_t *sensor, sensor_read_t type, sensor_data_t *data) |
Read sensor data. More... | |
static bool | bmp_set_state (sensor_hal_t *hal, sensor_state_t state) |
Set the BMP085 / BMP180 execution mode. More... | |
Variables | |
static bmp_caldata_t | caldata |
static osrs_t | sensor_oss |
#define AC1 (caldata.ac1) |
Referenced by bmp_get_cal_param(), and bmp_get_pressure().
#define AC2 (caldata.ac2) |
Referenced by bmp_get_cal_param(), and bmp_get_pressure().
#define AC3 (caldata.ac3) |
Referenced by bmp_get_cal_param(), and bmp_get_pressure().
#define AC4 (caldata.ac4) |
Referenced by bmp_get_cal_param(), and bmp_get_pressure().
#define AC5 (caldata.ac5) |
Referenced by bmp_get_cal_param(), bmp_get_pressure(), and bmp_get_temperature().
#define AC6 (caldata.ac6) |
Referenced by bmp_get_cal_param(), bmp_get_pressure(), and bmp_get_temperature().
#define B1 (caldata.b1) |
Referenced by bmp_get_cal_param(), and bmp_get_pressure().
#define B2 (caldata.b2) |
Referenced by bmp_get_cal_param(), and bmp_get_pressure().
#define BMP_RESOLUTION (24 - (8 - sensor_oss)) |
Referenced by bmp085_init(), bmp180_init(), and bmp_set_state().
#define Mb (caldata.mb) |
Referenced by bmp_get_cal_param().
#define Mc (caldata.mc) |
Referenced by bmp_get_cal_param(), bmp_get_pressure(), and bmp_get_temperature().
#define Md (caldata.md) |
Referenced by bmp_get_cal_param(), bmp_get_pressure(), and bmp_get_temperature().
enum osrs_t |
Bosch BMP085 barometric sensor driver initialization.
This is the main initialization function for the BMP085 device.
sensor | Address of a sensor device descriptor. |
resvd | Reserved value. |
References BMP085_ID_VAL, BMP085_VER_VAL, BMP_CHIP_ID, BMP_CHIP_VERSION, bmp_get_cal_param(), bmp_ioctl(), bmp_read(), BMP_RESOLUTION, sensor_desc::drv, sensor_device_t::func, sensor_desc::hal, OSS_STANDARD, sensor_funcs_t::read, sensor_hal::resolution, sensor_bus_get, SENSOR_CAPS_AUX_TEMP, sensor_oss, SENSOR_UNITS_pascal, SENSOR_VENDOR_BOSCH, and status.
Bosch BMP180 barometric sensor driver initialization.
This is the main initialization function for the BMP180 device.
sensor | Address of a sensor device descriptor. |
resvd | Reserved value. |
References BMP180_ID_VAL, BMP180_VER_VAL, BMP_CHIP_ID, BMP_CHIP_VERSION, bmp_get_cal_param(), bmp_ioctl(), bmp_read(), BMP_RESOLUTION, sensor_desc::drv, sensor_device_t::func, sensor_desc::hal, OSS_STANDARD, sensor_funcs_t::read, sensor_hal::resolution, sensor_bus_get, SENSOR_CAPS_AUX_TEMP, sensor_oss, SENSOR_UNITS_pascal, SENSOR_VENDOR_BOSCH, and status.
|
static |
Read sensor device ID and revision numbers.
This function reads the sensor hardware identification registers and returns these values to the addresses specified in the function parameters.
sensor | Address of an initialized sensor device descriptor. |
data | Address of sensor_data_t structure to return values. |
References BMP_CHIP_ID, BMP_CHIP_VERSION, sensor_data_t::device, and sensor_bus_get.
Referenced by bmp_read().
|
inlinestatic |
Wait for completion of sensor analog-to-digital conversion.
Per the Bosch BMP085 & BMP180 data sheets there will be a delay between the time when a data measurement is requested and the sensor internal A/D conversion is complete. The maximum conversion varies according to the oversampling mode.
Instead of waiting for the maximum conversion time, the end of conversion (EOC) digital sensor output, which is connected to a port on the "Atmel Sensor Board", can be tested for a completed conversion.
hal | Address of an initialized sensor HAL descriptor. |
Poll the End Of Conversion (EOC) input pin.
This works on the BMP085 but not on the BMP180.
while (gpio_pin_is_low (hal->mcu_sigint));
References delay_ms, and sensor_oss.
Referenced by bmp_get_up().
|
static |
Read BMP085 / BMP180 calibration coefficients.
Calculating temperature in degrees C or pressure in Pa requires the use of calibration data coefficients stored in the BMP EEPROM. Every sensor module has individual coefficients. Before the first calculation of temperature and pressure, the master reads this data from device EEPROM.
hal | Address of an initialized sensor HAL descriptor. |
bool | "true" if valid coefficients have been fetched |
bool | "false" for errors reading the device coefficients |
References AC1, AC2, AC3, AC4, AC5, AC6, B1, B2, BMP_EEPROM_ADDR, BMP_EEPROM_SIZE_BYTES, Mb, Mc, Md, and sensor_bus_read.
Referenced by bmp085_init(), and bmp180_init().
|
static |
Get a pressure sensor sample.
If scaled data format is selected for the device, this routine gets a compensated "true pressure" sample using the sampling mode specified when the device was initialized. Otherwise a raw uncompensated pressure reading is returned in "data".
sensor | Address of an initialized sensor device descriptor. |
data | The address where pressure samples are returned. |
References AC1, AC2, AC3, AC4, AC5, AC6, B1, B2, bmp_get_up(), bmp_get_ut(), Mc, Md, sensor_data_t::pressure, sensor_data_t::scaled, sensor_oss, and UP.
Referenced by bmp_read().
|
static |
Get a temperature sensor sample.
If scaled data format is selected for the device, this routine gets a compensated "true temperature" sample. Otherwise, a raw uncompensated temperature reading is returned in "data".
sensor | Address of an initialized sensor device descriptor. |
data | The address where temperature samples are returned. |
References AC5, AC6, bmp_get_ut(), Mc, Md, sensor_data_t::scaled, and sensor_data_t::temperature.
Referenced by bmp_read().
|
static |
Get an uncompensated pressure (UP) reading.
This routine gets a raw pressure sample reading from a Bosch BMP085 or BMP180 device. In the event of a sensor or bus error, a 32-bit value of -1 (all bits set) may be returned from this routine.
hal | Address of an initialized sensor HAL descriptor. |
References BMP_CONTROL, BMP_DATA_MSB, bmp_eoc_wait(), BMP_PRESS_READ, sensor_bus_put, sensor_bus_read, sensor_oss, and UP.
Referenced by bmp_get_pressure().
|
static |
Get an uncompensated temperature (UT) reading.
This routine gets a raw temperature sample reading from the a BMP085 or BMP180 device. In the event of a sensor or bus error, a 32-bit value of -1 (all bits set) may be returned from this routine.
hal | Address of an initialized sensor HAL descriptor. |
References BMP_CONTROL, BMP_DATA_MSB, BMP_TEMP_READ, delay_ms, sensor_bus_put, and sensor_bus_read.
Referenced by bmp_get_pressure(), and bmp_get_temperature().
|
static |
BMP085 / BMP180 ioctl control entry point.
hal | Address of an initialized sensor device descriptor. |
cmd | Command to execute |
arg | Argument for command (varies) |
References bmp_set_state(), sensor_desc::err, sensor_desc::hal, SENSOR_ERR_UNSUPPORTED, SENSOR_SET_STATE, and status.
Referenced by bmp085_init(), and bmp180_init().
|
static |
Read sensor data.
If scaled data format is selected for the device, this routine gets a compensated "true pressure" sample using the sampling mode specified when the device was initialized. Otherwise a raw uncompensated pressure reading is returned in "data".
sensor | Address of an initialized sensor device descriptor. |
type | Type of sensor data to read. |
data | The address where pressure samples are returned. |
References bmp_device_id(), bmp_get_pressure(), bmp_get_temperature(), sensor_desc::err, sensor_desc::hal, SENSOR_ERR_FUNCTION, SENSOR_READ_ID, SENSOR_READ_PRESSURE, and SENSOR_READ_TEMPERATURE.
Referenced by bmp085_init(), and bmp180_init().
|
static |
Set the BMP085 / BMP180 execution mode.
This routine sets a specified BMP085 or BMP180 execution state to one of the following:
SENSOR_STATE_LOWEST_POWER or SENSOR_STATE_LOW_POWER Ultra low power mode (1 internal sample). In this mode the average current @ 1 sample/s is typically 3 microamps.
SENSOR_STATE_NORMAL Standard mode (2 internal samples). In this mode the average current @ 1 sample/s is typically 5 microamps.
SENSOR_STATE_HIGH_POWER High resolution mode (4 internal samples). In this mode the average current @ 1 sample/s is typically 7 microamps.
SENSOR_STATE_HIGHEST_POWER Ultra high resolution mode (8 internal samples). In this mode the average current @ 1 sample/s is 12 microamps.
SENSOR_STATE_RESET This function resets the device and internal registers to the power-up default settings.
sensor | Address of an initialized sensor device descriptor. |
state | A specified sensor operational state. |
Activate, then deactivate, the master reset pin (XCLR).
This works on the BMP085 but not on the BMP180.
gpio_set_pin_low (hal->mcu_sigout); gpio_set_pin_high (hal->mcu_sigout);
References BMP_RESET_CMD, BMP_RESOLUTION, BMP_SOFT_RESET, OSS_HIGH, OSS_LOW_POWER, OSS_STANDARD, OSS_ULTRA_HIGH, sensor_hal::resolution, sensor_bus_put, sensor_oss, SENSOR_STATE_HIGH_POWER, SENSOR_STATE_HIGHEST_POWER, SENSOR_STATE_LOW_POWER, SENSOR_STATE_LOWEST_POWER, SENSOR_STATE_NORMAL, and SENSOR_STATE_RESET.
Referenced by bmp_ioctl().
|
static |
|
static |
Referenced by bmp085_init(), bmp180_init(), bmp_eoc_wait(), bmp_get_pressure(), bmp_get_up(), and bmp_set_state().