Atmel Software Framework

bmp.c File Reference

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) 2012 Atmel Corporation. All rights reserved.

#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)
#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)

Referenced by bmp_get_cal_param().

#define Mc   (caldata.mc)
#define Md   (caldata.md)

enum osrs_t

BMP "oversampling_setting" mode values.

Enumerator
OSS_LOW_POWER 

Ultra low power (1 internal samples)

OSS_STANDARD 

Standard (2 internal samples)

OSS_HIGH 

High resolution (4 internal samples)

OSS_ULTRA_HIGH 

Ultra high resolution (8 internal samples)

bool bmp085_init ( sensor_t sensor,
int  resvd 
)

Bosch BMP085 barometric sensor driver initialization.

This is the main initialization function for the BMP085 device.

Parameters
sensorAddress of a sensor device descriptor.
resvdReserved value.
Returns
bool true if the sensor is ready for use, else false.

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.

bool bmp180_init ( sensor_t sensor,
int  resvd 
)

Bosch BMP180 barometric sensor driver initialization.

This is the main initialization function for the BMP180 device.

Parameters
sensorAddress of a sensor device descriptor.
resvdReserved value.
Returns
bool true if the sensor is ready for use, else false.

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 bool bmp_device_id ( sensor_hal_t hal,
sensor_data_t data 
)
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.

Parameters
sensorAddress of an initialized sensor device descriptor.
dataAddress of sensor_data_t structure to return values.
Returns
bool true if the call succeeds, else false is returned.

References BMP_CHIP_ID, BMP_CHIP_VERSION, sensor_data_t::device, and sensor_bus_get.

Referenced by bmp_read().

static void bmp_eoc_wait ( sensor_hal_t hal)
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.

Parameters
halAddress of an initialized sensor HAL descriptor.
Returns
Nothing.

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 bool bmp_get_cal_param ( sensor_hal_t hal)
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.

Parameters
halAddress of an initialized sensor HAL descriptor.
Return values
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, bytes_read, Mb, Mc, Md, and sensor_bus_read.

Referenced by bmp085_init(), and bmp180_init().

static bool bmp_get_pressure ( sensor_hal_t hal,
sensor_data_t data 
)
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".

Parameters
sensorAddress of an initialized sensor device descriptor.
dataThe address where pressure samples are returned.
Returns
bool true if the call succeeds, else false is 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, and sensor_oss.

Referenced by bmp_read().

static bool bmp_get_temperature ( sensor_hal_t hal,
sensor_data_t data 
)
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".

Parameters
sensorAddress of an initialized sensor device descriptor.
dataThe address where temperature samples are returned.
Returns
bool true if the call succeeds, else false is returned.

References AC5, AC6, bmp_get_ut(), Mc, Md, sensor_data_t::scaled, and sensor_data_t::temperature.

Referenced by bmp_read().

static int32_t bmp_get_up ( sensor_hal_t hal)
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.

Parameters
halAddress of an initialized sensor HAL descriptor.
Returns
An uncompensated pressure reading.

References BMP_CONTROL, BMP_DATA_MSB, bmp_eoc_wait(), BMP_PRESS_READ, sensor_bus_put, sensor_bus_read, and sensor_oss.

Referenced by bmp_get_pressure().

static int32_t bmp_get_ut ( sensor_hal_t hal)
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.

Parameters
halAddress of an initialized sensor HAL descriptor.
Returns
An uncompensated temperature reading.

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 bool bmp_ioctl ( sensor_t sensor,
sensor_command_t  cmd,
void *  arg 
)
static

BMP085 / BMP180 ioctl control entry point.

Parameters
halAddress of an initialized sensor device descriptor.
cmdCommand to execute
argArgument for command (varies)
Returns
bool true if the call succeeds, else false is returned.

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 bool bmp_read ( sensor_t sensor,
sensor_read_t  type,
sensor_data_t data 
)
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".

Parameters
sensorAddress of an initialized sensor device descriptor.
typeType of sensor data to read.
dataThe address where pressure samples are returned.
Returns
bool true if the call succeeds, else false is 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 bool bmp_set_state ( sensor_hal_t hal,
sensor_state_t  state 
)
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.

Parameters
sensorAddress of an initialized sensor device descriptor.
stateA specified sensor operational state.
Returns
bool true if the call succeeds, else false is returned.

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

bmp_caldata_t caldata
static