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

    Sudeep1310
    Established Member

    Hello Minhwan,

    As I told you in my first message program exucution pointer was always stuck in internal API is used to read the calibrated data from the sensor in bme680.c  driver file. So I have tried some tricks to analyse where it is stucking. So I got the point it is stucking when executing functon "bme680_get_regs(BME680_COEFF_ADDR1, coeff_array, BME680_COEFF_ADDR1_LEN, dev)" . Here BME680_COEFF_ADDR1 is 0x89 and BME680_COEFF_ADDR1_LEN is 25 and this BME680_COEFF_ADDR1 is  incrementing  here 25 times to collect data from all these 25 addresses but in my case after incrementing  4-5 times it is stucking always. So I have tried to read I2C of all these 25 register addresses  seperately with some delay instead of reading multiple in one I2C read function. After this trick it never stuck . But still I didn't get the point  why this is happening?  After this changes in code , I am getting readings but constant values and Not getting change in Temperature also even I am putting it infront of Air Hot Gun. 

    I don't want to change original library function so Please Guide. As I mentioned in previous mesage I am getting correct Chip ID So I2C is working . I am getting meas period 183. Is it correct or not? Please suggest. 

    I am not using  bsec library right not just using  driver's files (bme680.c , bme680.h , bme680_defs.h). Please guide for proper use. Refer my main code given in previous message and correct me where I am doing wrong. 

     

    BR

    Sudeep

     

     

    Minhwan
    Community Moderator
    Community Moderator

    Hello Sudeep, 

     

    I understood. 

    Let's try one by one. 

    Firstly, you can update our latest API as below. 

    https://github.com/BoschSensortec/BME68x-Sensor-API

    And, please put your i2c functions in common.c (And, removed all COINES related source code)

    https://github.com/BoschSensortec/BME68x-Sensor-API/blob/master/examples/common/common.c

    If there is i2c issue, put 1ms delay in bme68x_i2c_read and bme68x_i2c_write functions. 

    There are 4 examples code, so you can run it. 

    If there is any error, please let me know which error you get and where. 

    Thank you. 

     

    Sudeep1310
    Established Member
    Hello Minhwan,

    Thanks for your valubale suggestions.  Yes I will do as per your suggestions and will let you know about response.


     

     

    Sudeep1310
    Established Member

     Hello Minhwan,

    As you suggested I have just test one step using new updated API's.

    As per your suggeston I just put my I2C functions in common.c. Commented all coines related functions, Please  refer modified comman.c  and bme68x.c file attached with this message and you can see modification done by me. 

    I am just trying to execute following code (copied from example forced_mode.c) in my main.c and pupose is that at least I will get success in BME initialization. Please check following code. 


    /* Includes ------------------------------------------------------------------*/
    #include "BlueNRG_x_device.h"
    #include <stdio.h>
    #include "BlueNRG1_conf.h"
    #include "SDK_EVAL_Config.h"
    #include "BlueNRG1_it.h"
    #include "bme68x.h"
    #include "common.h"
    #include "bme68x_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 ---------------------------------------------------------*/


    /* Private function prototypes -----------------------------------------------*/

    void processCommand(void);
    void processCommand1(void);
    //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 bme68x_dev bme;
    int8_t rslt;
    struct bme68x_conf conf;
    struct bme68x_heatr_conf heatr_conf;
    struct bme68x_data data;
    uint32_t del_period;
    uint32_t time_ms = 0;
    uint8_t n_fields;
    uint16_t sample_count = 1;

    /* Interface preference is updated as a parameter
    * For I2C : BME68X_I2C_INTF
    * For SPI : BME68X_SPI_INTF
    */
    rslt = bme68x_interface_init(&bme, BME68X_I2C_INTF);
    bme68x_check_rslt("bme68x_interface_init", rslt);
    rslt = bme68x_init(&bme);
    bme68x_check_rslt("bme68x_init", rslt);

    /* Check if rslt == BME68X_OK, report or handle if otherwise */
    conf.filter = BME68X_FILTER_OFF;
    conf.odr = BME68X_ODR_NONE;
    conf.os_hum = BME68X_OS_16X;
    conf.os_pres = BME68X_OS_1X;
    conf.os_temp = BME68X_OS_2X;
    rslt = bme68x_set_conf(&conf, &bme);
    bme68x_check_rslt("bme68x_set_conf", rslt);

    /* Check if rslt == BME68X_OK, report or handle if otherwise */
    heatr_conf.enable = BME68X_ENABLE;
    heatr_conf.heatr_temp = 300;
    heatr_conf.heatr_dur = 100;
    rslt = bme68x_set_heatr_conf(BME68X_FORCED_MODE, &heatr_conf, &bme);
    bme68x_check_rslt("bme68x_set_heatr_conf", rslt);

    printf("Sample, TimeStamp(ms), Temperature(deg C), Pressure(Pa), Humidity(%%), Gas resistance(ohm), Status\n");

     

    }

     

     

     

     

    #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*****************************************************************************/

     

    I have edited initialization function and added some printf functions to know where I am getting  stuck. So Output I am getting as Below,

    Sudeep1310_0-1643362653020.png

     

    Getting Chip ID  97(0x61) is correct.  And Problem is same as previous, I am stuck at rslt = get_calib_data(dev). Not getting any rslt value. One point I didn't got as you suggested, If I2C will get issue then I need to add 1ms delay in I2C read and write function but where I can add it? In common.c?  Please suggest

     
     
     

    Minhwan
    Community Moderator
    Community Moderator

    Chip id 97 is correct. 

    For delay, you need to check "//Here"

    BME68X_INTF_RET_TYPE bme68x_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
    {
    uint8_t dev_addr = *(uint8_t*)intf_ptr;
    //Here
    return SdkEvalI2CRead(reg_data, dev_addr, reg_addr, (uint16_t)len);

    }

    /*!
    * I2C write function map to COINES platform
    */
    BME68X_INTF_RET_TYPE bme68x_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
    {
    uint8_t dev_addr = *(uint8_t*)intf_ptr;

    //Here
    return SdkEvalI2CWrite((uint8_t *)reg_data, dev_addr, reg_addr, (uint16_t)len);

    }

     

    And, I saw your code, and your delay unit is mili second, but we are using micro second. 

    Therefore, if you don't have us, please devide 1000 and use the time. Like

    /*!
    * Delay function map to COINES platform
    */
    void bme68x_delay_us(uint32_t period, void *intf_ptr)
    {

       period = period / 1000;

      if( period == 0)

          period  = 1;

    SdkDelayMs(period);
    }

    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