Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    Getting error in bme680 calibration function.

    Getting error in bme680 calibration function.

    Established Member


    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; = 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: ");


    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

    Community Moderator
    Community Moderator

    Hello Sudeep, 


    Currently, I'm checking with HQ whether we can read and write i2c data in case i2c communication length is less than BME68x requires. 

    I will let you know, but possibly you can't use it. 


    Established Member

    Hello Minhwan,

    Thanks for  your  valuable assistance. Once you check with HQ let me know. Your feedback is important to me.

    Community Moderator
    Community Moderator

    Hi Sudeep1310,

    I would recommend migrating to the newer version of the sensor API that supports both the BME680 and BME688. Given that your platform only supports 16 byte reads, you have to achieve longer reads by modifying your I2C read to perform consecutive reads to acheive longer transactions. It would look something like below


    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 */
    	uint16_t max_len = 16; /* BlueNRG RX FIFO depth */
    	uint16_t bytes_left = len;
    	uint16_t len_to_read = 0;
    	uint16_t i = 0;
    	for(i = 0; (i < len) && (rslt == 0);)
    		bytes_left = len - i;
    		len_to_read = (bytes_left < max_len) ? bytes_left : max_len;
    		rslt = SdkEvalI2CRead(&reg_data[i], dev_id, reg_addr + i, len_to_read);
    		i += len_to_read;
    	return rslt;



    Established Member

    Hello Kgoveas,

    Thank you very much for your guidance. I will modify my I2C read function as per your suggestion and will give you feedback soon. 




    Established Member

    Hello Kgoveas,

    Thanks once again for your great suggestons. Your trick is working  with my code. I getting forced example output as below,

    Sample, TimeStamp(ms), Temperature(deg C), Pressure(Pa), Humidity(%), Gas resistance(ohm), Status
    1, 1000, 28.75, 94488.88, 35.88, 5825.59, 0xa0
    2, 1000, 28.98, 94491.52, 35.91, 1831.92, 0xb0
    3, 1000, 29.48, 94483.83, 35.98, 1680.24, 0xb0
    4, 1000, 29.97, 94487.53, 36.05, 1686.79, 0xb0
    5, 1000, 30.32, 94488.09, 36.12, 1692.28, 0xb0
    6, 1000, 30.56, 94490.24, 36.14, 1724.87, 0xb0
    7, 1000, 30.76, 94494.60, 36.15, 1746.91, 0xb0
    8, 1000, 30.94, 94484.99, 36.14, 1765.91, 0xb0
    9, 1000, 31.09, 94492.68, 36.11, 1779.22, 0xb0
    10, 1000, 31.22, 94493.74, 36.07, 1806.44, 0xb0


    As compared to my previous output of my register based code Temperature, Pressure, Humidity output looks same.

    Look here,

    Temperature: 27.299999  
    Humidity: 36.500977  
    Pressure: 947.539978   (in  KPa)
    Altitude: 561.994995
    Gas: 0.000000 

    I have tested sensor intefaced with Arduino board and Gas resistance output  is between 1800-2000 always whenever I was testing with Arduino board. Means Now after implemeted your trick the output of gas resistance I am getting is nearly about same. So I conclude that it is working. 

    I have one doubt, As I seen  in output there is taken 10 samples and each time temperature is incremented by 1. So I am worried about this temperature value. Because I have refered with standard temperature monitor device and temperature here in testing room is 27.30 degree celcius. Please Guide on it. And tell me about Status value getting in Output (0xa0 and 0xb0)