34 0, 0, SLEEP_MODE, SKIPPED, SKIPPED, 0, FILTER_OFF, STB_TIME_0_5};
47 0, 0, FORCED_MODE, SKIPPED, OVERSAMPLING_1, 0, FILTER_OFF, STB_TIME_0_5};
57 LOG_ERR(logger,
"Invalid WHO AM I");
65 miosix::Thread::sleep(3);
67 loadCompensationParameters();
71 miosix::Thread::sleep(
81 if (config.
bytes.ctrlPressureAndTemperature !=
82 readBackConfig.bytes.ctrlPressureAndTemperature ||
83 config.
bytes.config != readBackConfig.bytes.config)
85 LOG_ERR(logger,
"Device configuration incorrect, setup failed");
96 config.
bits.mode = mode;
103 config.
bits.oversamplingPressure = oversampling;
110 config.
bits.oversamplingTemperature = oversampling;
117 config.
bits.filter = filterCoeff;
124 config.
bits.standbyTime = standbyTime;
134 int32_t adc_P = ((uint32_t)buffer[0]) << 12;
135 adc_P |= ((uint32_t)buffer[1]) << 4;
136 adc_P |= (buffer[2] >> 4) & 0x0F;
140 data.
pressure = compensatePressure(adc_P);
157 int32_t adcTemperature = ((uint32_t)buffer[0]) << 12;
158 adcTemperature |= ((uint32_t)buffer[1]) << 4;
159 adcTemperature |= (buffer[2] >> 4) & 0x0F;
161 fineTemperature = computeFineTemperature(adcTemperature);
165 data.
temperature = compensateTemperature(fineTemperature);
181 return ceil(1.25 + (2.3 * config.
bits.oversamplingTemperature) +
182 (2.3 * config.
bits.oversamplingPressure + 0.575));
201 int32_t adcTemperature = ((uint32_t)buffer[3]) << 12;
202 adcTemperature |= ((uint32_t)buffer[4]) << 4;
203 adcTemperature |= (buffer[5] >> 4) & 0x0F;
205 int32_t adc_P = ((uint32_t)buffer[0]) << 12;
206 adc_P |= ((uint32_t)buffer[1]) << 4;
207 adc_P |= (buffer[2] >> 4) & 0x0F;
210 fineTemperature = computeFineTemperature(adcTemperature);
212 data.
temperature = compensateTemperature(fineTemperature);
217 data.
pressure = compensatePressure(adc_P);
229bool BMP280I2C::reset()
240bool BMP280I2C::checkWhoAmI()
255void BMP280I2C::setConfiguration() { setConfiguration(config); }
257void BMP280I2C::setConfiguration(BMP280Config config)
259 if (!bus.
writeRegister(slaveConfig, REG_CONFIG, config.bytes.config))
261 LOG_ERR(logger,
"Error while writing to register REG_CONFIG");
266 config.bytes.ctrlPressureAndTemperature))
268 LOG_ERR(logger,
"Error while writing to register REG_CTRL_MEAS");
273BMP280I2C::BMP280Config BMP280I2C::readConfiguration()
288void BMP280I2C::loadCompensationParameters()
299int32_t BMP280I2C::computeFineTemperature(int32_t adcTemperature)
302 var1 = ((((adcTemperature >> 3) - ((int32_t)compParams.
bits.dig_T1 << 1))) *
303 ((int32_t)compParams.
bits.dig_T2)) >>
305 var2 = (((((adcTemperature >> 4) - ((int32_t)compParams.
bits.dig_T1)) *
306 ((adcTemperature >> 4) - ((int32_t)compParams.
bits.dig_T1))) >>
308 ((int32_t)compParams.
bits.dig_T3)) >>
313int32_t BMP280I2C::compensateTemperature(int32_t fineTemperature)
315 return (fineTemperature * 5 + 128) >> 8;
318uint32_t BMP280I2C::compensatePressure(int32_t adc_P)
320 int64_t var1, var2, p;
321 var1 = ((int64_t)fineTemperature) - 128000;
322 var2 = var1 * var1 * (int64_t)compParams.
bits.dig_P6;
323 var2 = var2 + ((var1 * (int64_t)compParams.
bits.dig_P5) << 17);
324 var2 = var2 + (((int64_t)compParams.
bits.dig_P4) << 35);
325 var1 = ((var1 * var1 * (int64_t)compParams.
bits.dig_P3) >> 8) +
326 ((var1 * ((int64_t)compParams.
bits.dig_P2) << 12));
328 ((((int64_t)1) << 47) + var1) * ((int64_t)compParams.
bits.dig_P1) >> 33;
332 p = (((p << 31) - var2) * 3125) / var1;
333 var1 = (((int64_t)compParams.
bits.dig_P9) * (p >> 13) * (p >> 13)) >> 25;
334 var2 = (((int64_t)compParams.
bits.dig_P8) * p) >> 19;
335 p = ((p + var1 + var2) >> 8) + (((int64_t)compParams.
bits.dig_P7) << 4);
#define LOG_ERR(logger,...)
void setSensorMode(Mode mode)
Sets the sensor mode.
bool init() override
Initialize the device with the specified configuration.
BMP280I2C(I2C &bus, BMP280Config config=BMP280_CONFIG_ALL_ENABLED)
void setTemperatureOversampling(Oversampling oversampling)
Sets the oversampling for temperature readings, use SKIPPED to disable temperature sampling.
void setPressureOversampling(Oversampling oversampling)
Sets the oversampling for pressure readings, use SKIPPED to disable pressure sampling.
PressureData readPressure()
Reads only the pressure, does not set the configuration.
BMP280Data sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
static const BMP280Config BMP280_CONFIG_TEMP_SINGLE
void setStandbyTime(StandbyTime standbyTime)
Sets the standby time between readings in normal mode.
bool selfTest() override
Reads the WHO AM I register.
TemperatureData readTemperature()
Reads only the temperature, does not set the configuration.
static constexpr uint8_t REG_ID_VAL
Who am I value.
static const BMP280Config BMP280_DEFAULT_CONFIG
Datasheet values for indoor navigation.
unsigned int getMaxMeasurementTime()
static unsigned int calculateMaxMeasurementTime(BMP280Config config)
Maximum measurement time formula from datasheet page 51.
static const BMP280Config BMP280_CONFIG_ALL_ENABLED
Temperature enabled in forced mode.
void setFilterCoeff(FilterCoeff filterCoeff)
Sets the coefficient for the IIR filter (applied to temperature and pressure)
High level driver for the I2C peripherals.
bool readFromRegister(const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, void *buffer, const size_t nBytes)
Non blocking operation to read n-bytes from register from a slave.
bool writeRegister(const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, const uint8_t registerContent)
Non blocking operation to write an 8-bit register from a slave.
bool readRegister(const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint8_t ®isterContent)
Non blocking operation to read an 8-bit register from a slave.
uint64_t getTimestamp()
Returns the current timer value in microseconds.
This file includes all the types the logdecoder script will decode.
uint64_t pressureTimestamp
uint64_t temperatureTimestamp
struct Boardcore::BMP280I2C::BMP280Config::@5 bytes