Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    Getting error in bme680 calibration function.

    Getting error in bme680 calibration function.

    Sudeep1310
    Established Member

    Hi,

    I am trying to get compile bme680_init() function only and it interfaced with the BlueNRG-2 (BLE+MCU)module. I am using  Keil compiller. Please look below for reference

    struct bme680_dev gas_sensor;

    /* You may assign a chip select identifier to be handled later */
    gas_sensor.dev_id = BME680_I2C_ADDR_PRIMARY;
    gas_sensor.intf = BME680_I2C_INTF;
    gas_sensor.read = i2c_read;
    gas_sensor.write = i2c_write;
    gas_sensor.delay_ms = delay_ms;
    /* amb_temp can be set to 25 prior to configuring the gas sensor
    * or by performing a few temperature readings without operating the gas sensor.
    */
    gas_sensor.amb_temp = 25;


    int8_t rslt = BME680_OK;
    rslt = bme680_init(&gas_sensor);
    printf("BME680 InIt Result: ");
    if(rslt==0)
    {
    printf("Success");
    }
    else
    {
    printf("Error");
    }
    printf("\n");

     

    But I am getting issue at  rslt = bme680_get_regs(BME680_COEFF_ADDR1, coeff_array, BME680_COEFF_ADDR1_LEN, dev);

    in get_calib_data () function. Here Program is stuck and getting  error in I2C reading. But I am getting proper Chip ID 0x61 while reading  chip ID . So I am assuming my I2C lines are working. Also tested with other sensor and confirm I2C line is working.  I have also checked about BME680_COEFF_ADDR1 and that is 0x89 given in bme680_def.h file. But It is not mentioned anywhere in datasheet. 

    Can you please Guide me where I am doing wrong. Please Guide. 

    31 REPLIES 31

    Minhwan
    Community Moderator
    Community Moderator

    Hello Sudeep, 

     

    Could you share your whole application code related to BME680? 

    And, if you stuck that point, mean that no return value is availble right? If there is return value, what is it? 

    Thank you. 

    Sudeep1310
    Established Member

    Here is my main code where I am just testing  BME initialization function. Here I have got chip ID properly but gettng  stuck  in Calibration function. I want to just print success after bme680_init(&gas_sensor) function. My I2C function is working, I have tried BME280 also and it working properly but getting issue in BME680. As I have mentioned in last message I am stuck in calibration function where I am not getting  any return value. 


    /******************** ************************************** ********************
    * File Name : I2C/Master_Polling/main.c
    * Author : BCI Team
    * Version : V1.0.0
    * Date : Jan-2022
    * Description : Code demostrating the I2C master functionality

    *******************************************************************************/


    /* Includes ------------------------------------------------------------------*/
    #include "BlueNRG_x_device.h"
    #include <stdio.h>
    #include "BlueNRG1_conf.h"
    #include "SDK_EVAL_Config.h"
    #include "bme680.h"
    #include "bme680_defs.h"

     

    /** @addtogroup BlueNRG1_StdPeriph_Examples BlueNRG1 Standard Peripheral Examples
    * @{
    */

    /** @addtogroup I2C_Examples I2C Examples
    * @{
    */

    /** @addtogroup I2C_Master I2C Master
    * @{
    */

    /* Private typedef -----------------------------------------------------------*/


    /* Private define ------------------------------------------------------------*/


    /* Private macro -------------------------------------------------------------*/

     

    /* Private variables ---------------------------------------------------------*/
    int status=0;
    //uint16_t dev=0x52;
    uint8_t id,id1;
    uint8_t byteData[10], sensorState=0;
    uint16_t wordData;
    uint8_t ToFSensor = 1; // 0=Left, 1=Center(default), 2=Right
    uint16_t Distance;
    uint16_t SignalRate;
    uint16_t AmbientRate;
    uint16_t SpadNum;
    uint8_t RangeStatus;
    uint8_t dataReady;
    volatile uint32_t lSystickCounter=0;
    /* Private function prototypes -----------------------------------------------*/
    void SdkDelayMs(volatile uint32_t lTimeMs);
    void processCommand(void);
    void processCommand1(void);
    static int8_t i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len);
    static int8_t i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len);
    void delay_ms(uint32_t period);
    //void helpMessage(void);

    /* Private functions ---------------------------------------------------------*/

    /**
    * @brief Main program code
    * @param None
    * @retval None
    */
    int main(void)
    {
    /* System initialization function */
    SystemInit();

    /* Identify BlueNRG1 platform */
    SdkEvalIdentification();

    /* UART initialization */
    SdkEvalComUartInit(UART_BAUDRATE);

    /* Enable the GPIO Clock */
    SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_GPIO, ENABLE);

    GPIO_InitType GPIO_InitStructure;

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
    GPIO_InitStructure.GPIO_Mode = GPIO_Output;
    GPIO_InitStructure.GPIO_Pull = DISABLE;
    GPIO_InitStructure.GPIO_HighPwr = ENABLE;
    GPIO_Init(&GPIO_InitStructure);
    /* Put the LED off */
    GPIO_WriteBit(GPIO_Pin_1,Bit_SET);


    /* Configure SysTick to generate interrupt */
    SysTick_Config(SYST_CLOCK/1000 - 1);

    /* I2C initialization */
    SdkEvalI2CInit(400000);
    /* Infinite loop for process command */
    processCommand1();


    }

     

    /**
    * @brief Process command code
    * @param None
    * @retval None
    */
    void processCommand1(void)
    {

    struct bme680_dev gas_sensor;

    /* You may assign a chip select identifier to be handled later */
    gas_sensor.dev_id = BME680_I2C_ADDR_PRIMARY; // 0x76
    gas_sensor.intf = BME680_I2C_INTF;
    gas_sensor.read = i2c_read;
    gas_sensor.write = i2c_write;
    gas_sensor.delay_ms = delay_ms;
    /* amb_temp can be set to 25 prior to configuring the gas sensor
    * or by performing a few temperature readings without operating the gas sensor.
    */
    gas_sensor.amb_temp = 25;


    int8_t rslt = BME680_OK;
    rslt = bme680_init(&gas_sensor);
    printf("BME680 InIt Result: ");
    if(rslt==0)
    {
    printf("Success");
    }
    else
    {
    printf("Error");
    }
    printf("\n");

    // while(1)
    // {


    // }
    }

     

     

     

     

    /**
    * @brief Delay function
    * @param Delay in ms
    * @retval None
    */
    void SdkDelayMs(volatile uint32_t lTimeMs)
    {
    uint32_t nWaitPeriod = ~lSystickCounter;

    if(nWaitPeriod<lTimeMs)
    {
    while( lSystickCounter != 0xFFFFFFFF);
    nWaitPeriod = lTimeMs-nWaitPeriod;
    }
    else
    nWaitPeriod = lTimeMs+ ~nWaitPeriod;

    while( lSystickCounter != nWaitPeriod ) ;

    }
    //*****************************************************************************************************************
    void delay_ms(uint32_t period)
    {
    SdkDelayMs(period);
    }

    //*****************************************************************************************************************
    int8_t i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
    {
    int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
    uint8_t data;

    rslt= SdkEvalI2CRead(&data, dev_id, reg_addr, len);
    *reg_data = data;

    return rslt;
    }
    //*****************************************************************************************************************
    //*****************************************************************************************************************
    int8_t i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
    {
    int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
    uint8_t data;

    rslt=SdkEvalI2CWrite(&data, dev_id, reg_addr, len);
    *reg_data = data;

    return rslt;
    }
    //*****************************************************************************************************************

     

    #ifdef USE_FULL_ASSERT

    /**
    * @brief Reports the name of the source file and the source line number
    * where the assert_param error has occurred.
    * @param file: pointer to the source file name
    * @param line: assert_param error line source number
    */
    void assert_failed(uint8_t* file, uint32_t line)
    {
    /* User can add his own implementation to report the file name and line number,
    ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

    /* Infinite loop */
    while (1)
    {
    }
    }

    #endif

    /**
    * @}
    */

    /**
    * @}
    */

    /**
    * @}
    */

    /*******************  *****END OF FILE**************************************************************************************************/

     

    Sudeep1310
    Established Member

    Hello Minhwan,

    I have changed Internal Calibrartion function in bme680.c as like below,

    static int8_t get_calib_data(struct bme680_dev *dev)
    {
    int8_t rslt;
    //uint8_t coeff_array[BME680_COEFF_SIZE] = { 0 };
    uint8_t coeff_array[41] = { 0 };
    uint8_t temp_var = 0; /* Temporary variable */

    /* Check for null pointer in the device structure*/
    rslt = null_ptr_check(dev);
    if (rslt == BME680_OK) {
    // printf("Calibration In Test: \r");
    //rslt = bme680_get_regs(BME680_COEFF_ADDR1, coeff_array, BME680_COEFF_ADDR1_LEN, dev);
    rslt = bme680_get_regs(0x89, &coeff_array[0], 1, dev);
    dev->delay_ms(1);
    //printf("1 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x8a, &coeff_array[1], 1, dev);
    dev->delay_ms(1);
    //printf("2 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x8b, &coeff_array[2], 1, dev);
    dev->delay_ms(1);
    //printf("3 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x8c, &coeff_array[3], 1, dev);
    dev->delay_ms(1);
    //printf("4 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x8d, &coeff_array[4], 1, dev);
    dev->delay_ms(1);
    //printf("5 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x8e, &coeff_array[5], 1, dev);
    dev->delay_ms(1);
    //printf("6 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x8f, &coeff_array[6], 1, dev);
    dev->delay_ms(1);
    //printf("7 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x90, &coeff_array[7], 1, dev);
    dev->delay_ms(1);
    //printf("8 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x91, &coeff_array[8], 1, dev);
    dev->delay_ms(1);
    //printf("9 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x92, &coeff_array[9], 1, dev);
    dev->delay_ms(1);
    //printf("10 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x93, &coeff_array[10], 1, dev);
    dev->delay_ms(1);
    //printf("11 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x94, &coeff_array[11], 1, dev);
    dev->delay_ms(1);
    //printf("12 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x95, &coeff_array[12], 1, dev);
    dev->delay_ms(1);
    //printf("13 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x96, &coeff_array[13], 1, dev);
    dev->delay_ms(1);
    //printf("14 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x97, &coeff_array[14], 1, dev);
    dev->delay_ms(1);
    //printf("15 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x98, &coeff_array[15], 1, dev);
    dev->delay_ms(1);
    //printf("16 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x99, &coeff_array[16], 1, dev);
    dev->delay_ms(1);
    //printf("17 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x9a, &coeff_array[17], 1, dev);
    dev->delay_ms(1);
    //printf("18 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x9b, &coeff_array[18], 1, dev);
    dev->delay_ms(1);
    //printf("19 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x9c, &coeff_array[19], 1, dev);
    dev->delay_ms(1);
    //printf("20 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x9d, &coeff_array[20], 1, dev);
    dev->delay_ms(1);
    //printf("21 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x9e, &coeff_array[21], 1, dev);
    dev->delay_ms(1);
    //printf("22 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0x9f, &coeff_array[22], 1, dev);
    dev->delay_ms(1);
    //printf("23 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xa0, &coeff_array[23], 1, dev);
    dev->delay_ms(1);
    //printf("24 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xa2, &coeff_array[24], 1, dev);
    dev->delay_ms(1);
    //printf("25 test: %d\r\n",rslt);


    // printf("first test: \r\n");
    /* Append the second half in the same array */
    // if (rslt == BME680_OK)
    // {
    rslt = bme680_get_regs(0xe1, &coeff_array[25], 1, dev);
    //printf("26 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xe2, &coeff_array[26], 1, dev);
    //printf("27 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xe3, &coeff_array[27], 1, dev);
    //printf("28 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xe4, &coeff_array[28], 1, dev);
    //printf("29 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xe5, &coeff_array[29], 1, dev);
    //printf("30 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xe6, &coeff_array[30], 1, dev);
    //printf("31 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xe7, &coeff_array[31], 1, dev);
    //printf("32 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xe8, &coeff_array[32], 1, dev);
    //printf("33 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xe9, &coeff_array[33], 1, dev);
    //printf("34 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xea, &coeff_array[34], 1, dev);
    //printf("35 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xeb, &coeff_array[35], 1, dev);
    //printf("36 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xec, &coeff_array[36], 1, dev);
    //printf("37 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xed, &coeff_array[37], 1, dev);
    //printf("38 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xee, &coeff_array[38], 1, dev);
    //printf("39 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xef, &coeff_array[39], 1, dev);
    //printf("40 test: %d\r\n",rslt);
    rslt = bme680_get_regs(0xf0, &coeff_array[40], 1, dev);
    dev->delay_ms(1);
    //printf("41 test: %d\r\n",rslt);
    // }
    // printf("second test: \r\n");
    //rslt = bme680_get_regs(BME680_COEFF_ADDR2, &coeff_array[BME680_COEFF_ADDR1_LEN], BME680_COEFF_ADDR2_LEN, dev);

    /* Temperature related coefficients */
    dev->calib.par_t1 = (uint16_t) (BME680_CONCAT_BYTES(coeff_array[BME680_T1_MSB_REG],
    coeff_array[BME680_T1_LSB_REG]));
    dev->calib.par_t2 = (int16_t) (BME680_CONCAT_BYTES(coeff_array[BME680_T2_MSB_REG],
    coeff_array[BME680_T2_LSB_REG]));
    dev->calib.par_t3 = (int8_t) (coeff_array[BME680_T3_REG]);

    /* Pressure related coefficients */
    dev->calib.par_p1 = (uint16_t) (BME680_CONCAT_BYTES(coeff_array[BME680_P1_MSB_REG],
    coeff_array[BME680_P1_LSB_REG]));
    dev->calib.par_p2 = (int16_t) (BME680_CONCAT_BYTES(coeff_array[BME680_P2_MSB_REG],
    coeff_array[BME680_P2_LSB_REG]));
    dev->calib.par_p3 = (int8_t) coeff_array[BME680_P3_REG];
    dev->calib.par_p4 = (int16_t) (BME680_CONCAT_BYTES(coeff_array[BME680_P4_MSB_REG],
    coeff_array[BME680_P4_LSB_REG]));
    dev->calib.par_p5 = (int16_t) (BME680_CONCAT_BYTES(coeff_array[BME680_P5_MSB_REG],
    coeff_array[BME680_P5_LSB_REG]));
    dev->calib.par_p6 = (int8_t) (coeff_array[BME680_P6_REG]);
    dev->calib.par_p7 = (int8_t) (coeff_array[BME680_P7_REG]);
    dev->calib.par_p8 = (int16_t) (BME680_CONCAT_BYTES(coeff_array[BME680_P8_MSB_REG],
    coeff_array[BME680_P8_LSB_REG]));
    dev->calib.par_p9 = (int16_t) (BME680_CONCAT_BYTES(coeff_array[BME680_P9_MSB_REG],
    coeff_array[BME680_P9_LSB_REG]));
    dev->calib.par_p10 = (uint8_t) (coeff_array[BME680_P10_REG]);

    /* Humidity related coefficients */
    dev->calib.par_h1 = (uint16_t) (((uint16_t) coeff_array[BME680_H1_MSB_REG] << BME680_HUM_REG_SHIFT_VAL)
    | (coeff_array[BME680_H1_LSB_REG] & BME680_BIT_H1_DATA_MSK));
    dev->calib.par_h2 = (uint16_t) (((uint16_t) coeff_array[BME680_H2_MSB_REG] << BME680_HUM_REG_SHIFT_VAL)
    | ((coeff_array[BME680_H2_LSB_REG]) >> BME680_HUM_REG_SHIFT_VAL));
    dev->calib.par_h3 = (int8_t) coeff_array[BME680_H3_REG];
    dev->calib.par_h4 = (int8_t) coeff_array[BME680_H4_REG];
    dev->calib.par_h5 = (int8_t) coeff_array[BME680_H5_REG];
    dev->calib.par_h6 = (uint8_t) coeff_array[BME680_H6_REG];
    dev->calib.par_h7 = (int8_t) coeff_array[BME680_H7_REG];

    /* Gas heater related coefficients */
    dev->calib.par_gh1 = (int8_t) coeff_array[BME680_GH1_REG];
    dev->calib.par_gh2 = (int16_t) (BME680_CONCAT_BYTES(coeff_array[BME680_GH2_MSB_REG],
    coeff_array[BME680_GH2_LSB_REG]));
    dev->calib.par_gh3 = (int8_t) coeff_array[BME680_GH3_REG];

    /* Other coefficients */
    if (rslt == BME680_OK) {
    rslt = bme680_get_regs(BME680_ADDR_RES_HEAT_RANGE_ADDR, &temp_var, 1, dev);

    dev->calib.res_heat_range = ((temp_var & BME680_RHRANGE_MSK) / 16);
    if (rslt == BME680_OK) {
    rslt = bme680_get_regs(BME680_ADDR_RES_HEAT_VAL_ADDR, &temp_var, 1, dev);

    dev->calib.res_heat_val = (int8_t) temp_var;
    if (rslt == BME680_OK)
    rslt = bme680_get_regs(BME680_ADDR_RANGE_SW_ERR_ADDR, &temp_var, 1, dev);
    }
    }
    dev->calib.range_sw_err = ((int8_t) temp_var & (int8_t) BME680_RSERROR_MSK) / 16;
    }

    return rslt;
    }

    and changed function of read field data as like below,

    static int8_t read_field_data(struct bme680_field_data *data, struct bme680_dev *dev)
    {
    int8_t rslt;
    //uint8_t buff[BME680_FIELD_LENGTH] = { 0 };
    uint8_t buff[15] = { 0 };
    uint8_t gas_range;
    uint32_t adc_temp;
    uint32_t adc_pres;
    uint16_t adc_hum;
    uint16_t adc_gas_res;
    uint8_t tries = 10;

    /* Check for null pointer in the device structure*/
    rslt = null_ptr_check(dev);
    do {
    if (rslt == BME680_OK) {

    //rslt = bme680_get_regs(((uint8_t) (BME680_FIELD0_ADDR)), buff, (uint16_t) BME680_FIELD_LENGTH, dev);
    rslt = bme680_get_regs( 0x1d, &buff[0], 1, dev);
    dev->delay_ms(1);
    rslt = bme680_get_regs( 0x1e, &buff[1], 1, dev);
    dev->delay_ms(1);
    rslt = bme680_get_regs( 0x1f, &buff[2], 1, dev);
    dev->delay_ms(1);
    rslt = bme680_get_regs( 0x20, &buff[3], 1, dev);
    dev->delay_ms(1);
    rslt = bme680_get_regs( 0x21, &buff[4], 1, dev);
    dev->delay_ms(1);
    rslt = bme680_get_regs( 0x22, &buff[5], 1, dev);
    dev->delay_ms(1);
    rslt = bme680_get_regs( 0x23, &buff[6], 1, dev);
    dev->delay_ms(1);
    rslt = bme680_get_regs( 0x24, &buff[7], 1, dev);
    dev->delay_ms(1);
    rslt = bme680_get_regs( 0x25, &buff[8], 1, dev);
    dev->delay_ms(1);
    rslt = bme680_get_regs( 0x26, &buff[9], 1, dev);
    dev->delay_ms(1);
    rslt = bme680_get_regs( 0x27, &buff[10], 1, dev);
    dev->delay_ms(1);
    rslt = bme680_get_regs( 0x28, &buff[11], 1, dev);
    dev->delay_ms(1);
    rslt = bme680_get_regs( 0x29, &buff[12], 1, dev);
    dev->delay_ms(1);
    rslt = bme680_get_regs( 0x2a, &buff[13], 1, dev);
    dev->delay_ms(1);
    rslt = bme680_get_regs( 0x2b, &buff[14], 1, dev);
    dev->delay_ms(1);

    //printf("Test1\n");

    data->status = buff[0] & BME680_NEW_DATA_MSK;
    data->gas_index = buff[0] & BME680_GAS_INDEX_MSK;
    data->meas_index = buff[1];

    /* 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_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_gas_res = (uint16_t) ((uint32_t) buff[13] * 4 | (((uint32_t) buff[14]) / 64));
    gas_range = buff[14] & BME680_GAS_RANGE_MSK;

    data->status |= buff[14] & BME680_GASM_VALID_MSK;
    data->status |= buff[14] & BME680_HEAT_STAB_MSK;

    if (data->status & BME680_NEW_DATA_MSK) {
    data->temperature = calc_temperature(adc_temp, dev);
    data->pressure = calc_pressure(adc_pres, dev);
    data->humidity = calc_humidity(adc_hum, dev);
    data->gas_resistance = calc_gas_resistance(adc_gas_res, gas_range, dev);
    break;
    }
    /* Delay to poll the data */
    dev->delay_ms(BME680_POLL_PERIOD_MS);
    }
    tries--;
    } while (tries);

    if (!tries)
    rslt = BME680_W_NO_NEW_DATA;

    return rslt;
    }

     

    Now I am getting reading but it is wrong  and constant each time as like below,

    T: 35.30 degC, P: 655.58 hPa, H 100.00 %rH
    T: 35.30 degC, P: 655.58 hPa, H 100.00 %rH
    T: 35.30 degC, P: 655.58 hPa, H 100.00 %rH
    T: 35.30 degC, P: 655.58 hPa, H 100.00 %rH
    T: 35.30 degC, P: 655.58 hPa, H 100.00 %rH
    T: 35.30 degC, P: 655.58 hPa, H 100.00 %rH
    T: 35.30 degC, P: 655.58 hPa, H 100.00 %rH
    T: 35.30 degC, P: 655.58 hPa, H 100.00 %rH
    T: 35.30 degC, P: 655.58 hPa, H 100.00 %rH
    T: 35.30 degC, P: 655.58 hPa, H 100.00 %rH

     

    Here 

    if(data.status & BME680_GASM_VALID_MSK)

    condition is not verified so not printing Gas Value, Here I am giving my main code again as below,


    /******************** ****************** ********************
    * File Name : I2C/Master_Polling/main.c
    * Author : BCI Team
    * Version : V1.0.0
    * Date : Jan-2022
    * Description : Code demostrating the I2C master functionality
    *******************************************************************************/


    /* Includes ------------------------------------------------------------------*/
    #include "BlueNRG_x_device.h"
    #include <stdio.h>
    #include "BlueNRG1_conf.h"
    #include "SDK_EVAL_Config.h"
    #include "bme680.h"

     


    /** @addtogroup BlueNRG1_StdPeriph_Examples BlueNRG1 Standard Peripheral Examples
    * @{
    */

    /** @addtogroup I2C_Examples I2C Examples
    * @{
    */

    /** @addtogroup I2C_Master I2C Master
    * @{
    */

    /* Private typedef -----------------------------------------------------------*/


    /* Private define ------------------------------------------------------------*/


    /* Private macro -------------------------------------------------------------*/

     

    /* Private variables ---------------------------------------------------------*/
    struct bme680_dev gas_sensor;
    struct bme680_field_data data;

    uint8_t set_required_settings;
    uint16_t meas_period;
    int status=0;
    //uint16_t dev=0x52;
    uint8_t id,id1;
    uint8_t byteData[10], sensorState=0;
    uint16_t wordData;
    uint8_t ToFSensor = 1; // 0=Left, 1=Center(default), 2=Right
    uint16_t Distance;
    uint16_t SignalRate;
    uint16_t AmbientRate;
    uint16_t SpadNum;
    uint8_t RangeStatus;
    uint8_t dataReady;
    volatile uint32_t lSystickCounter=0;
    /* Private function prototypes -----------------------------------------------*/
    void SdkDelayMs(volatile uint32_t lTimeMs);
    void processCommand(void);
    void processCommand1(void);
    static int8_t i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len);
    static int8_t i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len);
    void delay_ms(uint32_t period);
    //void helpMessage(void);

    /* Private functions ---------------------------------------------------------*/

    /**
    * @brief Main program code
    * @param None
    * @retval None
    */
    int main(void)
    {
    /* System initialization function */
    SystemInit();

    /* Identify BlueNRG1 platform */
    SdkEvalIdentification();

    /* UART initialization */
    SdkEvalComUartInit(UART_BAUDRATE);

    /* Enable the GPIO Clock */
    SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_GPIO, ENABLE);

    GPIO_InitType GPIO_InitStructure;

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
    GPIO_InitStructure.GPIO_Mode = GPIO_Output;
    GPIO_InitStructure.GPIO_Pull = DISABLE;
    GPIO_InitStructure.GPIO_HighPwr = ENABLE;
    GPIO_Init(&GPIO_InitStructure);
    /* Put the LED off */
    GPIO_WriteBit(GPIO_Pin_1,Bit_SET);


    /* Configure SysTick to generate interrupt */
    SysTick_Config(SYST_CLOCK/1000 - 1);

    /* I2C initialization */
    SdkEvalI2CInit(400000);
    /* Infinite loop for process command */
    processCommand1();


    }

     

    /**
    * @brief Process command code
    * @param None
    * @retval None
    */
    void processCommand1(void)
    {


    /* You may assign a chip select identifier to be handled later */
    gas_sensor.dev_id = BME680_I2C_ADDR_PRIMARY; // 0x76
    gas_sensor.intf = BME680_I2C_INTF;
    gas_sensor.read = i2c_read;
    gas_sensor.write = i2c_write;
    gas_sensor.delay_ms = delay_ms;
    /* amb_temp can be set to 25 prior to configuring the gas sensor
    * or by performing a few temperature readings without operating the gas sensor.
    */
    gas_sensor.amb_temp = 25;


    int8_t rslt = BME680_OK;
    rslt = bme680_init(&gas_sensor);
    printf("BME680 InIt Result: ");
    if(rslt==0)
    {
    printf("Success");
    }
    else
    {
    printf("Error");
    }
    delay_ms(5);
    printf("\n");


    /* Set the temperature, pressure and humidity settings */
    gas_sensor.tph_sett.os_hum = BME680_OS_2X;
    gas_sensor.tph_sett.os_pres = BME680_OS_4X;
    gas_sensor.tph_sett.os_temp = BME680_OS_8X;
    gas_sensor.tph_sett.filter = BME680_FILTER_SIZE_3;

    /* Set the remaining gas sensor settings and link the heating profile */
    gas_sensor.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS;
    /* Create a ramp heat waveform in 3 steps */
    gas_sensor.gas_sett.heatr_temp = 320; /* degree Celsius */
    gas_sensor.gas_sett.heatr_dur = 150; /* milliseconds */

    /* Select the power mode */
    /* Must be set before writing the sensor configuration */
    gas_sensor.power_mode = BME680_FORCED_MODE;

    /* Set the required sensor settings needed */
    set_required_settings = BME680_OST_SEL | BME680_OSP_SEL | BME680_OSH_SEL | BME680_FILTER_SEL
    | BME680_GAS_SENSOR_SEL;

    /* Set the desired sensor configuration */
    rslt = bme680_set_sensor_settings(set_required_settings,&gas_sensor);

    /* Set the power mode */
    rslt = bme680_set_sensor_mode(&gas_sensor);
    printf("Configuration Success\n");
    delay_ms(5);

    bme680_get_profile_dur(&meas_period, &gas_sensor);
    //delay_ms(5);

    while(1)
    {
    delay_ms(meas_period); /* Delay till the measurement is ready */
    rslt = bme680_get_sensor_data(&data, &gas_sensor);
    delay_ms(5);

    printf("T: %.2f degC, P: %.2f hPa, H %.2f %%rH ", data.temperature / 100.0f,
    data.pressure / 100.0f, data.humidity / 1000.0f );
    // delay_ms(5);
    /* Avoid using measurements from an unstable heating setup */
    if(data.status & BME680_GASM_VALID_MSK)
    printf(", G: %d ohms", data.gas_resistance);
    // delay_ms(5);
    printf("\r\n");
    // delay_ms(5);

    /* Trigger the next measurement if you would like to read data out continuously */
    if (gas_sensor.power_mode == BME680_FORCED_MODE) {
    rslt = bme680_set_sensor_mode(&gas_sensor);
    }
    // delay_ms(5);
    }

    }

     

     

     

     

    /**
    * @brief Delay function
    * @param Delay in ms
    * @retval None
    */
    void SdkDelayMs(volatile uint32_t lTimeMs)
    {
    uint32_t nWaitPeriod = ~lSystickCounter;

    if(nWaitPeriod<lTimeMs)
    {
    while( lSystickCounter != 0xFFFFFFFF);
    nWaitPeriod = lTimeMs-nWaitPeriod;
    }
    else
    nWaitPeriod = lTimeMs+ ~nWaitPeriod;

    while( lSystickCounter != nWaitPeriod ) ;

    }
    //*****************************************************************************************************************
    void delay_ms(uint32_t period)
    {
    SdkDelayMs(period);
    }

    //*****************************************************************************************************************
    int8_t i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
    {
    int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
    uint8_t data;

    rslt= SdkEvalI2CRead(&data, dev_id, reg_addr, len);
    *reg_data = data;

    return rslt;
    }
    //*****************************************************************************************************************
    //*****************************************************************************************************************
    int8_t i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
    {
    int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
    uint8_t data;

    rslt=SdkEvalI2CWrite(&data, dev_id, reg_addr, len);
    *reg_data = data;

    return rslt;
    }
    //*****************************************************************************************************************

     

    #ifdef USE_FULL_ASSERT

    /**
    * @brief Reports the name of the source file and the source line number
    * where the assert_param error has occurred.
    * @param file: pointer to the source file name
    * @param line: assert_param error line source number
    */
    void assert_failed(uint8_t* file, uint32_t line)
    {
    /* User can add his own implementation to report the file name and line number,
    ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

    /* Infinite loop */
    while (1)
    {
    }
    }

    #endif

    /**
    * @}
    */

    /**
    * @}
    */

    /**
    * @}
    */

    /******************* *****END OF FILE*******************************************************/

     

    Please Suggest where I am doing wrong. In current code I am reading  separate register instead of multiple reading  so don't know whether it is right or wrong. Please Guide.

    Minhwan
    Community Moderator
    Community Moderator

    Hello, 

     

    I'm confused, so please be clear. 

    1) I saw your temperature and humidity is okay, but why you changed our code? It's okay to add delay function, but use the others. 

    2) Do you want to check gas resistance? Are you using bsec library? If yes, which example? 

    Thank you. 

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist