Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMP280 MSB temperature is sometimes corrupted

    Jussi
    Member

    Re: BMP280 MSB temperature is sometimes corrupted

    I have tried with multiple different sensors and boards. I can open the attachment just fine. I'll just copy paste the log here.

     

    [00:00:05.230,133] <dbg> bmp280.read_pressure: Uncom data. Temp: 509328 (0x7c590), Press: 326160 (0x4fa10)
    [00:00:05.230,163] <dbg> bmp280.read_pressure: Got compensated temperature: 21.26
    [00:00:05.230,255] <dbg> bmp280.read_pressure: Got compensated pressure: 998.91
    [00:00:10.220,397] <dbg> bmp280.read_pressure: Uncom data. Temp: 509328 (0x7c590), Press: 326160 (0x4fa10)
    [00:00:10.220,428] <dbg> bmp280.read_pressure: Got compensated temperature: 21.26
    [00:00:10.220,520] <dbg> bmp280.read_pressure: Got compensated pressure: 998.91
    [00:00:15.220,672] <dbg> bmp280.read_pressure: Uncom data. Temp: 509304 (0x7c578), Press: 326156 (0x4fa0c)
    [00:00:15.220,703] <dbg> bmp280.read_pressure: Got compensated temperature: 21.25
    [00:00:15.220,794] <dbg> bmp280.read_pressure: Got compensated pressure: 998.90
    [00:00:20.220,947] <dbg> bmp280.read_pressure: Uncom data. Temp: 509328 (0x7c590), Press: 326156 (0x4fa0c)
    [00:00:20.220,977] <dbg> bmp280.read_pressure: Got compensated temperature: 21.26
    [00:00:20.221,069] <dbg> bmp280.read_pressure: Got compensated pressure: 998.92
    [00:00:25.220,214] <dbg> bmp280.read_pressure: Uncom data. Temp: 509312 (0x7c580), Press: 326160 (0x4fa10)
    [00:00:25.220,245] <dbg> bmp280.read_pressure: Got compensated temperature: 21.26
    [00:00:25.220,336] <dbg> bmp280.read_pressure: Got compensated pressure: 998.90
    [00:00:30.220,489] <dbg> bmp280.read_pressure: Uncom data. Temp: 509328 (0x7c590), Press: 326144 (0x4fa00)
    [00:00:30.220,520] <dbg> bmp280.read_pressure: Got compensated temperature: 21.26
    [00:00:30.220,611] <dbg> bmp280.read_pressure: Got compensated pressure: 998.94
    [00:00:35.220,764] <dbg> bmp280.read_pressure: Uncom data. Temp: 509312 (0x7c580), Press: 326168 (0x4fa18)
    [00:00:35.220,794] <dbg> bmp280.read_pressure: Got compensated temperature: 21.26
    [00:00:35.220,886] <dbg> bmp280.read_pressure: Got compensated pressure: 998.89
    [00:00:40.221,038] <dbg> bmp280.read_pressure: Uncom data. Temp: 509304 (0x7c578), Press: 326184 (0x4fa28)
    [00:00:40.221,069] <dbg> bmp280.read_pressure: Got compensated temperature: 21.25
    [00:00:40.221,160] <dbg> bmp280.read_pressure: Got compensated pressure: 998.86
    [00:00:45.221,313] <dbg> bmp280.read_pressure: Uncom data. Temp: 509304 (0x7c578), Press: 326164 (0x4fa14)
    [00:00:45.221,343] <dbg> bmp280.read_pressure: Got compensated temperature: 21.25
    [00:00:45.221,435] <dbg> bmp280.read_pressure: Got compensated pressure: 998.89
    [00:00:50.221,618] <dbg> bmp280.read_pressure: Uncom data. Temp: 247168 (0x3c580), Press: 326140 (0x4f9fc)
    [00:00:50.221,649] <dbg> bmp280.read_pressure: Got compensated temperature: -60.00
    [00:00:50.221,740] <dbg> bmp280.read_pressure: Got compensated pressure: 873.32
    [00:00:50.241,699] <dbg> bmp280.read_pressure: Uncom data. Temp: 509368 (0x7c5b8), Press: 326144 (0x4fa00)
    [00:00:50.241,760] <dbg> bmp280.read_pressure: Got compensated temperature: 21.27
    [00:00:50.241,851] <dbg> bmp280.read_pressure: Got compensated pressure: 998.96
    [00:00:55.222,015] <dbg> bmp280.read_pressure: Uncom data. Temp: 247192 (0x3c598), Press: 326132 (0x4f9f4)
    [00:00:55.222,045] <dbg> bmp280.read_pressure: Got compensated temperature: -59.99
    [00:00:55.222,137] <dbg> bmp280.read_pressure: Got compensated pressure: 873.34
    [00:00:55.242,095] <dbg> bmp280.read_pressure: Uncom data. Temp: 247224 (0x3c5b8), Press: 326148 (0x4fa04)
    [00:00:55.242,156] <dbg> bmp280.read_pressure: Got compensated temperature: -59.98
    [00:00:55.242,248] <dbg> bmp280.read_pressure: Got compensated pressure: 873.33
    [00:00:55.265,228] <dbg> bmp280.read_pressure: Uncom data. Temp: 247264 (0x3c5e0), Press: 326180 (0x4fa24)
    [00:00:55.265,289] <dbg> bmp280.read_pressure: Got compensated temperature: -59.97
    [00:00:55.265,380] <dbg> bmp280.read_pressure: Got compensated pressure: 873.30
    [00:00:55.293,304] <dbg> bmp280.read_pressure: Uncom data. Temp: 247304 (0x3c608), Press: 326188 (0x4fa2c)
    [00:00:55.293,334] <dbg> bmp280.read_pressure: Got compensated temperature: -59.96
    [00:00:55.293,426] <dbg> bmp280.read_pressure: Got compensated pressure: 873.31
    [00:01:00.222,564] <dbg> bmp280.read_pressure: Uncom data. Temp: 247176 (0x3c588), Press: 326132 (0x4f9f4)
    [00:01:00.222,595] <dbg> bmp280.read_pressure: Got compensated temperature: -60.00
    [00:01:00.222,686] <dbg> bmp280.read_pressure: Got compensated pressure: 873.33
    [00:01:05.222,839] <dbg> bmp280.read_pressure: Uncom data. Temp: 509288 (0x7c568), Press: 326144 (0x4fa00)
    [00:01:05.222,869] <dbg> bmp280.read_pressure: Got compensated temperature: 21.25
    [00:01:05.222,961] <dbg> bmp280.read_pressure: Got compensated pressure: 998.92
    [00:01:05.242,919] <dbg> bmp280.read_pressure: Uncom data. Temp: 509360 (0x7c5b0), Press: 326168 (0x4fa18)
    [00:01:05.242,980] <dbg> bmp280.read_pressure: Got compensated temperature: 21.27
    [00:01:05.243,072] <dbg> bmp280.read_pressure: Got compensated pressure: 998.91
    [00:01:05.266,052] <dbg> bmp280.read_pressure: Uncom data. Temp: 247264 (0x3c5e0), Press: 326164 (0x4fa14)
    [00:01:05.266,113] <dbg> bmp280.read_pressure: Got compensated temperature: -59.97
    [00:01:05.266,204] <dbg> bmp280.read_pressure: Got compensated pressure: 873.33
    [00:01:10.222,351] <dbg> bmp280.read_pressure: Uncom data. Temp: 247160 (0x3c578), Press: 326164 (0x4fa14)
    [00:01:10.222,381] <dbg> bmp280.read_pressure: Got compensated temperature: -60.00
    [00:01:10.222,473] <dbg> bmp280.read_pressure: Got compensated pressure: 873.28
    [00:01:15.222,625] <dbg> bmp280.read_pressure: Uncom data. Temp: 509304 (0x7c578), Press: 326152 (0x4fa08)
    [00:01:15.222,656] <dbg> bmp280.read_pressure: Got compensated temperature: 21.25
    [00:01:15.222,747] <dbg> bmp280.read_pressure: Got compensated pressure: 998.91
    [00:01:15.242,706] <dbg> bmp280.read_pressure: Uncom data. Temp: 247224 (0x3c5b8), Press: 326172 (0x4fa1c)
    [00:01:15.242,767] <dbg> bmp280.read_pressure: Got compensated temperature: -59.98
    [00:01:15.242,858] <dbg> bmp280.read_pressure: Got compensated pressure: 873.30
    [00:01:20.223,022] <dbg> bmp280.read_pressure: Uncom data. Temp: 509296 (0x7c570), Press: 326168 (0x4fa18)
    [00:01:20.223,052] <dbg> bmp280.read_pressure: Got compensated temperature: 21.25
    [00:01:20.223,144] <dbg> bmp280.read_pressure: Got compensated pressure: 998.88
    [00:01:20.243,103] <dbg> bmp280.read_pressure: Uncom data. Temp: 247200 (0x3c5a0), Press: 326172 (0x4fa1c)
    [00:01:20.243,164] <dbg> bmp280.read_pressure: Got compensated temperature: -59.99
    [00:01:20.243,255] <dbg> bmp280.read_pressure: Got compensated pressure: 873.29
    [00:01:25.223,419] <dbg> bmp280.read_pressure: Uncom data. Temp: 247224 (0x3c5b8), Press: 326172 (0x4fa1c)
    [00:01:25.223,449] <dbg> bmp280.read_pressure: Got compensated temperature: -59.98
    [00:01:25.223,541] <dbg> bmp280.read_pressure: Got compensated pressure: 873.30
    [00:01:30.223,693] <dbg> bmp280.read_pressure: Uncom data. Temp: 509520 (0x7c650), Press: 326192 (0x4fa30)
    [00:01:30.223,724] <dbg> bmp280.read_pressure: Got compensated temperature: 21.32
    [00:01:30.223,815] <dbg> bmp280.read_pressure: Got compensated pressure: 998.95
    [00:01:30.243,774] <dbg> bmp280.read_pressure: Uncom data. Temp: 247416 (0x3c678), Press: 326236 (0x4fa5c)
    [00:01:30.243,835] <dbg> bmp280.read_pressure: Got compensated temperature: -59.92
    [00:01:30.243,927] <dbg> bmp280.read_pressure: Got compensated pressure: 873.29
    [00:01:35.223,083] <dbg> bmp280.read_pressure: Uncom data. Temp: 247464 (0x3c6a8), Press: 326196 (0x4fa34)
    [00:01:35.223,114] <dbg> bmp280.read_pressure: Got compensated temperature: -59.91
    [00:01:35.223,205] <dbg> bmp280.read_pressure: Got compensated pressure: 873.37
    [00:01:40.223,388] <dbg> bmp280.read_pressure: Uncom data. Temp: 509712 (0x7c710), Press: 326252 (0x4fa6c)
    [00:01:40.223,419] <dbg> bmp280.read_pressure: Got compensated temperature: 21.38
    [00:01:40.223,510] <dbg> bmp280.read_pressure: Got compensated pressure: 998.95
    [00:01:40.243,469] <dbg> bmp280.read_pressure: Uncom data. Temp: 509752 (0x7c738), Press: 326272 (0x4fa80)
    [00:01:40.243,530] <dbg> bmp280.read_pressure: Got compensated temperature: 21.39
    [00:01:40.243,621] <dbg> bmp280.read_pressure: Got compensated pressure: 998.94
    [00:01:40.266,571] <dbg> bmp280.read_pressure: Uncom data. Temp: 509800 (0x7c768), Press: 326304 (0x4faa0)
    [00:01:40.266,632] <dbg> bmp280.read_pressure: Got compensated temperature: 21.41
    [00:01:40.266,723] <dbg> bmp280.read_pressure: Got compensated pressure: 998.91
    [00:01:40.294,647] <dbg> bmp280.read_pressure: Uncom data. Temp: 509848 (0x7c798), Press: 326308 (0x4faa4)
    [00:01:40.294,677] <dbg> bmp280.read_pressure: Got compensated temperature: 21.42
    [00:01:40.294,769] <dbg> bmp280.read_pressure: Got compensated pressure: 998.93
    [00:01:45.223,907] <dbg> bmp280.read_pressure: Uncom data. Temp: 509816 (0x7c778), Press: 326340 (0x4fac4)
    [00:01:45.223,937] <dbg> bmp280.read_pressure: Got compensated temperature: 21.41
    [00:01:45.224,029] <dbg> bmp280.read_pressure: Got compensated pressure: 998.86
    [00:01:50.223,175] <dbg> bmp280.read_pressure: Uncom data. Temp: 509952 (0x7c800), Press: 326384 (0x4faf0)
    [00:01:50.223,205] <dbg> bmp280.read_pressure: Got compensated temperature: 21.46
    [00:01:50.223,297] <dbg> bmp280.read_pressure: Got compensated pressure: 998.85
    [00:01:55.223,449] <dbg> bmp280.read_pressure: Uncom data. Temp: 510064 (0x7c870), Press: 326392 (0x4faf8)
    [00:01:55.223,480] <dbg> bmp280.read_pressure: Got compensated temperature: 21.49
    [00:01:55.223,571] <dbg> bmp280.read_pressure: Got compensated pressure: 998.90
    [00:02:00.223,724] <dbg> bmp280.read_pressure: Uncom data. Temp: 510176 (0x7c8e0), Press: 326444 (0x4fb2c)
    [00:02:00.223,754] <dbg> bmp280.read_pressure: Got compensated temperature: 21.53
    [00:02:00.223,846] <dbg> bmp280.read_pressure: Got compensated pressure: 998.87
    Jussi
    Member

    Re: BMP280 MSB temperature is sometimes corrupted

    And the codes:

    static int init() {
      int err = 0;
    
      if (initialized) {
        return 0;
      }
    
      bmp.dev_id = I2C_ADD_BMP280;
      bmp.intf = BMP280_I2C_INTF;
    
      bmp.delay_ms = delay_ms;
      bmp.read = i2c_reg_read;
      bmp.write = i2c_reg_write;
    
      err = bmp280_init(&bmp);
      if (err != 0) {
        LOG_DBG("bmp280_init failed: %d", err);
        return err;
      }
    
      err = bmp280_get_config(&conf, &bmp);
      if (err != 0) {
        return err;
      }
      LOG_DBG("os_temp=%u, os_pres=%u, odr=%u, filter=%u, spi3w_en=%u",
              conf.os_temp, conf.os_pres, conf.odr, conf.filter, conf.spi3w_en);
    
      conf.os_temp = BMP280_OS_2X;
      conf.filter = BMP280_FILTER_COEFF_2;
    
      conf.os_pres = BMP280_OS_4X;
      // Not used in forced mode actually
      conf.odr = BMP280_ODR_1000_MS;
    
      // Note that this function internally sets bmp->conf = conf
      err = bmp280_set_config(&conf, &bmp);
      if (err != 0) {
        return err;
      }
      initialized = true;
      return err;
    }
    
    static int read_pressure(float* pressure_hpa_out) {
      int err = init();
      if (err) {
        return err;
      }
    
      // Settnig the power mode to forced, triggers the measurement
      err = bmp280_set_power_mode(BMP280_FORCED_MODE, &bmp);
      if (err != 0) {
        return err;
      }
    
      struct bmp280_uncomp_data ucomp_data;
      double pres, temperature;
    
      // According to  data sheet, measurement time should be around 12ms with these settings
      // If we wait 11+2=13ms result seems to be ready according to experiments
      k_sleep(K_MSEC(11));
    
      struct bmp280_status status;
      // Just in case sensor is not ready yet, poll the status register for a while
      int max_wait = 5;
      do {
        k_sleep(K_MSEC(2));
        err = bmp280_get_status(&status, &bmp);
        if (err != 0) {
          return err;
        }
        LOG_DBG("measuring=%s, im_update=%s", status.measuring ? "true" : "false", status.im_update ? "true" : "false");
      } while (status.measuring && max_wait-- > 0);
    
      // Reading the data is a delegant business with this driver. First read raw data.
      err = bmp280_get_uncomp_data(&ucomp_data, &bmp);
      if (err != 0) {
        return err;
      }
      LOG_DBG("Uncom data. Temp: %d (0x%X), Press: %u (0x%X)",
              ucomp_data.uncomp_temp, ucomp_data.uncomp_temp, ucomp_data.uncomp_press, ucomp_data.uncomp_press);
    
      // Then we have to read the compensated temperature, although we don't really need it for anything
      // This sets things straight inside the driver
      err = bmp280_get_comp_temp_double(&temperature, ucomp_data.uncomp_temp, &bmp);
      if (err != 0) {
        return err;
      }
      LOG_DBG("Got compensated temperature: " LONE_FLOAT_FORMATTER, LONE_FLOAT_ARG((float)temperature));
    
      // And then we can read the compensated pressure
      err = bmp280_get_comp_pres_double(&pres, ucomp_data.uncomp_press, &bmp);
      if (err != 0) {
        return err;
      }
    
      // From Pa to hPa
      *pressure_hpa_out = (float)(pres / 100);
      LOG_DBG("Got compensated pressure: " LONE_FLOAT_FORMATTER, LONE_FLOAT_ARG(*pressure_hpa_out));
    
      return 0;
    }

     

    Yanchao
    Community Moderator

    Re: BMP280 MSB temperature is sometimes corrupted

    Hi,

    Yesteday, I test BMP280 pressure and temp data with COINES/APP2.0/BMP280 shuttle, haven't find this issue.

    From your code and log, BMP280 configed in Force mode, before read temp/press register data, there 5x2ms round read bmp280_get_status(), your sample interval nearly 5sec.

    One suggestion, in Force mode, make 5x100ms round read bmp280_get_status().

    Another suggestion, try to use Normal mode to get press/temp data, and log data as API examples.

    Wait for your feedback!

    Best regards.

    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