Skip to content

Commit 7875e5c

Browse files
authored
Merge pull request #10 from xoseperez/master
Perform burst reads for pressure, temperature and humidity
2 parents df329f6 + 998021d commit 7875e5c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/SparkFunBME280.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ float BME280::readFloatPressure( void )
282282

283283
// Returns pressure in Pa as unsigned 32 bit integer in Q24.8 format (24 integer bits and 8 fractional bits).
284284
// Output value of “24674867” represents 24674867/256 = 96386.2 Pa = 963.862 hPa
285-
int32_t adc_P = ((uint32_t)readRegister(BME280_PRESSURE_MSB_REG) << 12) | ((uint32_t)readRegister(BME280_PRESSURE_LSB_REG) << 4) | ((readRegister(BME280_PRESSURE_XLSB_REG) >> 4) & 0x0F);
285+
uint8_t buffer[3];
286+
readRegisterRegion(buffer, BME280_PRESSURE_MSB_REG, 3);
287+
int32_t adc_P = ((uint32_t)buffer[0] << 12) | ((uint32_t)buffer[1] << 4) | ((buffer[2] >> 4) & 0x0F);
286288

287289
int64_t var1, var2, p_acc;
288290
var1 = ((int64_t)t_fine) - 128000;
@@ -347,7 +349,9 @@ float BME280::readFloatHumidity( void )
347349

348350
// Returns humidity in %RH as unsigned 32 bit integer in Q22. 10 format (22 integer and 10 fractional bits).
349351
// Output value of “47445” represents 47445/1024 = 46. 333 %RH
350-
int32_t adc_H = ((uint32_t)readRegister(BME280_HUMIDITY_MSB_REG) << 8) | ((uint32_t)readRegister(BME280_HUMIDITY_LSB_REG));
352+
uint8_t buffer[2];
353+
readRegisterRegion(buffer, BME280_HUMIDITY_MSB_REG, 2);
354+
int32_t adc_H = ((uint32_t)buffer[0] << 8) | ((uint32_t)buffer[1]);
351355

352356
int32_t var1;
353357
var1 = (t_fine - ((int32_t)76800));
@@ -376,7 +380,9 @@ float BME280::readTempC( void )
376380
// t_fine carries fine temperature as global value
377381

378382
//get the reading (adc_T);
379-
int32_t adc_T = ((uint32_t)readRegister(BME280_TEMPERATURE_MSB_REG) << 12) | ((uint32_t)readRegister(BME280_TEMPERATURE_LSB_REG) << 4) | ((readRegister(BME280_TEMPERATURE_XLSB_REG) >> 4) & 0x0F);
383+
uint8_t buffer[3];
384+
readRegisterRegion(buffer, BME280_TEMPERATURE_MSB_REG, 3);
385+
int32_t adc_T = ((uint32_t)buffer[0] << 12) | ((uint32_t)buffer[1] << 4) | ((buffer[2] >> 4) & 0x0F);
380386

381387
//By datasheet, calibrate
382388
int64_t var1, var2;

0 commit comments

Comments
 (0)