BME280组合式温湿度气压传感器(数据手册、使用、原理图)
立即下载
资源介绍:
BME280是一款成熟的数字湿度、压力和温度传感器。该传感器有一个非常紧凑的金属盖LGA封装,所需面积仅为2.5x2.5mm²,高度为0.93mm。它体积小,功耗低,适合在手机、GPS手持机或手表等电池驱动设备中应用。BME280与Bosch SensortecBMP280数字压力传感器寄存器和特性相兼容。BME280可为所有需要湿度和压力测量的应用场景下提供高性能输出。这些新兴的家庭自动化控制、室内导航、健身以及高精度GPS等场景要求传感器同时具有较高的精度和较低的持有成本(TCO)。
/**\mainpage
* Copyright (C) 2016 - 2017 Bosch Sensortec GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of the copyright holder nor the names of the
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
* OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*
* The information provided is believed to be accurate and reliable.
* The copyright holder assumes no responsibility
* for the consequences of use
* of such information nor for any infringement of patents or
* other rights of third parties which may result from its use.
* No license is granted by implication or otherwise under any patent or
* patent rights of the copyright holder.
*
* File bme280.c
* Date 14 Feb 2018
* Version 3.3.4
*
*/
/*! @file bme280.c
@brief Sensor driver for BME280 sensor */
#include "bme280.h"
/**\name Internal macros */
/* To identify osr settings selected by user */
#define OVERSAMPLING_SETTINGS UINT8_C(0x07)
/* To identify filter and standby settings selected by user */
#define FILTER_STANDBY_SETTINGS UINT8_C(0x18)
/*!
* @brief This internal API puts the device to sleep mode.
*
* @param[in] dev : Structure instance of bme280_dev.
*
* @return Result of API execution status.
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error
*/
static int8_t put_device_to_sleep(const struct bme280_dev *dev);
/*!
* @brief This internal API writes the power mode in the sensor.
*
* @param[in] dev : Structure instance of bme280_dev.
* @param[in] sensor_mode : Variable which contains the power mode to be set.
*
* @return Result of API execution status.
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error
*/
static int8_t write_power_mode(uint8_t sensor_mode, const struct bme280_dev *dev);
/*!
* @brief This internal API is used to validate the device pointer for
* null conditions.
*
* @param[in] dev : Structure instance of bme280_dev.
*
* @return Result of API execution status
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error
*/
static int8_t null_ptr_check(const struct bme280_dev *dev);
/*!
* @brief This internal API interleaves the register address between the
* register data buffer for burst write operation.
*
* @param[in] reg_addr : Contains the register address array.
* @param[out] temp_buff : Contains the temporary buffer to store the
* register data and register address.
* @param[in] reg_data : Contains the register data to be written in the
* temporary buffer.
* @param[in] len : No of bytes of data to be written for burst write.
*/
static void interleave_reg_addr(const uint8_t *reg_addr, uint8_t *temp_buff, const uint8_t *reg_data, uint8_t len);
/*!
* @brief This internal API reads the calibration data from the sensor, parse
* it and store in the device structure.
*
* @param[in] dev : Structure instance of bme280_dev.
*
* @return Result of API execution status
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error
*/
static int8_t get_calib_data(struct bme280_dev *dev);
/*!
* @brief This internal API is used to parse the temperature and
* pressure calibration data and store it in the device structure.
*
* @param[out] dev : Structure instance of bme280_dev to store the calib data.
* @param[in] reg_data : Contains the calibration data to be parsed.
*/
static void parse_temp_press_calib_data(const uint8_t *reg_data, struct bme280_dev *dev);
/*!
* @brief This internal API is used to parse the humidity calibration data
* and store it in device structure.
*
* @param[out] dev : Structure instance of bme280_dev to store the calib data.
* @param[in] reg_data : Contains calibration data to be parsed.
*/
static void parse_humidity_calib_data(const uint8_t *reg_data, struct bme280_dev *dev);
#ifdef BME280_FLOAT_ENABLE
/*!
* @brief This internal API is used to compensate the raw pressure data and
* return the compensated pressure data in double data type.
*
* @param[in] uncomp_data : Contains the uncompensated pressure data.
* @param[in] calib_data : Pointer to the calibration data structure.
*
* @return Compensated pressure data.
* @retval Compensated pressure data in double.
*/
static double compensate_pressure(const struct bme280_uncomp_data *uncomp_data,
const struct bme280_calib_data *calib_data);
/*!
* @brief This internal API is used to compensate the raw humidity data and
* return the compensated humidity data in double data type.
*
* @param[in] uncomp_data : Contains the uncompensated humidity data.
* @param[in] calib_data : Pointer to the calibration data structure.
*
* @return Compensated humidity data.
* @retval Compensated humidity data in double.
*/
static double compensate_humidity(const struct bme280_uncomp_data *uncomp_data,
const struct bme280_calib_data *calib_data);
/*!
* @brief This internal API is used to compensate the raw temperature data and
* return the compensated temperature data in double data type.
*
* @param[in] uncomp_data : Contains the uncompensated temperature data.
* @param[in] calib_data : Pointer to calibration data structure.
*
* @return Compensated temperature data.
* @retval Compensated temperature data in double.
*/
static double compensate_temperature(const struct bme280_uncomp_data *uncomp_data,
struct bme280_calib_data *calib_data);
#else
/*!
* @brief This internal API is used to compensate the raw temperature data and
* return the compensated temperature data in integer data type.
*
* @param[in] uncomp_data : Contains the uncompensated temperature data.
* @param[in] calib_data : Pointer to calibration data structure.
*
* @return Compensated temperature data.
* @retval Compensated temperature data in integer.
*/
static int32_t compensate_temperature(const struct bme280_uncomp_data *uncomp_data,
struct bme280_calib_data *calib_data);
/*!
* @brief This internal API is used to compensate the raw pressure data and
* return the compensated pressure data in integer data type.
*
* @param[in] uncomp_data : Contains the uncompensated pressure data.
* @param[in] calib_data : Pointer to the calibration data structure.
*
* @return Compensated pressure data.
* @retval Compensated pressure data in integer.
*/
static uint32_t compensate_pressure(const struct bme280_uncomp_data *uncomp_data,
const struct bme280_ca