I am trying to get the temperature, pressure and humidity from the BME280 sensor through i2c but I am getting the same readings all the time: 24.05 deg C, 632.83 hPa, 53.13% 24.05 deg C, 632.83 hPa, 53.13% 24.05 deg C, 632.83 hPa, 53.13% 24.05 deg C, 632.83 hPa, 53.13% I read a similar problem from another user's post in this forum but, in that case, he had configured the interface as SPI instead of i2c but I have it correctly set. This is the sensor initialization code I am using: int8_t bme280_sensor_init(void)
{
dev.dev_id = BME280_I2C_ADDR_SEC; //BME280_I2C_ADDR_PRIM;
dev.intf = BME280_I2C_INTF;
dev.read = bme280_i2c_read;
dev.write = bme280_i2c_write;
dev.delay_ms = user_delay_ms;
int8_t result = bme280_init(&dev);
if(result != BME280_OK)
return -1;
// I tried both setting values with same result
// dev.settings.osr_h = BME280_OVERSAMPLING_1X;
// dev.settings.osr_p = BME280_OVERSAMPLING_16X;
// dev.settings.osr_t = BME280_OVERSAMPLING_2X;
// dev.settings.filter = BME280_FILTER_COEFF_16;
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;
uint8_t settings_sel = BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL;
result = bme280_set_sensor_settings(settings_sel, &dev);
if(result != BME280_OK)
return -1;
return 0;
} This is the code I use to read the values: int8_t bme280_sensor_read(float *temp, float *press, float *hum)
{
struct bme280_data comp_data;
/* configure forced mode */
uint8_t result = bme280_set_sensor_mode(BME280_FORCED_MODE, &dev);
if(result != BME280_OK)
return -1;
/* wait for the measurements to complete */
dev.delay_ms(1000);//40
result = bme280_get_sensor_data(BME280_ALL, &comp_data, &dev);
if(result != BME280_OK)
return -1;
/* Read was ok, update values */
#ifdef BME280_FLOAT_ENABLE
*temp = comp_data.temperature;
*press = 0.01 * comp_data.pressure;
*hum = comp_data.humidity;
#else
#ifdef BME280_64BIT_ENABLE
*temp = 0.01f * comp_data.temperature;
*press = 0.0001f * comp_data.pressure;
*hum = 1.0f / 1024.0f * comp_data.humidity;
#else
*temp = 0.01f * comp_data.temperature; // USING THIS
*press = 0.01f * comp_data.pressure;
*hum = 1.0f / 1024.0f * comp_data.humidity;
#endif
#endif
return 0;
} In bme280_defs.h file I have commented out the BME280_64BIT_ENABLE definition: #ifndef BME280_FLOAT_ENABLE
/* #define BME280_FLOAT_ENABLE */
#endif
#ifndef BME280_FLOAT_ENABLE
#ifndef BME280_64BIT_ENABLE
//#define BME280_64BIT_ENABLE
#endif
#endif Am I missing something? any help or tip about how to procceed ? Thanks, Javi EDIT: Just in case it helps, I have added some debug traces in the read and write callbacks. I print the device addres, register address, register data, length and, in case of a read, the bytes read Initializating I2C
[R] 0x77 0xD0 0x60 01: 60
[W] 0x77 0xE0 0xB6 01
[R] 0x77 0xF3 0x00 01: 00
[R] 0x77 0x88 0x2C 26: 2C 6D 30 66 32 00 F8 8D 16 D6 D0 0B DF 25 2D FF F9 FF 0C 30 20 D1 88 13 00 4B
[R] 0x77 0xE1 0x5B 07: 5B 01 00 16 23 03 1E
[R] 0x77 0xF4 0xEC 01: EC
[W] 0x77 0xF2 0x01 01
[R] 0x77 0xF4 0xEC 01: EC
[W] 0x77 0xF4 0xEC 01
[R] 0x77 0xF4 0xE4 01: E4
[W] 0x77 0xF4 0x24 01
[R] 0x77 0xF5 0xFC 01: FC
[W] 0x77 0xF5 0xE0 01
Setting forced mode
[R] 0x77 0xF4 0xDC 01: DC
[R] 0x77 0xF4 0xDC 01: DC
[W] 0x77 0xF4 0xDD 01
Getting sensor data
[R] 0x77 0xF7 0x80 08: 80 00 00 80 00 00 80 00
24.05 deg C, 632.83 hPa, 53.13%
... View more