Hello Everyone, I am considering BME280 in one of our projects, using Sparkfun BME280 break out board to evaluate the accuracy and performance of the sensor. I am getting temperature, humidity, and pressure readings 0 (uncompensated value 0, after compensation temperature -40, humidity 0, and pressure 110000. struct bme280_dev dev;
uint32_t req_delay;
uint8_t i2c_try = 0;
/* BME280 sensor's API call */
static int8_t bme280_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr){
while (i2c_try < 5){
if (HAL_I2C_Mem_Read(&I2c2Handle, *(uint16_t *)intf_ptr, (uint16_t) reg_addr, 1, reg_data, (uint16_t) len, 1000) != HAL_OK){
I2C2_Error ();
i2c_try++;
} else {
i2c_try = 5;
}
}
i2c_try = 0;
return 0;
}
static int8_t bme280_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr){
while (i2c_try < 5){
if (HAL_I2C_Mem_Write(&I2c2Handle, *(uint16_t *) intf_ptr, (uint16_t) reg_addr, 1, reg_data, (uint16_t) len, 1000) != HAL_OK){
I2C2_Error ();
i2c_try++;
} else {
i2c_try = 5;
}
}
i2c_try = 0;
return 0;
}
static void bme280_delay_us(uint32_t period, void *intf_ptr){
HAL_Delay(1000);
}
int8_t bme280_Senosr_Init (void){
int8_t rslt = BME280_OK;
memset(&dev, 0, sizeof(struct bme280_dev));
uint8_t dev_addr = (BME280_I2C_ADDR_SEC << 1);
dev.intf_ptr = &dev_addr;
dev.intf = BME280_I2C_INTF;
dev.read = bme280_i2c_read;
dev.write = bme280_i2c_write;
dev.delay_us = bme280_delay_us;
rslt = bme280_init(&dev);
uint8_t settings_sel;
/* Recommended mode of operation: Weather monitoring */
dev.settings.osr_h = BME280_OVERSAMPLING_1X;
dev.settings.osr_p = BME280_OVERSAMPLING_1X;
dev.settings.osr_t = BME280_OVERSAMPLING_1X;
dev.settings.filter = BME280_FILTER_COEFF_OFF;
settings_sel = BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL;
rslt = bme280_set_sensor_settings(settings_sel, &dev);
/*Calculate the minimum delay required between consecutive measurement based upon the sensor enabled
* and the oversampling configuration. */
req_delay = bme280_cal_meas_delay(&dev.settings);
return rslt;
}
int8_t bme280_readings (struct bme280_data *comp_data){
int8_t rslt = BME280_OK;
rslt = bme280_set_sensor_mode(BME280_FORCED_MODE, &dev);
/* Wait for the measurement to complete and print data @25Hz */
dev.delay_us(req_delay, dev.intf_ptr);
rslt = bme280_get_sensor_data(BME280_ALL, comp_data, &dev);
return rslt;
} I have added a delay for 1 second between bme280_set_sensor_mode and bme280_get_sensor_data. I call bme280_Senosr_Init after I2C initialization at one time, bme280_readings in a process that runs every 10 seconds. I am using the BME280 V.3.50. Why BME280 not giving sensor reading correctly? Any thought? If more information needed to understand the problem, please let me know. Thanks! -Arya
... View more