Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BME680 read write is working but no new data receiving

    BME680 read write is working but no new data receiving

    Schakus
    New Poster

    Hello,

    I am trying to get the BME680 working with the Bosch Lib and a PIC32MM0256GPM064.
    I am able to read and write registers and see the correct values via printf's and on my logic analyzer.
    If the example code is reading the sensor data via bme680_get_sensor_data the rslt is everytime BME680_W_NO_NEW_DATA.

    I also tried it with a PIC18F46K42 and got the same problem (but different I2C code provided by MCC).

    My code to verify the I2C functions:

    user_i2c_read(0x77, 0xD0, buffer, 1);
    printf("Read Reg 0x%X: 0x%X (0x61 expected)\n",(0xD0),buffer[0]);
    
    user_delay_ms(100);
    buffer[0] = 0x03;
    user_i2c_write(0x77, 0x72, buffer, 1);
    printf("writing 0x03 to 0x72...\n");
    
    buffer[0] = 0x04;
    user_i2c_write(0x77, 0x64, buffer, 1);
    printf("writing 0x04 to 0x64...\n");
    
    buffer[0] = 0x05;
    user_i2c_write(0x77, 0x5A, buffer, 1);
    printf("writing 0x05 to 0x5A...\n");
    
    buffer[0] = 0x06;
    user_i2c_write(0x77, 0x50, buffer, 1);
    printf("writing 0x06 to 0x50...\n");
    
    user_delay_ms(100);
    buffer[0] = 0;
    user_i2c_read(0x77, 0x72, buffer, 1); // read 
    printf("Read Reg 0x%X: 0x%X (0x03 expected)\n",(0x72),buffer[0]);
    
    buffer[0] = 0;
    user_i2c_read(0x77, 0x64, buffer, 1); // read 
    printf("Read Reg 0x%X: 0x%X (0x04 expected)\n",(0x64),buffer[0]);
    
    buffer[0] = 0;
    user_i2c_read(0x77, 0x5A, buffer, 1); // read 
    printf("Read Reg 0x%X: 0x%X (0x05 expected)\n",(0x5A),buffer[0]);
    
    buffer[0] = 0;
    user_i2c_read(0x77, 0x50, buffer, 1); // read 
    printf("Read Reg 0x%X: 0x%X (0x06 expected)\n",(0x50),buffer[0]);

     

    Console output is:

    Schakus_0-1610013948801.png

    Logic Analyzer:

    Schakus_1-1610014116445.png

     

    Looks good for me. 

     

    But if I let the example code running, BME680_W_NO_NEW_DATA is the result.

    If I let it run once and then read out the wait and heat registers there are wrong (but constant) numbers in.

    Schakus_2-1610014397108.png

     

    What could I do? Is my verification correct?

     

    Thanks!

     

    15 REPLIES 15

    Jet
    Occasional Contributor

    Hi Sir:

        BME680 need to work with BSEC algorithm, I didn't found the BSEC content.

       Why did you not use BESC algorithm? Did you verify the API code of BME680?

    Sorry of course I am using the bosch library.

    Thats why I am asking if I am testing the i2c functions correctly.

    the i2c code is:

     

     

     

    int8_t user_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 */
    
        /*
         * The parameter dev_id can be used as a variable to store the I2C address of the device
         */
    
        /*
         * Data on the bus should be like
         * |------------+---------------------|
         * | I2C action | Data                |
         * |------------+---------------------|
         * | Start      | -                   |
         * | Write      | (reg_addr)          |
         * | Stop       | -                   |
         * | Start      | -                   |
         * | Read       | (reg_data[0])       |
         * | Read       | (....)              |
         * | Read       | (reg_data[len - 1]) |
         * | Stop       | -                   |
         * |------------+---------------------|
         */
        I2C1_WriteNBytes((dev_id | 0b00000001), &reg_addr, 1);
        I2C1_ReadNBytes((dev_id | 0b00000010), reg_data, len);
        
        return rslt;
    }
    
    int8_t user_i2c_write(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 */
    
        /*
         * The parameter dev_id can be used as a variable to store the I2C address of the device
         */
    
        /*
         * Data on the bus should be like
         * |------------+---------------------|
         * | I2C action | Data                |
         * |------------+---------------------|
         * | Start      | -                   |
         * | Write      | (reg_addr)          |
         * | Write      | (reg_data[0])       |
         * | Write      | (....)              |
         * | Write      | (reg_data[len - 1]) |
         * | Stop       | -                   |
         * |------------+---------------------|
         */
        uint8_t i2cWriteBuffer[50];
        
        int i;
        for (i = len; (i+1) > 0; i--) {
            i2cWriteBuffer[i+1] = reg_data[i];
        }
        i2cWriteBuffer[0] = reg_addr;
        
        I2C1_WriteNBytes((dev_id | 0b00000001), i2cWriteBuffer, len+1);
        return rslt;
    }

     

     

     

     

    And in my previous post you see that I am able to write and read the registers correctly. e.g. 0xD0 is the chip id, in the 0x72... I am writing some random values and reading them back.

     

    Thats why I don't understand why the library is not able to read the data correctly. I added an if in the example code:

     

     

     

    rslt = bme680_get_sensor_data(&data, &gas_sensor);
            
            if(rslt == BME680_W_NO_NEW_DATA){
                printf("bme680_get_sensor_data FAILED - BME680_W_NO_NEW_DATA\n");
            }

     

     

     

     and I am getting the random data for temperature, pressure,... you saw in my previous post and the rslt is: BME680_W_NO_NEW_DATA

    I also added the main.c file, maybe it gives an better overview. 

    Do you have an idea?

    Thanks

    Jet
    Occasional Contributor

    Hi Sir:

        1. If you can read out CHIP ID, maybe I2C communication is ok.

            Did you get the correct temperture/humidity/pressure/gas resistance? 

        2. I browsed your code, it is the API code ,not BESC code.

           It only can output gas resistance for BME680 API code. If you want to get IAQ, please choose BESC library.

            Did you use API code to verify I2C communication?

    Thanks for your answer.

    Read and write looks like working well. I found a bug in my write function (I didn't see that its not incrementing by writing multiple bytes). But still not working.

    No I don't get the correct values for temp,... the library is setting the result to: BME680_W_NO_NEW_DATA

     

    Which API code for verify do you mean?

    Okay I will have a look for the BSEC software.

     

    My current I2C test with multiple bytes (no library will be called):

    // reset
            buffer[0] = 0xB6;
            user_i2c_write(0x77, 0xE0, buffer, 1);
            
            user_delay_ms(1000);
            
            user_i2c_read(0x77, 0x50, buffer, 30);
            int i;
            for (i = 0; i < 30; i++) {
                printf("Read Reg 0x%X: 0x%X\n",(0x50+i),buffer[i]);
            }
            
            user_delay_ms(100);
            for (i = 0; i < 30; i++) {
                buffer[i] = 0x00+i;
            }
            user_i2c_write(0x77, 0x50, buffer, 30);
            printf("writing data...\n");
            
            user_delay_ms(100);
            
            user_i2c_read(0x77, 0x50, buffer, 30);
            for (i = 0; i < 30; i++) {
                printf("Read Reg 0x%X: 0x%X\n",(0x50+i),buffer[i]);
            }
            
            // reset
            buffer[0] = 0xB6;
            user_i2c_write(0x77, 0xE0, buffer, 1);
            printf("reseting...\n");
            user_delay_ms(1000);
            
            user_i2c_read(0x77, 0x50, buffer, 30);
            for (i = 0; i < 30; i++) {
                printf("Read Reg 0x%X: 0x%X\n",(0x50+i),buffer[i]);
            }
            
            while(1);

    Output serial window:

    START<\n>
    Read Reg 0x50: 0x0<\n>
    Read Reg 0x51: 0x0<\n>
    Read Reg 0x52: 0x0<\n>
    Read Reg 0x53: 0x0<\n>
    Read Reg 0x54: 0x0<\n>
    Read Reg 0x55: 0x0<\n>
    Read Reg 0x56: 0x0<\n>
    Read Reg 0x57: 0x0<\n>
    Read Reg 0x58: 0x0<\n>
    Read Reg 0x59: 0x0<\n>
    Read Reg 0x5A: 0x0<\n>
    Read Reg 0x5B: 0x0<\n>
    Read Reg 0x5C: 0x0<\n>
    Read Reg 0x5D: 0x0<\n>
    Read Reg 0x5E: 0x0<\n>
    Read Reg 0x5F: 0x0<\n>
    Read Reg 0x60: 0x0<\n>
    Read Reg 0x61: 0x0<\n>
    Read Reg 0x62: 0x0<\n>
    Read Reg 0x63: 0x0<\n>
    Read Reg 0x64: 0x0<\n>
    Read Reg 0x65: 0x0<\n>
    Read Reg 0x66: 0x0<\n>
    Read Reg 0x67: 0x0<\n>
    Read Reg 0x68: 0x0<\n>
    Read Reg 0x69: 0x0<\n>
    Read Reg 0x6A: 0x0<\n>
    Read Reg 0x6B: 0x0<\n>
    Read Reg 0x6C: 0x0<\n>
    Read Reg 0x6D: 0x0<\n>
    writing data...<\n>
    Read Reg 0x50: 0x0<\n>
    Read Reg 0x51: 0x1<\n>
    Read Reg 0x52: 0x2<\n>
    Read Reg 0x53: 0x3<\n>
    Read Reg 0x54: 0x4<\n>
    Read Reg 0x55: 0x5<\n>
    Read Reg 0x56: 0x6<\n>
    Read Reg 0x57: 0x7<\n>
    Read Reg 0x58: 0x8<\n>
    Read Reg 0x59: 0x9<\n>
    Read Reg 0x5A: 0xA<\n>
    Read Reg 0x5B: 0xB<\n>
    Read Reg 0x5C: 0xC<\n>
    Read Reg 0x5D: 0xD<\n>
    Read Reg 0x5E: 0xE<\n>
    Read Reg 0x5F: 0xF<\n>
    Read Reg 0x60: 0x10<\n>
    Read Reg 0x61: 0x11<\n>
    Read Reg 0x62: 0x12<\n>
    Read Reg 0x63: 0x13<\n>
    Read Reg 0x64: 0x14<\n>
    Read Reg 0x65: 0x15<\n>
    Read Reg 0x66: 0x16<\n>
    Read Reg 0x67: 0x17<\n>
    Read Reg 0x68: 0x18<\n>
    Read Reg 0x69: 0x19<\n>
    Read Reg 0x6A: 0x1A<\n>
    Read Reg 0x6B: 0x1B<\n>
    Read Reg 0x6C: 0x1C<\n>
    Read Reg 0x6D: 0x1D<\n>
    reseting...<\n>
    Read Reg 0x50: 0x0<\n>
    Read Reg 0x51: 0x0<\n>
    Read Reg 0x52: 0x0<\n>
    Read Reg 0x53: 0x0<\n>
    Read Reg 0x54: 0x0<\n>
    Read Reg 0x55: 0x0<\n>
    Read Reg 0x56: 0x0<\n>
    Read Reg 0x57: 0x0<\n>
    Read Reg 0x58: 0x0<\n>
    Read Reg 0x59: 0x0<\n>
    Read Reg 0x5A: 0x0<\n>
    Read Reg 0x5B: 0x0<\n>
    Read Reg 0x5C: 0x0<\n>
    Read Reg 0x5D: 0x0<\n>
    Read Reg 0x5E: 0x0<\n>
    Read Reg 0x5F: 0x0<\n>
    Read Reg 0x60: 0x0<\n>
    Read Reg 0x61: 0x0<\n>
    Read Reg 0x62: 0x0<\n>
    Read Reg 0x63: 0x0<\n>
    Read Reg 0x64: 0x0<\n>
    Read Reg 0x65: 0x0<\n>
    Read Reg 0x66: 0x0<\n>
    Read Reg 0x67: 0x0<\n>
    Read Reg 0x68: 0x0<\n>
    Read Reg 0x69: 0x0<\n>
    Read Reg 0x6A: 0x0<\n>
    Read Reg 0x6B: 0x0<\n>
    Read Reg 0x6C: 0x0<\n>
    Read Reg 0x6D: 0x0<\n>

     

    Looks good for me but the library will give me constant numbers back:

    T: 147.85 degC, P: 21522598.00 hPa, H 1308676.12 %rH <\r><\n>
    T: 147.85 degC, P: 21522598.00 hPa, H 1308676.12 %rH <\r><\n>
    T: 147.85 degC, P: 21522598.00 hPa, H 1308676.12 %rH <\r><\n>
    ...

     and the BME680_W_NO_NEW_DATA is set as rslt...

     

    Do you have an another idea?

     

    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