From f99a8f84db6c052ed0d94a978ba1b132f3bb5f77 Mon Sep 17 00:00:00 2001 From: Maharavan Sundaram Date: Thu, 28 Aug 2025 14:20:42 +0530 Subject: [PATCH] BME690 v1.0.3 --- bme69x.c | 52 +++++++++++++++++++--- bme69x.h | 6 +-- bme69x_defs.h | 6 +-- examples/common/common.c | 2 +- examples/common/common.h | 2 +- examples/forced_mode/forced_mode.c | 4 +- examples/parallel_mode/parallel_mode.c | 2 +- examples/self_test/self_test.c | 2 +- examples/sequential_mode/sequential_mode.c | 4 +- 9 files changed, 60 insertions(+), 20 deletions(-) diff --git a/bme69x.c b/bme69x.c index 2cda92a..cfbc82d 100644 --- a/bme69x.c +++ b/bme69x.c @@ -1,5 +1,5 @@ /** -* Copyright (c) 2024 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2025 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bme69x.c -* @date 2024-05-14 -* @version v1.0.1 +* @date 2025-07-15 +* @version v1.0.3 * */ @@ -905,6 +905,17 @@ static uint32_t calc_humidity(uint16_t hum_adc, int16_t comp_temperature, const 2097152ULL) * dev->calib.par_h5 + 8192UL) / 16384UL); var_H = var_H - (((((var_H / 32768UL) * (var_H / 32768UL)) / 128UL) * dev->calib.par_h6) / 16UL); + + if (var_H < 0) + { + var_H = 0; + } + + if (var_H > 419430400) + { + var_H = 419430400; + } + hum_comp = (uint32_t)(var_H / 4096UL); return hum_comp; @@ -1027,7 +1038,8 @@ static float calc_humidity(uint16_t hum_adc, float comp_temperature, const struc double oh, tk10h, sh; double tk1sh, tk2sh, hlin2; double hoff, hsens; - double temp_comp, calc_hum, temp_var_1; + double temp_comp, calc_hum, hum_float_val; + int32_t hum_int_val; temp_comp = (comp_temperature * 5120) - 76800; @@ -1040,8 +1052,21 @@ static float calc_humidity(uint16_t hum_adc, float comp_temperature, const struc hoff = (double)hum_adc - (oh + tk10h * temp_comp); hsens = hoff * sh * (1 + (tk1sh * temp_comp) + (tk1sh * tk2sh * temp_comp * temp_comp)); - temp_var_1 = hsens * (1 - hlin2 * hsens); - calc_hum = temp_var_1; + hum_float_val = hsens * (1 - hlin2 * hsens); + + /* Avoid direct floating-point comparison by using integer scaling */ + hum_int_val = (int32_t)(hum_float_val * 1000.0f); + + if (hum_int_val >= 100000) + { + hum_float_val = 100.0; + } + else if (hum_int_val < 0) + { + hum_float_val = 0.0; + } + + calc_hum = hum_float_val; return (float)calc_hum; } @@ -1721,8 +1746,23 @@ static int8_t get_calib_data(struct bme69x_dev *dev) /* Humidity related coefficients */ dev->calib.par_h5 = (int16_t)(((int16_t)coeff_array[BME69X_IDX_S_H_MSB] << 4) | (coeff_array[BME69X_IDX_S_H_LSB] >> 4)); + + if (dev->calib.par_h5 > 2047) + { + /* Convert to negative value */ + dev->calib.par_h5 = (int16_t)(dev->calib.par_h5 - 4096); + } + dev->calib.par_h1 = (int16_t)(((int16_t)coeff_array[BME69X_IDX_O_H_MSB] << 4) | (coeff_array[BME69X_IDX_O_H_LSB] & 0x0F)); + + /* Check if the value is above 2047 */ + if (dev->calib.par_h1 > 2047) + { + /* Convert to negative value */ + dev->calib.par_h1 = (int16_t)(dev->calib.par_h1 - 4096); + } + dev->calib.par_h2 = (int8_t)coeff_array[BME69X_IDX_TK10H_C]; dev->calib.par_h4 = (int8_t)coeff_array[BME69X_IDX_par_h4]; dev->calib.par_h3 = (uint8_t)coeff_array[BME69X_IDX_par_h3]; diff --git a/bme69x.h b/bme69x.h index 4f54f22..4525615 100644 --- a/bme69x.h +++ b/bme69x.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2024 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2025 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bme69x.h -* @date 2024-05-14 -* @version v1.0.1 +* @date 2025-07-15 +* @version v1.0.3 * */ diff --git a/bme69x_defs.h b/bme69x_defs.h index 49c3109..58ccb6e 100644 --- a/bme69x_defs.h +++ b/bme69x_defs.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2024 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2025 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bme69x_defs.h -* @date 2024-05-14 -* @version v1.0.1 +* @date 2025-07-15 +* @version v1.0.3 * */ diff --git a/examples/common/common.c b/examples/common/common.c index 66372bd..7dd1f94 100644 --- a/examples/common/common.c +++ b/examples/common/common.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2024 Bosch Sensortec GmbH. All rights reserved. + * Copyright (C) 2025 Bosch Sensortec GmbH. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ diff --git a/examples/common/common.h b/examples/common/common.h index c014b14..f8295e6 100644 --- a/examples/common/common.h +++ b/examples/common/common.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2024 Bosch Sensortec GmbH. All rights reserved. + * Copyright (C) 2025 Bosch Sensortec GmbH. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ diff --git a/examples/forced_mode/forced_mode.c b/examples/forced_mode/forced_mode.c index 1cb57e7..3be953c 100644 --- a/examples/forced_mode/forced_mode.c +++ b/examples/forced_mode/forced_mode.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2024 Bosch Sensortec GmbH + * Copyright (C) 2025 Bosch Sensortec GmbH * * SPDX-License-Identifier: BSD-3-Clause * @@ -38,7 +38,7 @@ int main(void) * For I2C : BME69X_I2C_INTF * For SPI : BME69X_SPI_INTF */ - rslt = bme69x_interface_init(&bme, BME69X_I2C_INTF); + rslt = bme69x_interface_init(&bme, BME69X_SPI_INTF); bme69x_check_rslt("bme69x_interface_init", rslt); rslt = bme69x_init(&bme); diff --git a/examples/parallel_mode/parallel_mode.c b/examples/parallel_mode/parallel_mode.c index e06cee3..ebd2a47 100644 --- a/examples/parallel_mode/parallel_mode.c +++ b/examples/parallel_mode/parallel_mode.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2024 Bosch Sensortec GmbH + * Copyright (C) 2025 Bosch Sensortec GmbH * * SPDX-License-Identifier: BSD-3-Clause * diff --git a/examples/self_test/self_test.c b/examples/self_test/self_test.c index 62dea75..f865d58 100644 --- a/examples/self_test/self_test.c +++ b/examples/self_test/self_test.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2024 Bosch Sensortec GmbH + * Copyright (C) 2025 Bosch Sensortec GmbH * * SPDX-License-Identifier: BSD-3-Clause * diff --git a/examples/sequential_mode/sequential_mode.c b/examples/sequential_mode/sequential_mode.c index 090a548..dd499b6 100644 --- a/examples/sequential_mode/sequential_mode.c +++ b/examples/sequential_mode/sequential_mode.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2024 Bosch Sensortec GmbH + * Copyright (C) 2025 Bosch Sensortec GmbH * * SPDX-License-Identifier: BSD-3-Clause * @@ -44,7 +44,7 @@ int main(void) * For I2C : BME69X_I2C_INTF * For SPI : BME69X_SPI_INTF */ - rslt = bme69x_interface_init(&bme, BME69X_I2C_INTF); + rslt = bme69x_interface_init(&bme, BME69X_SPI_INTF); bme69x_check_rslt("bme69x_interface_init", rslt); rslt = bme69x_init(&bme);