Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BME280 returns reset values

    turboscrew
    New Poster

    Re: BME280 returns reset values

    I mask and OR the bits in the register.

    I also took a copy of your humidity compensation function to try, but it also gave zero for that raw value (0x5295).

     

    turboscrew
    New Poster

    Re: BME280 returns reset values

    #define BME280_ADDR 0xEC // 111011xR

    /* registers */
    #define BME280_RESET 0xE0
    #define BME280_CTRL_HUM 0xF2
    #define BME280_STATUS 0xF3
    #define BME280_CTRL_MEAS 0xF4
    #define BME280_CONFIG 0xF5
    #define BME280_PRESS_MSB 0xF7
    /* values */
    #define BME280_CFG_OSRSH 0x01
    #define BME280_CFG_OSRST 0x01
    #define BME280_CFG_OSRSP 0x01
    #define BME280_CFG_T_SB 0x04 /* every 500 ms */
    #define BME280_CFG_FILT 0x00
    #define BME280_MODE_NORMAL 0x03
    #define BME280_MODE_SLEEP 0x00
    #define BME280_MODE_FORCED 0x01

    void BME280_init(void)
    {
    uint8_t tmp;

    /* reset */
    write_reg(BME280_ADDR, BME280_RESET, 0xB6);
    HAL_Delay(2);
    tmp = read_reg(BME280_ADDR, BME280_STATUS);
    while ((tmp & 0x1) != 0)
    {
    /* wait until NVM reading is finished */
    tmp = read_reg(BME280_ADDR, BME280_STATUS);
    }
    /* read cal data */
    BME280_read_cal_data();
    /* configure */
    tmp = ((BME280_CFG_OSRST & 7) << 5) || ((BME280_CFG_OSRSP & 7) << 2) || (BME280_MODE_NORMAL & 3);
    write_reg(BME280_ADDR, BME280_CONFIG, (((BME280_CFG_T_SB & 7) << 5) || ((BME280_CFG_FILT & 7) << 2)));
    write_reg(BME280_ADDR, BME280_CTRL_MEAS,tmp);
    write_reg(BME280_ADDR, BME280_CTRL_HUM, (BME280_CFG_OSRSH & 7));
    write_reg(BME280_ADDR, BME280_CTRL_MEAS,tmp);
    }

    (The code tag doesn't seem to work.)

     

    Vincent
    Community Moderator

    Re: BME280 returns reset values

    1. no need to read status bit during sensor reset.  you can check the chip id.  if chip id matched the desired value,  means sensor reset is done sucessfully

    2.  the correct flow should be as following:

    tmp = ((BME280_CFG_OSRST & 7) << 5) || ((BME280_CFG_OSRSP & 7) << 2) || (BME280_MODE_NORMAL & 0x00);
    write_reg(BME280_ADDR, BME280_CTRL_HUM, (BME280_CFG_OSRSH & 7));

    write_reg(BME280_ADDR, BME280_CONFIG, (((BME280_CFG_T_SB & 7) << 5) || ((BME280_CFG_FILT & 7) << 2)));
    write_reg(BME280_ADDR, BME280_CTRL_MEAS,tmp);
    tmp = ((BME280_CFG_OSRST & 7) << 5) || ((BME280_CFG_OSRSP & 7) << 2) || (BME280_MODE_NORMAL & 3);

    write_reg(BME280_ADDR, BME280_CTRL_MEAS,tmp);
    when the mode register is changed,  the measurement is suppose to start directly.   So it is better to set the configuration first,  then change the working mode afterwards.

    Then you should have the non zero in the ADC register of sensor.

    turboscrew
    New Poster

    Re: BME280 returns reset values

    Instead of polling of chip ID I do:

    while ((tmp & 0x1) != 0)
    {
    /* wait until NVM reading is finished */
    tmp = read_reg(BME280_ADDR, BME280_STATUS);
    }

    Does this: BME280_MODE_NORMAL & 0x00 mean the chip is to put to sleep?

    And there is a non-zero value in humidity register(s), but it's such that the compensation algorithm returns zero.

    buff[6] uint8_t 0x52 (Hex)
    buff[7] uint8_t 0x95 (Hex)

    How many bit ADC is used for humidity? The value (0x5295) has 15 bits.

    It seems like the result is zeroed at:

    var5 = (var5 < 0 ? 0 : var5);

    (humidity compensation code from your repo)

     

    Vincent
    Community Moderator

    Re: BME280 returns reset values

    Yes, if the mode [0:1] shows 0 means sensor is in sleep mode. 

    But i don't suggest you to check these bits and status bits just after reset sensor.   I will recommend you to check chip id instead after power cycle the sensor.

    16 bits ADC value are used to calculate humidity. 

    Can you check again your calibration parameters?  And also try to use the latest API from our Github.   

     

    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