Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BME680 I2C read and write

    BME680 I2C read and write

    Helio_Moreira
    New Poster

    Hi,

    I'm new using  a Bosch sensor and I want to acess it using "HAL" library.

    I have a BME680 sensor and I'm using a Nucleo-144 from ST. I want to use the API in GitHub (https://github.com/BoschSensortec/BME680_driver) but in file "bme680.c" I don't understand how use "read" and "write" called, for example,  in function get_mem_page().

    In "readme" file there are a template for "int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)" and "int8_t user_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)" but I don´t know how to fill it and where to include it (in main.c? or bme680.c?). Can someone explain it?

    Best resgard.

    8 REPLIES 8

    handytech
    Community Moderator
    Community Moderator

    It is not clear if your issue is related to the case above, therefore I would suggest creating your own thread/topic.

    Some information are missing to support your issue here, for instance:

    • Can you confirm that communication is successful at all, for example by reading the chip ID? We recommend using our official Sensor API, which does this check in its init function. Is this function returning any error code for you?
    • If you have communication issue, it could be helpful to share a capture of a transaction using an oscilloscope or logic analyzer.
    • It is mandatory to read the trimming registers for the compensation formulas to work. This is also done in the same init function as above. To review the implementation we would need you to share both the raw adc input fed to the compensation formulas (i.e. adc_temp, adc_pres, adc_hum, adc_gas_res and gas_range from here) as well as all of your calib_data values.
    • Also feel free to share your initialization, configuration and read-out code/routines using the sensor API.
    • ...

    zgg
    Long-established Member

    Hi

    A seperate note here:

    in case you don't want to spend too much time on debugging the i2c communication issues, a much easier way is to use an Arduino board to work with BME680 sensor.

    The key is that every Arduino board uses the same APIs for I2C communication and this abstraction make it much more consistent and easier to get started.

    Once you have the Arduino board, you could refer to example made available by Adafruit here:

    https://github.com/adafruit/Adafruit_BME680

    specifically the source code https://github.com/adafruit/Adafruit_BME680/blob/master/Adafruit_BME680.cpp contains a working example of how the read/write are setup by wrapping around the Arduino I2C APIs.

    ``

    bool Adafruit_BME680::begin(uint8_t addr, bool initSettings) {
    _i2caddr = addr;

    if (_cs == -1) {
    // i2c
    _wire->begin();

    gas_sensor.dev_id = addr;
    gas_sensor.intf = BME680_I2C_INTF;
    gas_sensor.read = &i2c_read;
    gas_sensor.write = &i2c_write;

    }

    ``

    }

    ``

    I used this, and it works like a breeze. Hope this helps.

     

     

     

     

     

     

     

    if (HAL_I2C_Master_Transmit(&hi2c4, (dev_id << 1), &reg_addr, 1, 10)!= HAL_OK)

    Hi Sir ,

               I follow all your suggetions can you share your code for user i2c read & write

    for your ref Ifollow this lib https://github.com/BoschSensortec/BME680_driver

     

    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