Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BME688 sensor API

    BME688 sensor API

    Rosso9
    Established Member

    Hi, I'm using  the BME688 sensor for a new project with Nordik nRF52832. I find on github the API for using the sensor. The problem is that API's files include the library coines that I'm not able to find anywhere. I would like to ask you if you have it or if you have a structure of the library to implement (because I do not understand what the various functions do). Thanks for your helps

    18 REPLIES 18

    Rosso9
    Established Member

    Hi,

    Thanks again for your help.

    I try to modify the common.c file to adapt to my microcontroller. I would like to ask you if the structure is correct (not the single function on the code but the general struscture), because when I built the program I have no problem, but then the code returns error. In particular, init_interface function works correctly, but then init funcrion, set_config function ecc return error -2: communication error

     

    static const nrf_drv_twi_t i2c_instance = NRF_DRV_TWI_INSTANCE(0);

    BME68X_INTF_RET_TYPE bme68x_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
    {
    int8_t err = nrf_drv_twi_rx(&i2c_instance, reg_addr, reg_data, len);
    return err;
    }


    BME68X_INTF_RET_TYPE bme68x_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
    {
    int8_t err = nrf_drv_twi_tx(&i2c_instance, reg_addr, reg_data, len, false);
    return err;
    }


    void bme68x_delay_us(uint32_t period, void *intf_ptr)
    {
    nrf_delay_us(period);
    }

    int8_t bme68x_interface_init(struct bme68x_dev *bme, uint8_t intf)
    {
    int8_t rslt = BME68X_OK;
    uint8_t reg_addr;
    const uint8_t *reg_data;
    uint32_t len;
    void *intf_ptr;

    if (bme != NULL)
    {
    /* Bus configuration : I2C */
    if (intf == BME68X_I2C_INTF)
    {
    printf("I2C Interface\n");
    dev_addr = BME68X_I2C_ADDR_LOW;
    bme->read = bme68x_i2c_read;
    bme->write = bme68x_i2c_write;
    bme->intf = BME68X_I2C_INTF;

    //here I initialize the I2c component
    const nrf_drv_twi_config_t i2c_instance_config = { .scl = SCL_PIN,
    .sda = SDA_PIN,
    .frequency = NRF_TWI_FREQ_100K,
    .interrupt_priority = 0};
    rslt = nrf_drv_twi_init(&i2c_instance, &i2c_instance_config, NULL, NULL);
    if (rslt)
    {
    printf("Error %d: Initialization of I2C connection failed!\n", rslt);
    }
    //enable I2c instance
    nrf_drv_twi_enable(&i2c_instance);
    }

    bme->delay_us = bme68x_delay_us;
    bme->intf_ptr = &dev_addr;
    bme->amb_temp = 25; /* The ambient temperature in deg C is used for defining the heater temperature */
    }
    else
    {
    rslt = BME68X_E_NULL_PTR;
    }

    return rslt;
    }

     

     

    Thanks again

    Rosso9
    Established Member

    Hi,

    I try to risolve the problem of adaptation of common.c files. Now there is something that works but not correctly.

    In the main code, first I search if there are some connected devices through I2C (and I find that there is a device at 0x76, which is the BME688), then I try to use the forced mode configuration example, but here there is the problem. I attach here the output.

    //OUTPUT OF THE PROGRAM

    Starting the program
    TWI device detected at address 0x76.     //(TWI is equivalent to I2C) So the sensor is correctly connected

    INIZIO BME
    I2C Interface

    API name [bme68x_init] Error [-3] : Device not found
    API name [bme68x_set_conf]: Tutto ok
    API name [bme68x_set_heatr_conf]: Tutto ok
    API name [bme68x_set_op_mode]: Tutto ok
    API name [bme68x_get_data]: Tutto ok
    Getting data correctly
    Printing resultsstatus: 128
    Gas index: 0
    Meas index: 0
    Res heat: 128
    Current DAC: 0
    Gas wait period: 0
    Temperatura: 0.80 °C
    Pressione: -1290.20 Pa
    Umidita': 0.0 Gas resistance: 5070.0 O

    API name [bme68x_set_op_mode]: Tutto ok
    API name [bme68x_get_data] Warning [2] : No new data found


    API name [bme68x_set_op_mode]: Tutto ok
    API name [bme68x_get_data]: Tutto ok
    Getting data correctly
    Printing resultsstatus: 128
    Gas index: 10
    Meas index: 22
    Res heat: 64
    Current DAC: 0
    Gas wait period: 128
    Temperatura: 0.33 °C
    Pressione: 23550.48 Pa
    Umidita': 0.0 Gas resistance: 14202.64

     

    I do not understand. The sensor is correctly connected, otherwise the microcontroller would not find anything at the adress 0x76.

    But then when I try to initialize the sensor, it returns that the device is not found, but after it looks like as the sensor is connected and it says if it has new datas or no, and in case it sends datas (however, the datas that are sent are obviously wrong!).

    I do not understand where the problem is.

    Thanks for the help

    Minhwan
    Community Moderator
    Community Moderator

    Hi Rosso, 

     

    The error happens when you don't get correct chip ID. 

    What chip ID did you get from BME688? 

    Do you have logic analyzer or can read i2c value from your board? 

    Thanks, 

    Rosso9
    Established Member

    Hi again,

    after some troubles, I finally get the correct chip ID value.

    But now I have a different kind of problem.

    The first time I connect to power the sensor and run the program, I have this result:

    I2C InterfaceAPI name [bme68x_interface_init]: Tutto ok
    API name [bme68x_init]: Tutto ok
    API name [bme68x_set_conf]: Tutto ok
    API name [bme68x_set_heatr_conf]: Tutto ok
    API name [bme68x_set_op_mode]: Tutto ok
    API name [bme68x_get_data] Warning [2] : No new data found

    I have waited some times but it seems to be blocked in somewhere I do not know.

    If I push the reset button of microcontroller, I obtain a different result:

    INIZIO BME
    I2C InterfaceAPI name [bme68x_interface_init]: Tutto ok
    API name [bme68x_init]: Tutto ok

    Here, I see that the microcontroller is stopped in the bme68x_set_conf, and in particular it cannot exit the do while cicle at line 444 of bme68x.c file (it seems that the code want to put in sleep mode the sensor but it is not able).

    Do you have any idea of why I get these problems? I have not modified the bme68x.c file.

    Minhwan
    Community Moderator
    Community Moderator

    Hi Rosso, 

     

    Which example code did you refer to? 

    Please check your sequence is correct. For example, if you want to get data in foreced mode, you can refer below example. 

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

    And each function in BME68x API like bme68x_set_heatr_conf, we have return, so you can check whether there is error or not. 

    Let me know if you have further questions. 

    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