v3.5.3
- Changed the compensation equation formulas to use shifting operation - Updated the "bme680_get_profile_dur" API - Fixed Checkpatch and made linux compatible - Fixed bug of temperature compensation in pressure - Updated self test APIs
This commit is contained in:
parent
2a51b9c0c1
commit
94fd057adf
10
README.md
10
README.md
@ -6,10 +6,10 @@ The sensor driver package includes bme680.h, bme680.c and bme680_defs.h files
|
|||||||
|
|
||||||
## Version
|
## Version
|
||||||
File | Version | Date
|
File | Version | Date
|
||||||
-----|---------|-----
|
--------------|---------|-------------
|
||||||
bme680.c | 3.5.1 | 5 Jul 2017
|
bme680.c | 3.5.3 | 30 Oct 2017
|
||||||
bme680.h | 3.5.1 | 5 Jul 2017
|
bme680.h | 3.5.3 | 30 Oct 2017
|
||||||
bme680_defs.h | 3.5.1 | 5 Jul 2017
|
bme680_defs.h | 3.5.3 | 30 Oct 2017
|
||||||
|
|
||||||
## Integration details
|
## Integration details
|
||||||
* Integrate bme680.h, bme680_defs.h and bme680.c file in to your project.
|
* Integrate bme680.h, bme680_defs.h and bme680.c file in to your project.
|
||||||
@ -112,7 +112,7 @@ fill in the various parameters as shown below
|
|||||||
printf("T: %.2f degC, P: %.2f hPa, H %.2f %%rH ", data.temperature / 100.0f,
|
printf("T: %.2f degC, P: %.2f hPa, H %.2f %%rH ", data.temperature / 100.0f,
|
||||||
data.pressure / 100.0f, data.humidity / 1000.0f );
|
data.pressure / 100.0f, data.humidity / 1000.0f );
|
||||||
/* Avoid using measurements from an unstable heating setup */
|
/* Avoid using measurements from an unstable heating setup */
|
||||||
if(data.status & BME680_HEAT_STAB_MSK)
|
if(data.status & BME680_GASM_VALID_MSK)
|
||||||
printf(", G: %d ohms", data.gas_resistance);
|
printf(", G: %d ohms", data.gas_resistance);
|
||||||
|
|
||||||
printf("\r\n");
|
printf("\r\n");
|
||||||
|
@ -40,8 +40,8 @@
|
|||||||
* patent rights of the copyright holder.
|
* patent rights of the copyright holder.
|
||||||
*
|
*
|
||||||
* File bme680_selftest.c
|
* File bme680_selftest.c
|
||||||
* @date 5 Jul 2017
|
* @date 10 Oct 2017
|
||||||
* @version 3.5.1
|
* @version 3.5.2
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -53,7 +53,7 @@
|
|||||||
#include "bme680_selftest.h"
|
#include "bme680_selftest.h"
|
||||||
|
|
||||||
#define MIN_TEMPERATURE INT16_C(0) /* 0 degree Celsius */
|
#define MIN_TEMPERATURE INT16_C(0) /* 0 degree Celsius */
|
||||||
#define MAX_TEMPERATURE INT16_C(4000) /* 40 degree Celsius */
|
#define MAX_TEMPERATURE INT16_C(6000) /* 60 degree Celsius */
|
||||||
|
|
||||||
#define MIN_PRESSURE UINT32_C(90000) /* 900 hecto Pascals */
|
#define MIN_PRESSURE UINT32_C(90000) /* 900 hecto Pascals */
|
||||||
#define MAX_PRESSURE UINT32_C(110000) /* 1100 hecto Pascals */
|
#define MAX_PRESSURE UINT32_C(110000) /* 1100 hecto Pascals */
|
||||||
@ -63,7 +63,7 @@
|
|||||||
|
|
||||||
#define HEATR_DUR 2000
|
#define HEATR_DUR 2000
|
||||||
#define N_MEAS 6
|
#define N_MEAS 6
|
||||||
#define LOW_TEMP 200
|
#define LOW_TEMP 150
|
||||||
#define HIGH_TEMP 350
|
#define HIGH_TEMP 350
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -124,9 +124,9 @@ int8_t bme680_self_test(struct bme680_dev *dev)
|
|||||||
if (rslt == BME680_OK) {
|
if (rslt == BME680_OK) {
|
||||||
|
|
||||||
if (i % 2 == 0)
|
if (i % 2 == 0)
|
||||||
t_dev.gas_sett.heatr_temp = LOW_TEMP; /* Lower temperature */
|
|
||||||
else
|
|
||||||
t_dev.gas_sett.heatr_temp = HIGH_TEMP; /* Higher temperature */
|
t_dev.gas_sett.heatr_temp = HIGH_TEMP; /* Higher temperature */
|
||||||
|
else
|
||||||
|
t_dev.gas_sett.heatr_temp = LOW_TEMP; /* Lower temperature */
|
||||||
|
|
||||||
rslt = bme680_set_sensor_settings(settings_sel, &t_dev);
|
rslt = bme680_set_sensor_settings(settings_sel, &t_dev);
|
||||||
|
|
||||||
@ -169,15 +169,16 @@ static int8_t analyze_sensor_data(struct bme680_field_data *data, uint8_t n_meas
|
|||||||
self_test_failed++;
|
self_test_failed++;
|
||||||
|
|
||||||
for (i = 0; i < n_meas; i++) /* Every gas measurement should be valid */
|
for (i = 0; i < n_meas; i++) /* Every gas measurement should be valid */
|
||||||
if (!(data[i].status & (BME680_GASM_VALID_MSK | BME680_HEAT_STAB_MSK)))
|
if (!(data[i].status & BME680_GASM_VALID_MSK))
|
||||||
self_test_failed++;
|
self_test_failed++;
|
||||||
|
|
||||||
for (i = 2; i < n_meas; i += 2) {
|
/* 3 cycles heating are completed(HT1/LT1, HT2/LT2,HT3/LT3)
|
||||||
/* Invert formula to get integer values for centroid resistance, i.e. > 1 */
|
centroid gas ratio = 2*HT3 / (LT2+LT3) < 0.5*/
|
||||||
cent_res = (data[i - 2].gas_resistance + data[i].gas_resistance) / (2 * data[i - 1].gas_resistance);
|
/* Invert formula to get integer values for centroid resistance */
|
||||||
}
|
if (n_meas >= 6)
|
||||||
|
cent_res = (data[3].gas_resistance + data[5].gas_resistance) / (2 * data[4].gas_resistance);
|
||||||
|
|
||||||
if ((cent_res < 3) || (cent_res > 20)) /* 0.05 > cent_res^-1 < 0.03 */
|
if ((cent_res < 2)) /*cent_res^-1 < 0.5 */
|
||||||
self_test_failed++;
|
self_test_failed++;
|
||||||
|
|
||||||
if (self_test_failed)
|
if (self_test_failed)
|
||||||
|
@ -40,8 +40,8 @@
|
|||||||
* patent rights of the copyright holder.
|
* patent rights of the copyright holder.
|
||||||
*
|
*
|
||||||
* @file bme680_selftest.h
|
* @file bme680_selftest.h
|
||||||
* @date 5 Jul 2017
|
* @date 10 Oct 2017
|
||||||
* @version 3.5.1
|
* @version 3.5.2
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
167
bme680.c
167
bme680.c
@ -40,8 +40,8 @@
|
|||||||
* patent rights of the copyright holder.
|
* patent rights of the copyright holder.
|
||||||
*
|
*
|
||||||
* File bme680.c
|
* File bme680.c
|
||||||
* @date 5 Jul 2017
|
* @date 30 Oct 2017
|
||||||
* @version 3.5.1
|
* @version 3.5.3
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -239,15 +239,14 @@ int8_t bme680_init(struct bme680_dev *dev)
|
|||||||
|
|
||||||
/* Check for null pointer in the device structure*/
|
/* Check for null pointer in the device structure*/
|
||||||
rslt = null_ptr_check(dev);
|
rslt = null_ptr_check(dev);
|
||||||
if (rslt == BME680_OK)
|
if (rslt == BME680_OK) {
|
||||||
{
|
|
||||||
/* Soft reset to restore it to default values*/
|
/* Soft reset to restore it to default values*/
|
||||||
rslt = bme680_soft_reset(dev);
|
rslt = bme680_soft_reset(dev);
|
||||||
|
|
||||||
if (rslt == BME680_OK) {
|
if (rslt == BME680_OK) {
|
||||||
rslt = bme680_get_regs(BME680_CHIP_ID_ADDR, &dev->chip_id, 1, dev);
|
rslt = bme680_get_regs(BME680_CHIP_ID_ADDR, &dev->chip_id, 1, dev);
|
||||||
if (rslt == BME680_OK) {
|
if (rslt == BME680_OK) {
|
||||||
if (dev->chip_id == BME680_CHIP_ID) {
|
if (dev->chip_id == BME680_CHIP_ID) {
|
||||||
|
/* Get the Calibration data */
|
||||||
rslt = get_calib_data(dev);
|
rslt = get_calib_data(dev);
|
||||||
} else {
|
} else {
|
||||||
rslt = BME680_E_DEV_NOT_FOUND;
|
rslt = BME680_E_DEV_NOT_FOUND;
|
||||||
@ -398,7 +397,8 @@ int8_t bme680_set_sensor_settings(uint16_t desired_settings, struct bme680_dev *
|
|||||||
|
|
||||||
/* Selecting heater control for the sensor */
|
/* Selecting heater control for the sensor */
|
||||||
if (desired_settings & BME680_HCNTRL_SEL) {
|
if (desired_settings & BME680_HCNTRL_SEL) {
|
||||||
rslt = boundary_check(&dev->gas_sett.heatr_ctrl, BME680_ENABLE_HEATER, BME680_DISABLE_HEATER, dev);
|
rslt = boundary_check(&dev->gas_sett.heatr_ctrl, BME680_ENABLE_HEATER,
|
||||||
|
BME680_DISABLE_HEATER, dev);
|
||||||
reg_addr = BME680_CONF_HEAT_CTRL_ADDR;
|
reg_addr = BME680_CONF_HEAT_CTRL_ADDR;
|
||||||
|
|
||||||
if (rslt == BME680_OK)
|
if (rslt == BME680_OK)
|
||||||
@ -445,9 +445,14 @@ int8_t bme680_set_sensor_settings(uint16_t desired_settings, struct bme680_dev *
|
|||||||
|
|
||||||
/* Selecting the runGas and NB conversion settings for the sensor */
|
/* Selecting the runGas and NB conversion settings for the sensor */
|
||||||
if (desired_settings & (BME680_RUN_GAS_SEL | BME680_NBCONV_SEL)) {
|
if (desired_settings & (BME680_RUN_GAS_SEL | BME680_NBCONV_SEL)) {
|
||||||
rslt = boundary_check(&dev->gas_sett.run_gas, BME680_RUN_GAS_DISABLE, BME680_RUN_GAS_ENABLE, dev);
|
rslt = boundary_check(&dev->gas_sett.run_gas, BME680_RUN_GAS_DISABLE,
|
||||||
if (rslt == BME680_OK)
|
BME680_RUN_GAS_ENABLE, dev);
|
||||||
rslt = boundary_check(&dev->gas_sett.nb_conv, BME680_NBCONV_MIN, BME680_NBCONV_MAX, dev);
|
if (rslt == BME680_OK) {
|
||||||
|
/* Validate boundary conditions */
|
||||||
|
rslt = boundary_check(&dev->gas_sett.nb_conv, BME680_NBCONV_MIN,
|
||||||
|
BME680_NBCONV_MAX, dev);
|
||||||
|
}
|
||||||
|
|
||||||
reg_addr = BME680_CONF_ODR_RUN_GAS_NBC_ADDR;
|
reg_addr = BME680_CONF_ODR_RUN_GAS_NBC_ADDR;
|
||||||
|
|
||||||
if (rslt == BME680_OK)
|
if (rslt == BME680_OK)
|
||||||
@ -496,7 +501,8 @@ int8_t bme680_get_sensor_settings(uint16_t desired_settings, struct bme680_dev *
|
|||||||
|
|
||||||
/* get the T,P,H ,Filter,ODR settings here */
|
/* get the T,P,H ,Filter,ODR settings here */
|
||||||
if (desired_settings & BME680_FILTER_SEL)
|
if (desired_settings & BME680_FILTER_SEL)
|
||||||
dev->tph_sett.filter = BME680_GET_BITS(data_array[BME680_REG_FILTER_INDEX], BME680_FILTER);
|
dev->tph_sett.filter = BME680_GET_BITS(data_array[BME680_REG_FILTER_INDEX],
|
||||||
|
BME680_FILTER);
|
||||||
|
|
||||||
if (desired_settings & (BME680_OST_SEL | BME680_OSP_SEL)) {
|
if (desired_settings & (BME680_OST_SEL | BME680_OSP_SEL)) {
|
||||||
dev->tph_sett.os_temp = BME680_GET_BITS(data_array[BME680_REG_TEMP_INDEX], BME680_OST);
|
dev->tph_sett.os_temp = BME680_GET_BITS(data_array[BME680_REG_TEMP_INDEX], BME680_OST);
|
||||||
@ -504,15 +510,19 @@ int8_t bme680_get_sensor_settings(uint16_t desired_settings, struct bme680_dev *
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (desired_settings & BME680_OSH_SEL)
|
if (desired_settings & BME680_OSH_SEL)
|
||||||
dev->tph_sett.os_hum = BME680_GET_BITS_POS_0(data_array[BME680_REG_HUM_INDEX], BME680_OSH);
|
dev->tph_sett.os_hum = BME680_GET_BITS_POS_0(data_array[BME680_REG_HUM_INDEX],
|
||||||
|
BME680_OSH);
|
||||||
|
|
||||||
/* get the gas related settings */
|
/* get the gas related settings */
|
||||||
if (desired_settings & BME680_HCNTRL_SEL)
|
if (desired_settings & BME680_HCNTRL_SEL)
|
||||||
dev->gas_sett.heatr_ctrl = BME680_GET_BITS_POS_0(data_array[BME680_REG_HCTRL_INDEX], BME680_HCTRL);
|
dev->gas_sett.heatr_ctrl = BME680_GET_BITS_POS_0(data_array[BME680_REG_HCTRL_INDEX],
|
||||||
|
BME680_HCTRL);
|
||||||
|
|
||||||
if (desired_settings & (BME680_RUN_GAS_SEL | BME680_NBCONV_SEL)) {
|
if (desired_settings & (BME680_RUN_GAS_SEL | BME680_NBCONV_SEL)) {
|
||||||
dev->gas_sett.nb_conv = BME680_GET_BITS_POS_0(data_array[BME680_REG_NBCONV_INDEX], BME680_NBCONV);
|
dev->gas_sett.nb_conv = BME680_GET_BITS_POS_0(data_array[BME680_REG_NBCONV_INDEX],
|
||||||
dev->gas_sett.run_gas = BME680_GET_BITS(data_array[BME680_REG_RUN_GAS_INDEX], BME680_RUN_GAS);
|
BME680_NBCONV);
|
||||||
|
dev->gas_sett.run_gas = BME680_GET_BITS(data_array[BME680_REG_RUN_GAS_INDEX],
|
||||||
|
BME680_RUN_GAS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -602,7 +612,7 @@ void bme680_set_profile_dur(uint16_t duration, struct bme680_dev *dev)
|
|||||||
/*!
|
/*!
|
||||||
* @brief This API is used to get the profile duration of the sensor.
|
* @brief This API is used to get the profile duration of the sensor.
|
||||||
*/
|
*/
|
||||||
void bme680_get_profile_dur(uint16_t *duration, struct bme680_dev *dev)
|
void bme680_get_profile_dur(uint16_t *duration, const struct bme680_dev *dev)
|
||||||
{
|
{
|
||||||
uint32_t tph_dur; /* Calculate in us */
|
uint32_t tph_dur; /* Calculate in us */
|
||||||
|
|
||||||
@ -614,8 +624,14 @@ void bme680_get_profile_dur(uint16_t *duration, struct bme680_dev *dev)
|
|||||||
tph_dur /= UINT32_C(1000); /* Convert to ms */
|
tph_dur /= UINT32_C(1000); /* Convert to ms */
|
||||||
|
|
||||||
tph_dur += UINT32_C(1); /* Wake up duration of 1ms */
|
tph_dur += UINT32_C(1); /* Wake up duration of 1ms */
|
||||||
|
|
||||||
|
*duration = (uint16_t) tph_dur;
|
||||||
|
|
||||||
|
/* Get the gas duration only when the run gas is enabled */
|
||||||
|
if (dev->gas_sett.run_gas) {
|
||||||
/* The remaining time should be used for heating */
|
/* The remaining time should be used for heating */
|
||||||
*duration = dev->gas_sett.heatr_dur + (uint16_t) tph_dur;
|
*duration += dev->gas_sett.heatr_dur;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -650,6 +666,7 @@ static int8_t get_calib_data(struct bme680_dev *dev)
|
|||||||
{
|
{
|
||||||
int8_t rslt;
|
int8_t rslt;
|
||||||
uint8_t coeff_array[BME680_COEFF_SIZE] = { 0 };
|
uint8_t coeff_array[BME680_COEFF_SIZE] = { 0 };
|
||||||
|
uint8_t temp_var = 0; /* Temporary variable */
|
||||||
|
|
||||||
/* Check for null pointer in the device structure*/
|
/* Check for null pointer in the device structure*/
|
||||||
rslt = null_ptr_check(dev);
|
rslt = null_ptr_check(dev);
|
||||||
@ -657,8 +674,8 @@ static int8_t get_calib_data(struct bme680_dev *dev)
|
|||||||
rslt = bme680_get_regs(BME680_COEFF_ADDR1, coeff_array, BME680_COEFF_ADDR1_LEN, dev);
|
rslt = bme680_get_regs(BME680_COEFF_ADDR1, coeff_array, BME680_COEFF_ADDR1_LEN, dev);
|
||||||
/* Append the second half in the same array */
|
/* Append the second half in the same array */
|
||||||
if (rslt == BME680_OK)
|
if (rslt == BME680_OK)
|
||||||
rslt = bme680_get_regs(BME680_COEFF_ADDR2, &coeff_array[BME680_COEFF_ADDR1_LEN], BME680_COEFF_ADDR2_LEN,
|
rslt = bme680_get_regs(BME680_COEFF_ADDR2, &coeff_array[BME680_COEFF_ADDR1_LEN]
|
||||||
dev);
|
, BME680_COEFF_ADDR2_LEN, dev);
|
||||||
|
|
||||||
/* Temperature related coefficients */
|
/* Temperature related coefficients */
|
||||||
dev->calib.par_t1 = (uint16_t) (BME680_CONCAT_BYTES(coeff_array[BME680_T1_MSB_REG],
|
dev->calib.par_t1 = (uint16_t) (BME680_CONCAT_BYTES(coeff_array[BME680_T1_MSB_REG],
|
||||||
@ -703,8 +720,6 @@ static int8_t get_calib_data(struct bme680_dev *dev)
|
|||||||
dev->calib.par_gh3 = (int8_t) coeff_array[BME680_GH3_REG];
|
dev->calib.par_gh3 = (int8_t) coeff_array[BME680_GH3_REG];
|
||||||
|
|
||||||
/* Other coefficients */
|
/* Other coefficients */
|
||||||
uint8_t temp_var = 0; /* Temporary variable */
|
|
||||||
|
|
||||||
if (rslt == BME680_OK) {
|
if (rslt == BME680_OK) {
|
||||||
rslt = bme680_get_regs(BME680_ADDR_RES_HEAT_RANGE_ADDR, &temp_var, 1, dev);
|
rslt = bme680_get_regs(BME680_ADDR_RES_HEAT_RANGE_ADDR, &temp_var, 1, dev);
|
||||||
|
|
||||||
@ -734,7 +749,8 @@ static int8_t set_gas_config(struct bme680_dev *dev)
|
|||||||
rslt = null_ptr_check(dev);
|
rslt = null_ptr_check(dev);
|
||||||
if (rslt == BME680_OK) {
|
if (rslt == BME680_OK) {
|
||||||
|
|
||||||
uint8_t reg_addr[2], reg_data[2];
|
uint8_t reg_addr[2] = {0};
|
||||||
|
uint8_t reg_data[2] = {0};
|
||||||
|
|
||||||
if (dev->power_mode == BME680_FORCED_MODE) {
|
if (dev->power_mode == BME680_FORCED_MODE) {
|
||||||
reg_addr[0] = BME680_RES_HEAT0_ADDR;
|
reg_addr[0] = BME680_RES_HEAT0_ADDR;
|
||||||
@ -800,12 +816,12 @@ static int16_t calc_temperature(uint32_t temp_adc, struct bme680_dev *dev)
|
|||||||
int64_t var3;
|
int64_t var3;
|
||||||
int16_t calc_temp;
|
int16_t calc_temp;
|
||||||
|
|
||||||
var1 = ((int32_t) temp_adc / 8) - ((int32_t) dev->calib.par_t1 * 2);
|
var1 = ((int32_t) temp_adc >> 3) - ((int32_t) dev->calib.par_t1 << 1);
|
||||||
var2 = (var1 * (int32_t) dev->calib.par_t2) / 2048;
|
var2 = (var1 * (int32_t) dev->calib.par_t2) >> 11;
|
||||||
var3 = ((var1 / 2) * (var1 / 2)) / 4096;
|
var3 = ((var1 >> 1) * (var1 >> 1)) >> 12;
|
||||||
var3 = ((var3) * ((int32_t) dev->calib.par_t3 * 16)) / 16384;
|
var3 = ((var3) * ((int32_t) dev->calib.par_t3 << 4)) >> 14;
|
||||||
dev->calib.t_fine = (int32_t) (var2 + var3);
|
dev->calib.t_fine = (int32_t) (var2 + var3);
|
||||||
calc_temp = (int16_t) (((dev->calib.t_fine * 5) + 128) / 256);
|
calc_temp = (int16_t) (((dev->calib.t_fine * 5) + 128) >> 8);
|
||||||
|
|
||||||
return calc_temp;
|
return calc_temp;
|
||||||
}
|
}
|
||||||
@ -815,30 +831,42 @@ static int16_t calc_temperature(uint32_t temp_adc, struct bme680_dev *dev)
|
|||||||
*/
|
*/
|
||||||
static uint32_t calc_pressure(uint32_t pres_adc, const struct bme680_dev *dev)
|
static uint32_t calc_pressure(uint32_t pres_adc, const struct bme680_dev *dev)
|
||||||
{
|
{
|
||||||
int32_t var1;
|
int32_t var1 = 0;
|
||||||
int32_t var2;
|
int32_t var2 = 0;
|
||||||
int32_t var3;
|
int32_t var3 = 0;
|
||||||
int32_t calc_pres;
|
int32_t var4 = 0;
|
||||||
|
int32_t pressure_comp = 0;
|
||||||
|
|
||||||
var1 = (((int32_t) dev->calib.t_fine) / 2) - 64000;
|
var1 = (((int32_t)dev->calib.t_fine) >> 1) - 64000;
|
||||||
var2 = ((var1 / 4) * (var1 / 4)) / 2048;
|
var2 = ((((var1 >> 2) * (var1 >> 2)) >> 11) *
|
||||||
var2 = ((var2) * (int32_t) dev->calib.par_p6) / 4;
|
(int32_t)dev->calib.par_p6) >> 2;
|
||||||
var2 = var2 + ((var1 * (int32_t) dev->calib.par_p5) * 2);
|
var2 = var2 + ((var1 * (int32_t)dev->calib.par_p5) << 1);
|
||||||
var2 = (var2 / 4) + ((int32_t) dev->calib.par_p4 * 65536);
|
var2 = (var2 >> 2) + ((int32_t)dev->calib.par_p4 << 16);
|
||||||
var1 = ((var1 / 4) * (var1 / 4)) / 8192;
|
var1 = (((((var1 >> 2) * (var1 >> 2)) >> 13) *
|
||||||
var1 = (((var1) * ((int32_t) dev->calib.par_p3 * 32)) / 8) + (((int32_t) dev->calib.par_p2 * var1) / 2);
|
((int32_t)dev->calib.par_p3 << 5)) >> 3) +
|
||||||
var1 = var1 / 262144;
|
(((int32_t)dev->calib.par_p2 * var1) >> 1);
|
||||||
var1 = ((32768 + var1) * (int32_t) dev->calib.par_p1) / 32768;
|
var1 = var1 >> 18;
|
||||||
calc_pres = (int32_t) (1048576 - pres_adc);
|
var1 = ((32768 + var1) * (int32_t)dev->calib.par_p1) >> 15;
|
||||||
calc_pres = (int32_t) ((calc_pres - (var2 / 4096)) * (3125));
|
pressure_comp = 1048576 - pres_adc;
|
||||||
calc_pres = ((calc_pres / var1) * 2);
|
pressure_comp = (int32_t)((pressure_comp - (var2 >> 12)) * ((uint32_t)3125));
|
||||||
var1 = ((int32_t) dev->calib.par_p9 * (int32_t) (((calc_pres / 8) * (calc_pres / 8)) / 8192)) / 4096;
|
var4 = (1 << 31);
|
||||||
var2 = ((int32_t) (calc_pres / 4) * (int32_t) dev->calib.par_p8) / 8192;
|
if (pressure_comp >= var4)
|
||||||
var3 = ((int32_t) (calc_pres / 256) * (int32_t) (calc_pres / 256) * (int32_t) (calc_pres / 256)
|
pressure_comp = ((pressure_comp / (uint32_t)var1) << 1);
|
||||||
* (int32_t) dev->calib.par_p10) / 131072;
|
else
|
||||||
calc_pres = (int32_t) (calc_pres) + ((var1 + var2 + var3 + ((int32_t) dev->calib.par_p7 * 128)) / 16);
|
pressure_comp = ((pressure_comp << 1) / (uint32_t)var1);
|
||||||
|
var1 = ((int32_t)dev->calib.par_p9 * (int32_t)(((pressure_comp >> 3) *
|
||||||
|
(pressure_comp >> 3)) >> 13)) >> 12;
|
||||||
|
var2 = ((int32_t)(pressure_comp >> 2) *
|
||||||
|
(int32_t)dev->calib.par_p8) >> 13;
|
||||||
|
var3 = ((int32_t)(pressure_comp >> 8) * (int32_t)(pressure_comp >> 8) *
|
||||||
|
(int32_t)(pressure_comp >> 8) *
|
||||||
|
(int32_t)dev->calib.par_p10) >> 17;
|
||||||
|
|
||||||
|
pressure_comp = (int32_t)(pressure_comp) + ((var1 + var2 + var3 +
|
||||||
|
((int32_t)dev->calib.par_p7 << 7)) >> 4);
|
||||||
|
|
||||||
|
return (uint32_t)pressure_comp;
|
||||||
|
|
||||||
return (uint32_t) calc_pres;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -855,19 +883,19 @@ static uint32_t calc_humidity(uint16_t hum_adc, const struct bme680_dev *dev)
|
|||||||
int32_t temp_scaled;
|
int32_t temp_scaled;
|
||||||
int32_t calc_hum;
|
int32_t calc_hum;
|
||||||
|
|
||||||
temp_scaled = (((int32_t) dev->calib.t_fine * 5) + 128) / 256;
|
temp_scaled = (((int32_t) dev->calib.t_fine * 5) + 128) >> 8;
|
||||||
var1 = (int32_t) (hum_adc - ((int32_t) ((int32_t) dev->calib.par_h1 * 16)))
|
var1 = (int32_t) (hum_adc - ((int32_t) ((int32_t) dev->calib.par_h1 * 16)))
|
||||||
- (((temp_scaled * (int32_t) dev->calib.par_h3) / ((int32_t) 100)) / 2);
|
- (((temp_scaled * (int32_t) dev->calib.par_h3) / ((int32_t) 100)) >> 1);
|
||||||
var2 = ((int32_t) dev->calib.par_h2
|
var2 = ((int32_t) dev->calib.par_h2
|
||||||
* (((temp_scaled * (int32_t) dev->calib.par_h4) / ((int32_t) 100))
|
* (((temp_scaled * (int32_t) dev->calib.par_h4) / ((int32_t) 100))
|
||||||
+ (((temp_scaled * ((temp_scaled * (int32_t) dev->calib.par_h5) / ((int32_t) 100))) / 64)
|
+ (((temp_scaled * ((temp_scaled * (int32_t) dev->calib.par_h5) / ((int32_t) 100))) >> 6)
|
||||||
/ ((int32_t) 100)) + (int32_t) (1 * 16384))) / 1024;
|
/ ((int32_t) 100)) + (int32_t) (1 << 14))) >> 10;
|
||||||
var3 = var1 * var2;
|
var3 = var1 * var2;
|
||||||
var4 = (int32_t) dev->calib.par_h6 * 128;
|
var4 = (int32_t) dev->calib.par_h6 << 7;
|
||||||
var4 = ((var4) + ((temp_scaled * (int32_t) dev->calib.par_h7) / ((int32_t) 100))) / 16;
|
var4 = ((var4) + ((temp_scaled * (int32_t) dev->calib.par_h7) / ((int32_t) 100))) >> 4;
|
||||||
var5 = ((var3 / 16384) * (var3 / 16384)) / 1024;
|
var5 = ((var3 >> 14) * (var3 >> 14)) >> 10;
|
||||||
var6 = (var4 * var5) / 2;
|
var6 = (var4 * var5) >> 1;
|
||||||
calc_hum = (((var3 + var6) / 1024) * ((int32_t) 1000)) / 4096;
|
calc_hum = (((var3 + var6) >> 10) * ((int32_t) 1000)) >> 12;
|
||||||
|
|
||||||
if (calc_hum > 100000) /* Cap at 100%rH */
|
if (calc_hum > 100000) /* Cap at 100%rH */
|
||||||
calc_hum = 100000;
|
calc_hum = 100000;
|
||||||
@ -887,10 +915,11 @@ static uint32_t calc_gas_resistance(uint16_t gas_res_adc, uint8_t gas_range, con
|
|||||||
int64_t var3;
|
int64_t var3;
|
||||||
uint32_t calc_gas_res;
|
uint32_t calc_gas_res;
|
||||||
|
|
||||||
var1 = (int64_t) ((1340 + (5 * (int64_t) dev->calib.range_sw_err)) * ((int64_t) lookupTable1[gas_range])) / 65536;
|
var1 = (int64_t) ((1340 + (5 * (int64_t) dev->calib.range_sw_err)) *
|
||||||
var2 = (((int64_t) ((int64_t) gas_res_adc * 32768) - (int64_t) (16777216)) + var1);
|
((int64_t) lookupTable1[gas_range])) >> 16;
|
||||||
var3 = (((int64_t) lookupTable2[gas_range] * (int64_t) var1) / 512);
|
var2 = (((int64_t) ((int64_t) gas_res_adc << 15) - (int64_t) (16777216)) + var1);
|
||||||
calc_gas_res = (uint32_t) ((var3 + ((int64_t) var2 / 2)) / (int64_t) var2);
|
var3 = (((int64_t) lookupTable2[gas_range] * (int64_t) var1) >> 9);
|
||||||
|
calc_gas_res = (uint32_t) ((var3 + ((int64_t) var2 >> 1)) / (int64_t) var2);
|
||||||
|
|
||||||
return calc_gas_res;
|
return calc_gas_res;
|
||||||
}
|
}
|
||||||
@ -963,15 +992,18 @@ static int8_t read_field_data(struct bme680_field_data *data, struct bme680_dev
|
|||||||
rslt = null_ptr_check(dev);
|
rslt = null_ptr_check(dev);
|
||||||
do {
|
do {
|
||||||
if (rslt == BME680_OK) {
|
if (rslt == BME680_OK) {
|
||||||
rslt = bme680_get_regs(((uint8_t) (BME680_FIELD0_ADDR)), buff, (uint16_t) BME680_FIELD_LENGTH, dev);
|
rslt = bme680_get_regs(((uint8_t) (BME680_FIELD0_ADDR)), buff, (uint16_t) BME680_FIELD_LENGTH,
|
||||||
|
dev);
|
||||||
|
|
||||||
data->status = buff[0] & BME680_NEW_DATA_MSK;
|
data->status = buff[0] & BME680_NEW_DATA_MSK;
|
||||||
data->gas_index = buff[0] & BME680_GAS_INDEX_MSK;
|
data->gas_index = buff[0] & BME680_GAS_INDEX_MSK;
|
||||||
data->meas_index = buff[1];
|
data->meas_index = buff[1];
|
||||||
|
|
||||||
/* read the raw data from the sensor */
|
/* read the raw data from the sensor */
|
||||||
adc_pres = (uint32_t) (((uint32_t) buff[2] * 4096) | ((uint32_t) buff[3] * 16) | ((uint32_t) buff[4] / 16));
|
adc_pres = (uint32_t) (((uint32_t) buff[2] * 4096) | ((uint32_t) buff[3] * 16)
|
||||||
adc_temp = (uint32_t) (((uint32_t) buff[5] * 4096) | ((uint32_t) buff[6] * 16) | ((uint32_t) buff[7] / 16));
|
| ((uint32_t) buff[4] / 16));
|
||||||
|
adc_temp = (uint32_t) (((uint32_t) buff[5] * 4096) | ((uint32_t) buff[6] * 16)
|
||||||
|
| ((uint32_t) buff[7] / 16));
|
||||||
adc_hum = (uint16_t) (((uint32_t) buff[8] * 256) | (uint32_t) buff[9]);
|
adc_hum = (uint16_t) (((uint32_t) buff[8] * 256) | (uint32_t) buff[9]);
|
||||||
adc_gas_res = (uint16_t) ((uint32_t) buff[13] * 4 | (((uint32_t) buff[14]) / 64));
|
adc_gas_res = (uint16_t) ((uint32_t) buff[13] * 4 | (((uint32_t) buff[14]) / 64));
|
||||||
gas_range = buff[14] & BME680_GAS_RANGE_MSK;
|
gas_range = buff[14] & BME680_GAS_RANGE_MSK;
|
||||||
@ -985,9 +1017,9 @@ static int8_t read_field_data(struct bme680_field_data *data, struct bme680_dev
|
|||||||
data->humidity = calc_humidity(adc_hum, dev);
|
data->humidity = calc_humidity(adc_hum, dev);
|
||||||
data->gas_resistance = calc_gas_resistance(adc_gas_res, gas_range, dev);
|
data->gas_resistance = calc_gas_resistance(adc_gas_res, gas_range, dev);
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
dev->delay_ms(BME680_POLL_PERIOD_MS);
|
|
||||||
}
|
}
|
||||||
|
/* Delay to poll the data */
|
||||||
|
dev->delay_ms(BME680_POLL_PERIOD_MS);
|
||||||
}
|
}
|
||||||
tries--;
|
tries--;
|
||||||
} while (tries);
|
} while (tries);
|
||||||
@ -1026,7 +1058,8 @@ static int8_t set_mem_page(uint8_t reg_addr, struct bme680_dev *dev)
|
|||||||
reg = reg & (~BME680_MEM_PAGE_MSK);
|
reg = reg & (~BME680_MEM_PAGE_MSK);
|
||||||
reg = reg | (dev->mem_page & BME680_MEM_PAGE_MSK);
|
reg = reg | (dev->mem_page & BME680_MEM_PAGE_MSK);
|
||||||
|
|
||||||
dev->com_rslt = dev->write(dev->dev_id, BME680_MEM_PAGE_ADDR & BME680_SPI_WR_MSK, ®, 1);
|
dev->com_rslt = dev->write(dev->dev_id, BME680_MEM_PAGE_ADDR & BME680_SPI_WR_MSK,
|
||||||
|
®, 1);
|
||||||
if (dev->com_rslt != 0)
|
if (dev->com_rslt != 0)
|
||||||
rslt = BME680_E_COM_FAIL;
|
rslt = BME680_E_COM_FAIL;
|
||||||
}
|
}
|
||||||
|
8
bme680.h
8
bme680.h
@ -40,8 +40,8 @@
|
|||||||
* patent rights of the copyright holder.
|
* patent rights of the copyright holder.
|
||||||
*
|
*
|
||||||
* @file bme680.h
|
* @file bme680.h
|
||||||
* @date 5 Jul 2017
|
* @date 30 Oct 2017
|
||||||
* @version 3.5.1
|
* @version 3.5.3
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -162,7 +162,7 @@ void bme680_set_profile_dur(uint16_t duration, struct bme680_dev *dev);
|
|||||||
*
|
*
|
||||||
* @return Nothing
|
* @return Nothing
|
||||||
*/
|
*/
|
||||||
void bme680_get_profile_dur(uint16_t *duration, struct bme680_dev *dev);
|
void bme680_get_profile_dur(uint16_t *duration, const struct bme680_dev *dev);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief This API reads the pressure, temperature and humidity and gas data
|
* @brief This API reads the pressure, temperature and humidity and gas data
|
||||||
@ -186,7 +186,7 @@ int8_t bme680_get_sensor_data(struct bme680_field_data *data, struct bme680_dev
|
|||||||
* are to be set in the sensor.
|
* are to be set in the sensor.
|
||||||
*
|
*
|
||||||
* Macros | Functionality
|
* Macros | Functionality
|
||||||
*-------------------------|----------------------------------------------
|
*---------------------------------|----------------------------------------------
|
||||||
* BME680_OST_SEL | To set temperature oversampling.
|
* BME680_OST_SEL | To set temperature oversampling.
|
||||||
* BME680_OSP_SEL | To set pressure oversampling.
|
* BME680_OSP_SEL | To set pressure oversampling.
|
||||||
* BME680_OSH_SEL | To set humidity oversampling.
|
* BME680_OSH_SEL | To set humidity oversampling.
|
||||||
|
@ -40,8 +40,8 @@
|
|||||||
* patent rights of the copyright holder.
|
* patent rights of the copyright holder.
|
||||||
*
|
*
|
||||||
* @file bme680_defs.h
|
* @file bme680_defs.h
|
||||||
* @date 5 Jul 2017
|
* @date 30 Oct 2017
|
||||||
* @version 3.5.1
|
* @version 3.5.3
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -59,55 +59,36 @@
|
|||||||
/* header includes */
|
/* header includes */
|
||||||
#ifdef __KERNEL__
|
#ifdef __KERNEL__
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
|
#include <linux/kernel.h>
|
||||||
#else
|
#else
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __KERNEL__
|
/******************************************************************************/
|
||||||
#if (LONG_MAX) > 0x7fffffff
|
/*! @name Common macros */
|
||||||
#define __have_long64 1
|
/******************************************************************************/
|
||||||
#elif (LONG_MAX) == 0x7fffffff
|
|
||||||
#define __have_long32 1
|
#if !defined(UINT8_C) && !defined(INT8_C)
|
||||||
|
#define INT8_C(x) S8_C(x)
|
||||||
|
#define UINT8_C(x) U8_C(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(UINT8_C)
|
#if !defined(UINT16_C) && !defined(INT16_C)
|
||||||
#define INT8_C(x) x
|
#define INT16_C(x) S16_C(x)
|
||||||
#if (INT_MAX) > 0x7f
|
#define UINT16_C(x) U16_C(x)
|
||||||
#define UINT8_C(x) x
|
|
||||||
#else
|
|
||||||
#define UINT8_C(x) x##U
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(UINT16_C)
|
|
||||||
#define INT16_C(x) x
|
|
||||||
#if (INT_MAX) > 0x7fff
|
|
||||||
#define UINT16_C(x) x
|
|
||||||
#else
|
|
||||||
#define UINT16_C(x) x##U
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(INT32_C) && !defined(UINT32_C)
|
#if !defined(INT32_C) && !defined(UINT32_C)
|
||||||
#if __have_long32
|
#define INT32_C(x) S32_C(x)
|
||||||
#define INT32_C(x) x##L
|
#define UINT32_C(x) U32_C(x)
|
||||||
#define UINT32_C(x) x##UL
|
|
||||||
#else
|
|
||||||
#define INT32_C(x) x
|
|
||||||
#define UINT32_C(x) x##U
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(INT64_C) && !defined(UINT64_C)
|
#if !defined(INT64_C) && !defined(UINT64_C)
|
||||||
#if __have_long64
|
#define INT64_C(x) S64_C(x)
|
||||||
#define INT64_C(x) x##L
|
#define UINT64_C(x) U64_C(x)
|
||||||
#define UINT64_C(x) x##UL
|
|
||||||
#else
|
|
||||||
#define INT64_C(x) x##LL
|
|
||||||
#define UINT64_C(x) x##ULL
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
||||||
/**\name C standard macros */
|
/**\name C standard macros */
|
||||||
@ -250,7 +231,7 @@
|
|||||||
#define BME680_HCNTRL_SEL UINT16_C(32)
|
#define BME680_HCNTRL_SEL UINT16_C(32)
|
||||||
#define BME680_RUN_GAS_SEL UINT16_C(64)
|
#define BME680_RUN_GAS_SEL UINT16_C(64)
|
||||||
#define BME680_NBCONV_SEL UINT16_C(128)
|
#define BME680_NBCONV_SEL UINT16_C(128)
|
||||||
#define BME680_GAS_SENSOR_SEL UINT16_C(BME680_GAS_MEAS_SEL | BME680_RUN_GAS_SEL | BME680_NBCONV_SEL)
|
#define BME680_GAS_SENSOR_SEL (BME680_GAS_MEAS_SEL | BME680_RUN_GAS_SEL | BME680_NBCONV_SEL)
|
||||||
|
|
||||||
/** Number of conversion settings*/
|
/** Number of conversion settings*/
|
||||||
#define BME680_NBCONV_MIN UINT8_C(0)
|
#define BME680_NBCONV_MIN UINT8_C(0)
|
||||||
@ -524,6 +505,8 @@ struct bme680_dev {
|
|||||||
int8_t com_rslt;
|
int8_t com_rslt;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* BME680_DEFS_H_ */
|
#endif /* BME680_DEFS_H_ */
|
||||||
/** @}*/
|
/** @}*/
|
||||||
/** @}*/
|
/** @}*/
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
All notable changes to the BME680 Sensor API will be documented in this file.
|
All notable changes to the BME680 Sensor API will be documented in this file.
|
||||||
|
## v3.5.3, 30 Oct 2017
|
||||||
|
### Changed
|
||||||
|
- Changed the compensation equation formulae to use shifting operation
|
||||||
|
- Updated the "bme680_get_profile_dur" API
|
||||||
|
- Fixed Checkpatch and made linux compatible
|
||||||
|
|
||||||
|
## v3.5.2, 18 Oct 2017
|
||||||
|
### Changed
|
||||||
|
- Fixed bug of temperature compensation in pressure
|
||||||
|
|
||||||
## v3.5.1, 5 Jul 2017
|
## v3.5.1, 5 Jul 2017
|
||||||
### Changed
|
### Changed
|
||||||
|
Loading…
Reference in New Issue
Block a user