Fixup a coding error in BME280 example (#187)

This commit is contained in:
James Hughes 2021-11-19 16:37:36 +00:00 committed by GitHub
parent 9133a154d8
commit fb96fad5a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -117,7 +117,8 @@ void bmp280_read_raw(int32_t* temp, int32_t* pressure) {
// note: normal mode does not require further ctrl_meas and config register writes // note: normal mode does not require further ctrl_meas and config register writes
uint8_t buf[6]; uint8_t buf[6];
i2c_write_blocking(i2c_default, ADDR, (uint8_t*)REG_PRESSURE_MSB, 1, true); // true to keep master control of bus uint8_t reg = REG_PRESSURE_MSB;
i2c_write_blocking(i2c_default, ADDR, &reg, 1, true); // true to keep master control of bus
i2c_read_blocking(i2c_default, ADDR, buf, 6, false); // false - finished with bus i2c_read_blocking(i2c_default, ADDR, buf, 6, false); // false - finished with bus
// store the 20 bit read in a 32 bit signed integer for conversion // store the 20 bit read in a 32 bit signed integer for conversion
@ -184,7 +185,8 @@ void bmp280_get_calib_params(struct bmp280_calib_param* params) {
// and MSB register, so we read from 24 registers // and MSB register, so we read from 24 registers
uint8_t buf[NUM_CALIB_PARAMS] = { 0 }; uint8_t buf[NUM_CALIB_PARAMS] = { 0 };
i2c_write_blocking(i2c_default, ADDR, (uint8_t*)REG_DIG_T1_LSB, 1, true); // true to keep master control of bus uint8_t reg = REG_DIG_T1_LSB;
i2c_write_blocking(i2c_default, ADDR, &reg, 1, true); // true to keep master control of bus
// read in one go as register addresses auto-increment // read in one go as register addresses auto-increment
i2c_read_blocking(i2c_default, ADDR, buf, NUM_CALIB_PARAMS, false); // false, we're done reading i2c_read_blocking(i2c_default, ADDR, buf, NUM_CALIB_PARAMS, false); // false, we're done reading