read raw bme280 values
This commit is contained in:
parent
f7da5a3712
commit
6f8d2b8814
3 changed files with 43 additions and 3 deletions
29
bme280.c
29
bme280.c
|
|
@ -41,7 +41,7 @@
|
|||
|
||||
// #define REG_PRESSURE_XLSB _u(0xF9)
|
||||
// #define REG_PRESSURE_LSB _u(0xF8)
|
||||
// #define REG_PRESSURE_MSB _u(0xF7)
|
||||
#define REG_PRESSURE_MSB _u(0xF7)
|
||||
|
||||
// calibration registers
|
||||
#define REG_DIG_T1_LSB _u(0x88)
|
||||
|
|
@ -143,3 +143,30 @@ void bme280_init(bme280_config *config, i2c_inst_t *i2c, uint8_t sda_pin,
|
|||
config->i2c = i2c;
|
||||
return;
|
||||
}
|
||||
|
||||
static void bmp280_read_raw(bme280_config *config, int32_t* temp, int32_t* pressure, int32_t* humidity) {
|
||||
// BMP280 data registers are auto-incrementing and we have 3 temperature and
|
||||
// pressure registers each, so we start at 0xF7 and read 6 bytes to 0xFC
|
||||
// note: normal mode does not require further ctrl_meas and config register writes
|
||||
|
||||
uint8_t buf[6];
|
||||
uint8_t reg = REG_PRESSURE_MSB;
|
||||
i2c_write_blocking(config->i2c, ADDR, ®, 1, true); // true to keep master control of bus
|
||||
i2c_read_blocking(config->i2c, ADDR, buf, 6, false); // false - finished with bus
|
||||
|
||||
// store the 20 bit read in a 32 bit signed integer for conversion
|
||||
*pressure = (buf[0] << 12) | (buf[1] << 4) | (buf[2] >> 4);
|
||||
*temp = (buf[3] << 12) | (buf[4] << 4) | (buf[5] >> 4);
|
||||
}
|
||||
|
||||
bme280_reading bme280_read(bme280_config *config) {
|
||||
int32_t raw_temperature = 0;
|
||||
int32_t raw_pressure = 0;
|
||||
int32_t raw_humidity = 0;
|
||||
bmp280_read_raw(config, &raw_temperature, &raw_pressure, &raw_humidity);
|
||||
bme280_reading reading;
|
||||
reading.temperature = raw_temperature;
|
||||
reading.pressure = raw_pressure;
|
||||
reading.humidity = raw_humidity;
|
||||
return reading;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue