Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    BME680 I2C read and write

    BME680 I2C read and write

    New Poster


    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 ( 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

    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.
    • ...

    Long-established Member


    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:

    specifically the source code 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

    gas_sensor.dev_id = addr;
    gas_sensor.intf = BME680_I2C_INTF; = &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