Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BME280 reporting the same temperature values

    BME280 reporting the same temperature values

    Ale_00
    New Poster

    Hi,

    I'm currently using a BME280 to read temperature using I2C with STM32 F401RTE. The problem is that I succesfully initialized the sensor  but when I read the temperature I got 22.4879 every time. Below I copy the init function for the sensor and the code I use to read the data.  I'm using the latest version of bme280 library (v.3.5.1).

    struct bme280_dev sensore;
    struct bme280_settings *settings;

    void init_sensore (){

    int8_t rslt = BME280_OK;

    uint8_t dev_addr = 0x76;
    int8_t (*read_ptr)(uint8_t, uint8_t *, uint32_t, void *) = &user_i2c_read;
    int8_t (*write_ptr)(uint8_t, const uint8_t * ,uint32_t, void *) = &user_i2c_write;
    void (*delay_ptr)(uint32_t, void *) = &user_delay_us;

    sensore.intf_ptr = &dev_addr;
    sensore.intf = BME280_I2C_INTF;
    sensore.read = user_i2c_read;
    sensore.write = user_i2c_write;
    sensore.delay_us = user_delay_us;


    rslt = bme280_init(&sensore);

    settings->filter = BME280_FILTER_COEFF_16;

    settings->osr_h = BME280_NO_OVERSAMPLING;
    settings->osr_p = BME280_NO_OVERSAMPLING;;
    settings->osr_t = BME280_OVERSAMPLING_1X;

    settings->standby_time = BME280_STANDBY_TIME_0_5_MS;

    rslt = bme280_set_sensor_settings(BME280_SEL_ALL_SETTINGS, settings, &sensore);

    rslt = bme280_set_sensor_mode(BME280_POWERMODE_NORMAL, &sensore);
    }

    float read_temperature(){
    float temperature;
    uint32_t period = 40;
    struct bme280_data comp_data;
    int8_t rslt;

    user_delay_us(period, sensore.intf_ptr);

    rslt = bme280_get_sensor_data(BME280_TEMP, &comp_data, &sensore);

    temperature = comp_data.temperature;

    return temperature;
    }

    1 REPLY 1

    BSTRobin
    Community Moderator
    Community Moderator

    Hi Ale_00,

    The original definition of read-write functions is as follows:
    typedef BME280_INTF_RET_TYPE (*bme280_read_fptr_t)(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr);
    typedef BME280_INTF_RET_TYPE (*bme280_write_fptr_t)(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len,
    void *intf_ptr);

    I upload BME280 example code on STM32F401 for your reference.

    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