diff --git a/examples/bme688_dev_kit/bme688_dev_kit.ino b/examples/bme688_dev_kit/bme688_dev_kit.ino index 2c6ee1b..e4c5cda 100644 --- a/examples/bme688_dev_kit/bme688_dev_kit.ino +++ b/examples/bme688_dev_kit/bme688_dev_kit.ino @@ -15,16 +15,15 @@ */ #include "Arduino.h" -#include "FS.h" #include "bme68xLibrary.h" #include "commMux.h" -#include + +#include +#include /* Macros used in BME68x_datalogger module */ #define N_KIT_SENS 8 #define SD_PIN_CS 33 -#define SPI_COMM_SPEED 32000000 -#define SD_MAX_FILES 5 #define PANIC_LED LED_BUILTIN #define PANIC_DUR 1000 /* measurement duration */ @@ -39,6 +38,8 @@ bme68xData sensorData[N_KIT_SENS] = {0}; String logHeader; uint32_t lastLogged = 0; +static SdFat sd; + /** * @brief Initializes the sensor and hardware settings * Initializes the SD card module @@ -51,13 +52,14 @@ void setup(void) { delay(100); /* Setting SD Card */ - if (!SD.begin(SD_PIN_CS, SPI, SPI_COMM_SPEED, "/sd", SD_MAX_FILES)) { + if (!sd.begin(SD_PIN_CS, SPI_EIGHTH_SPEED)) { Serial.println("SD Card not found"); panicLeds(); } else { - SD.remove(LOG_FILE_NAME); - File file = SD.open(LOG_FILE_NAME, "w"); - if (!file) { + sd.remove(LOG_FILE_NAME); + File file; + + if (!file.open(LOG_FILE_NAME, (O_RDWR | O_CREAT))) { Serial.println("Failed to open file for writing"); panicLeds(); } @@ -97,7 +99,7 @@ void setup(void) { uint16_t mulProf[10] = {5, 2, 10, 30, 5, 5, 5, 5, 5, 5}; /* Shared heating duration in milliseconds */ uint16_t sharedHeatrDur = - MEAS_DUR - bme[i].getMeasDur(BME68X_PARALLEL_MODE); + MEAS_DUR - (bme[i].getMeasDur(BME68X_PARALLEL_MODE) / INT64_C(1000)); bme[i].setHeaterProf(tempProf, mulProf, sharedHeatrDur, 10); @@ -196,8 +198,9 @@ static void panicLeds(void) { */ static void writeFile(String sensorData) { - File file = SD.open(LOG_FILE_NAME, FILE_WRITE); - if (!file) { + File file; + + if (!file.open(LOG_FILE_NAME, (O_RDWR | O_AT_END))) { Serial.println("Failed to open file for writing"); panicLeds(); } @@ -214,8 +217,9 @@ static void writeFile(String sensorData) { * @param sensorData */ static void appendFile(String sensorData) { - File file = SD.open(LOG_FILE_NAME, FILE_APPEND); - if (!file) { + File file; + + if (!file.open(LOG_FILE_NAME, (O_RDWR | O_AT_END))) { Serial.println("Failed to open file for appending"); panicLeds(); } diff --git a/examples/bme688_dev_kit/commMux.cpp b/examples/bme688_dev_kit/commMux.cpp index 54a2b3c..46ff285 100644 --- a/examples/bme688_dev_kit/commMux.cpp +++ b/examples/bme688_dev_kit/commMux.cpp @@ -31,8 +31,8 @@ POSSIBILITY OF SUCH DAMAGE. @file commMux.cpp - @date 8 Feb 2022 - @version 1.1.40407 + @date 11 Jan 2023 + @version 1.2.40408 */ diff --git a/examples/bme688_dev_kit/commMux.h b/examples/bme688_dev_kit/commMux.h index c3160bb..1237a45 100644 --- a/examples/bme688_dev_kit/commMux.h +++ b/examples/bme688_dev_kit/commMux.h @@ -31,8 +31,8 @@ POSSIBILITY OF SUCH DAMAGE. @file commMux.h - @date 8 Feb 2022 - @version 1.1.40407 + @date 11 Jan 2023 + @version 1.2.40408 */ #ifndef COMM_MUX_H diff --git a/library.properties b/library.properties index e344c60..a153af9 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=BME68x Sensor library -version=1.1.40407 +version=1.2.40408 author=Bosch Sensortec maintainer=Bosch Sensortec sentence=Bosch Sensortec BME680 and BME688 sensor library diff --git a/src/bme68x/LICENSE b/src/bme68x/LICENSE index 39d6442..3fe3a6b 100644 --- a/src/bme68x/LICENSE +++ b/src/bme68x/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved. +Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. BSD-3-Clause diff --git a/src/bme68x/bme68x.c b/src/bme68x/bme68x.c index 7c3c935..cd6965b 100644 --- a/src/bme68x/bme68x.c +++ b/src/bme68x/bme68x.c @@ -1,5 +1,5 @@ /** -* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bme68x.c -* @date 2021-11-09 -* @version v4.4.7 +* @date 2023-02-07 +* @version v4.4.8 * */ @@ -145,28 +145,27 @@ int8_t bme68x_init(struct bme68x_dev *dev) { int8_t rslt; - rslt = bme68x_soft_reset(dev); + (void) bme68x_soft_reset(dev); + + rslt = bme68x_get_regs(BME68X_REG_CHIP_ID, &dev->chip_id, 1, dev); + if (rslt == BME68X_OK) { - rslt = bme68x_get_regs(BME68X_REG_CHIP_ID, &dev->chip_id, 1, dev); - if (rslt == BME68X_OK) + if (dev->chip_id == BME68X_CHIP_ID) { - if (dev->chip_id == BME68X_CHIP_ID) - { - /* Read Variant ID */ - rslt = read_variant_id(dev); + /* Read Variant ID */ + rslt = read_variant_id(dev); - if (rslt == BME68X_OK) - { - /* Get the Calibration data */ - rslt = get_calib_data(dev); - } - } - else + if (rslt == BME68X_OK) { - rslt = BME68X_E_DEV_NOT_FOUND; + /* Get the Calibration data */ + rslt = get_calib_data(dev); } } + else + { + rslt = BME68X_E_DEV_NOT_FOUND; + } } return rslt; @@ -289,10 +288,11 @@ int8_t bme68x_soft_reset(struct bme68x_dev *dev) { rslt = bme68x_set_regs(®_addr, &soft_rst_cmd, 1, dev); - /* Wait for 5ms */ - dev->delay_us(BME68X_PERIOD_RESET, dev->intf_ptr); if (rslt == BME68X_OK) { + /* Wait for 5ms */ + dev->delay_us(BME68X_PERIOD_RESET, dev->intf_ptr); + /* After reset get the memory page */ if (dev->intf == BME68X_SPI_INTF) { @@ -681,39 +681,41 @@ int8_t bme68x_set_heatr_conf(uint8_t op_mode, const struct bme68x_heatr_conf *co return rslt; } -/* +/*! * @brief This API is used to get the gas configuration of the sensor. */ int8_t bme68x_get_heatr_conf(const struct bme68x_heatr_conf *conf, struct bme68x_dev *dev) { - int8_t rslt; + int8_t rslt = BME68X_OK; uint8_t data_array[10] = { 0 }; uint8_t i; - /* FIXME: Add conversion to deg C and ms and add the other parameters */ - rslt = bme68x_get_regs(BME68X_REG_RES_HEAT0, data_array, 10, dev); - if (rslt == BME68X_OK) + if ((conf != NULL) && (conf->heatr_dur_prof != NULL) && (conf->heatr_temp_prof != NULL)) { - if (conf && conf->heatr_dur_prof && conf->heatr_temp_prof) + /* FIXME: Add conversion to deg C and ms and add the other parameters */ + rslt = bme68x_get_regs(BME68X_REG_RES_HEAT0, data_array, 10, dev); + + if (rslt == BME68X_OK) { - for (i = 0; i < 10; i++) + for (i = 0; i < conf->profile_len; i++) { conf->heatr_temp_prof[i] = data_array[i]; } rslt = bme68x_get_regs(BME68X_REG_GAS_WAIT0, data_array, 10, dev); + if (rslt == BME68X_OK) { - for (i = 0; i < 10; i++) + for (i = 0; i < conf->profile_len; i++) { conf->heatr_dur_prof[i] = data_array[i]; } } } - else - { - rslt = BME68X_E_NULL_PTR; - } + } + else + { + rslt = BME68X_E_NULL_PTR; } return rslt; @@ -732,14 +734,21 @@ int8_t bme68x_selftest_check(const struct bme68x_dev *dev) struct bme68x_conf conf; struct bme68x_heatr_conf heatr_conf; - /* Copy required parameters from reference bme68x_dev struct */ - t_dev.amb_temp = 25; - t_dev.read = dev->read; - t_dev.write = dev->write; - t_dev.intf = dev->intf; - t_dev.delay_us = dev->delay_us; - t_dev.intf_ptr = dev->intf_ptr; - rslt = bme68x_init(&t_dev); + rslt = null_ptr_check(dev); + + if (rslt == BME68X_OK) + { + /* Copy required parameters from reference bme68x_dev struct */ + t_dev.amb_temp = 25; + t_dev.read = dev->read; + t_dev.write = dev->write; + t_dev.intf = dev->intf; + t_dev.delay_us = dev->delay_us; + t_dev.intf_ptr = dev->intf_ptr; + + rslt = bme68x_init(&t_dev); + } + if (rslt == BME68X_OK) { /* Set the temperature, pressure and humidity & filter settings */ @@ -974,7 +983,7 @@ static uint32_t calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range return calc_gas_res; } -/* This internal API is used to calculate the heater resistance value using float */ +/* This internal API is used to calculate the heater resistance value using integer */ static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev) { uint8_t heatr_res; @@ -1132,7 +1141,7 @@ static float calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range) return calc_gas_res; } -/* This internal API is used to calculate the heater resistance value */ +/* This internal API is used to calculate the heater resistance value using float */ static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev) { float var1; diff --git a/src/bme68x/bme68x.h b/src/bme68x/bme68x.h index e6d4828..89b58ed 100644 --- a/src/bme68x/bme68x.h +++ b/src/bme68x/bme68x.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bme68x.h -* @date 2021-11-09 -* @version v4.4.7 +* @date 2023-02-07 +* @version v4.4.8 * */ diff --git a/src/bme68x/bme68x_defs.h b/src/bme68x/bme68x_defs.h index 861b2f7..1ad1584 100644 --- a/src/bme68x/bme68x_defs.h +++ b/src/bme68x/bme68x_defs.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bme68x_defs.h -* @date 2021-11-09 -* @version v4.4.7 +* @date 2023-02-07 +* @version v4.4.8 * */ diff --git a/src/bme68xLibrary.cpp b/src/bme68xLibrary.cpp index 5d1010c..7990cca 100644 --- a/src/bme68xLibrary.cpp +++ b/src/bme68xLibrary.cpp @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bme68xLibrary.cpp - * @date 8 Feb 2022 - * @version 1.1.40407 + * @date 11 Jan 2023 + * @version 1.2.40408 * */ @@ -51,6 +51,8 @@ #ifdef ARDUINO_ARCH_MBED /* Assuming all MBED implementations of Wire have 256 byte sized buffers */ +/* The buffer size needs to be modifed by the user as per the hardware they are using */ +/* Check I2C buffer length in Wire.h of used board in ardunio library folder under wire/src */ #define BME68X_I2C_BUFFER_SIZE 256 #define BME68X_BURST_SPI_TRANSFER diff --git a/src/bme68xLibrary.h b/src/bme68xLibrary.h index f02779d..79063ec 100644 --- a/src/bme68xLibrary.h +++ b/src/bme68xLibrary.h @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bme68xLibrary.h - * @date 8 Feb 2022 - * @version 1.1.40407 + * @date 11 Jan 2023 + * @version 1.2.40408 * */