This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to get Pressure and Humidity using BME280 with nrf52840 DK

Hi Nordic Team,

I have interfaced bme280 with nrf52840 and I got the temperature successfully. I have used https://github.com/knuta/nrf5-bme280-twi link for that.

Here in bme280_twi_measurement_fetch() function I've change the address from 0xFA to 0xF7, still I'm not getting the pressure, same with the humidity.

Can any one please help me out of this.

Regards.

  • Hi,

    Have you checked the datasheet of the sensor to see if there is anything else needed to get pressure/humidity data? E.g. some config to enable these measurements?

    What do you get when trying to read pressure/humidity? No data at all, or some kind of error?

    Best regards,
    Jørgen

  • Yes I've gone through the datasheet, need to change the address for getting others data, for temperature it is 0xFA and for pressure it is 0xF7. I'm attaching my snippet kindly look on that

    static void _compensate_temp(int32_t adc_T, int32_t *temp,int32_t adc_P, int32_t *press)
    {
       int32_t var3 = ((((adc_T>>3) - ((int32_t)m_dig_T1<<1))) * ((int32_t)m_dig_T2)) >> 11;
       int32_t var4 = (((((adc_T>>4) - ((int32_t)m_dig_T1)) * ((adc_T>>4) - ((int32_t)m_dig_T1))) >> 12) *
                      ((int32_t)m_dig_T3)) >> 14;
       t = var3 + var4;
       *temp = ((var3 + var4) * 5 + 128) >> 8;
    
       int32_t var1 = (((int32_t)t) >> 1) - (int32_t)64000;
       int32_t var2 = (((var1 >> 2) * (var1 >> 2)) >> 11)
         * ((int32_t)m_dig_P6);
       var2 = var2 + ((var1 * ((int32_t)m_dig_P5)) << 1);
       var2 = (var2 >> 2) + (((int32_t)m_dig_P4) << 16);
       var1 = (((m_dig_P3 * (((var1 >> 2) * (var1 >> 2)) >> 13)) >> 3)
          + ((((int32_t)m_dig_P2) * var1) >> 1)) >> 18;
       var1 = ((((32768 + var1)) * ((int32_t)m_dig_P1)) >> 15);
     
       if(var1 == 0) {
         return; /* Avoid exception caused by division by zero */
       }
     
       pressure = (((uint32_t)(((int32_t)1048576) - adc_P) - (var2 >> 12)))
         * 3125;
       if(pressure < 0x80000000) {
         pressure = (pressure << 1) / ((uint32_t)var1);
       } else {
         pressure = (pressure / (uint32_t)var1) * 2;
       }
     
       var1 = (((int32_t)m_dig_P9)
                    * ((int32_t)(((pressure >> 3) * (pressure >> 3)) >> 13))) >> 12;
       var2 = (((int32_t)(pressure >> 2)) * ((int32_t)m_dig_P8)) >> 13;
       pressure = (uint32_t)((int32_t)pressure
                             + ((var1 + var2 + m_dig_P7) >> 4));
     
       *press = pressure;
       printf("\r%d\r\n",*press);
    }
    
    void bme280_twi_measurement_fetch(void)
    {
    	_read(0xFA, m_buf, 3);
             nrf_delay_ms(100);
            _read(0xF7, m_buf2, 3);
    
            //_read(_REG_CTRL_HUM, m_buf, 3);
    
    }
    
    void bme280_twi_measurement_get_temp(bme280_twi_data_t *data)
    {
    	_compensate_temp(m_temp_raw, &data->temp,m_press_raw, &data->pressure);
    }
     

    Here in the attached code it is not executing to var1 and var2 which is for getting pressure, as I can't able to put the breakpoint here. it is jumping after calculating var3 and var4.

    Thanks.

  • The datasheet also says that (temperature,) humidity and pressure measurements can be skipped (in section 3.4). Looking at the code you linked, it seems to actually skip these measurements. Did you change the code to enable the measurements again?

  • Hello, 

    i'm having similar problem with bme280 sensor but with NRF5340  
    i'm  seeking help 
    thanks in advance

  • Someone will help you out in the ticket you have posted.

    This ticket is regarding nRF5 SDK, while nRF5340 only is supported in nRF Connect SDK. These SDKs have quite different architectures and drivers.

Related