34 0, 0, SLEEP_MODE, SKIPPED, SKIPPED, 0, FILTER_OFF, STB_TIME_0_5};
46 0, 0, FORCED_MODE, SKIPPED, OVERSAMPLING_1, 0, FILTER_OFF, STB_TIME_0_5};
49 : spiSlave(spiSlave), config(config)
57 LOG_ERR(logger,
"Invalid WHO AM I");
64 miosix::Thread::sleep(3);
66 loadCompensationParameters();
70 miosix::Thread::sleep(
80 if (config.
bytes.ctrlPressureAndTemperature !=
81 readBackConfig.bytes.ctrlPressureAndTemperature ||
82 config.
bytes.config != readBackConfig.bytes.config)
84 LOG_ERR(logger,
"Device configuration incorrect, setup failed");
95 config.
bits.mode = mode;
102 config.
bits.oversamplingPressure = oversampling;
109 config.
bits.oversamplingTemperature = oversampling;
116 config.
bits.filter = filterCoeff;
123 config.
bits.standbyTime = standbyTime;
138 int32_t adc_P = ((uint32_t)buffer[0]) << 12;
139 adc_P |= ((uint32_t)buffer[1]) << 4;
140 adc_P |= (buffer[2] >> 4) & 0x0F;
144 data.
pressure = compensatePressure(adc_P);
160 int32_t adcTemperature = ((uint32_t)buffer[0]) << 12;
161 adcTemperature |= ((uint32_t)buffer[1]) << 4;
162 adcTemperature |= (buffer[2] >> 4) & 0x0F;
164 fineTemperature = computeFineTemperature(adcTemperature);
168 data.
temperature = compensateTemperature(fineTemperature);
178 return ceil(1.25 + (2.3 * config.
bits.oversamplingTemperature) +
179 (2.3 * config.
bits.oversamplingPressure + 0.575));
202 int32_t adcTemperature = ((uint32_t)buffer[3]) << 12;
203 adcTemperature |= ((uint32_t)buffer[4]) << 4;
204 adcTemperature |= (buffer[5] >> 4) & 0x0F;
206 int32_t adc_P = ((uint32_t)buffer[0]) << 12;
207 adc_P |= ((uint32_t)buffer[1]) << 4;
208 adc_P |= (buffer[2] >> 4) & 0x0F;
211 fineTemperature = computeFineTemperature(adcTemperature);
213 data.
temperature = compensateTemperature(fineTemperature);
218 data.
pressure = compensatePressure(adc_P);
228 transaction.writeRegister(REG_RESET, 0xB6);
231bool BMP280::checkWhoAmI()
233 SPITransaction transaction(spiSlave);
235 uint8_t whoAmIValue = transaction.readRegister(REG_ID);
240void BMP280::setConfiguration() { setConfiguration(config); }
242void BMP280::setConfiguration(BMP280Config config)
244 SPITransaction transaction(spiSlave);
246 transaction.writeRegister(REG_CONFIG, config.bytes.config);
247 transaction.writeRegister(REG_CTRL_MEAS,
248 config.bytes.ctrlPressureAndTemperature);
251BMP280::BMP280Config BMP280::readConfiguration()
254 SPITransaction transaction(spiSlave);
256 transaction.readRegisters(REG_STATUS, (uint8_t*)&tmp, 3);
261void BMP280::loadCompensationParameters()
265 SPITransaction transaction(spiSlave);
267 transaction.readRegisters(REG_CALIB_0, (uint8_t*)&compParams, 25);
271int32_t BMP280::computeFineTemperature(int32_t adcTemperature)
274 var1 = ((((adcTemperature >> 3) - ((int32_t)compParams.
bits.dig_T1 << 1))) *
275 ((int32_t)compParams.
bits.dig_T2)) >>
277 var2 = (((((adcTemperature >> 4) - ((int32_t)compParams.
bits.dig_T1)) *
278 ((adcTemperature >> 4) - ((int32_t)compParams.
bits.dig_T1))) >>
280 ((int32_t)compParams.
bits.dig_T3)) >>
285int32_t BMP280::compensateTemperature(int32_t fineTemperature)
287 return (fineTemperature * 5 + 128) >> 8;
290uint32_t BMP280::compensatePressure(int32_t adc_P)
292 int64_t var1, var2, p;
293 var1 = ((int64_t)fineTemperature) - 128000;
294 var2 = var1 * var1 * (int64_t)compParams.
bits.dig_P6;
295 var2 = var2 + ((var1 * (int64_t)compParams.
bits.dig_P5) << 17);
296 var2 = var2 + (((int64_t)compParams.
bits.dig_P4) << 35);
297 var1 = ((var1 * var1 * (int64_t)compParams.
bits.dig_P3) >> 8) +
298 ((var1 * ((int64_t)compParams.
bits.dig_P2) << 12));
300 ((((int64_t)1) << 47) + var1) * ((int64_t)compParams.
bits.dig_P1) >> 33;
304 p = (((p << 31) - var2) * 3125) / var1;
305 var1 = (((int64_t)compParams.
bits.dig_P9) * (p >> 13) * (p >> 13)) >> 25;
306 var2 = (((int64_t)compParams.
bits.dig_P8) * p) >> 19;
307 p = ((p + var1 + var2) >> 8) + (((int64_t)compParams.
bits.dig_P7) << 4);
#define LOG_ERR(logger,...)
BMP280(SPISlave spiSlave, BMP280Config config=BMP280_CONFIG_ALL_ENABLED)
void setStandbyTime(StandbyTime standbyTime)
Sets the standby time between readings in normal mode.
void setSensorMode(Mode mode)
Sets the sensor mode.
bool init() override
Initialize the device with the specified configuration.
PressureData readPressure()
Reads only the pressure, does not set the configuration.
static const BMP280Config BMP280_CONFIG_ALL_ENABLED
Temperature enabled in forced mode.
BMP280Data sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
TemperatureData readTemperature()
Reads only the temperature, does not set the configuration.
static constexpr uint8_t REG_ID_VAL
Who am I value.
void setTemperatureOversampling(Oversampling oversampling)
Sets the oversampling for temperature readings, use SKIPPED to disable temperature sampling.
static unsigned int calculateMaxMeasurementTime(BMP280Config config)
Maximum measurement time formula from datasheet page 51.
static const BMP280Config BMP280_CONFIG_TEMP_SINGLE
void setFilterCoeff(FilterCoeff filterCoeff)
Sets the coefficient for the IIR filter (applied to temperature and pressure)
unsigned int getMaxMeasurementTime()
void setPressureOversampling(Oversampling oversampling)
Sets the oversampling for pressure readings, use SKIPPED to disable pressure sampling.
bool selfTest() override
Reads the WHO AM I register.
static const BMP280Config BMP280_DEFAULT_CONFIG
Datasheet values for indoor navigation.
Provides high-level access to the SPI Bus for a single transaction.
void readRegisters(uint8_t reg, uint8_t *data, size_t size)
Reads multiple bytes starting from the specified register.
uint64_t getTimestamp()
Returns the current timer value in microseconds.
This file includes all the types the logdecoder script will decode.
uint64_t pressureTimestamp
Contains information about a single SPI slave device.
uint64_t temperatureTimestamp
struct Boardcore::BMP280::BMP280Config::@4 bytes