raspberrypi / pico-examples

BSD 3-Clause "New" or "Revised" License
2.84k stars 820 forks source link

BME 280 SPI example needs temperature and pressure switched? #442

Closed rvt closed 5 months ago

rvt commented 10 months ago

If we look at the code here : https://github.com/raspberrypi/pico-examples/blob/master/spi/bme280_spi/bme280_spi.c#L229

We can see that both compensate_pressure and compensate_temperature is called. However since compensate_temperature set'st_fine and compensate_pressure uses t_fine in it's calculations they call order should be:

        // These are the raw numbers from the chip, so we need to run through the
        // compensations to get human understandable numbers
        temperature = compensate_temp(temperature);
        pressure = compensate_pressure(pressure);

when done in this order, then the first calculation for pressure is correct. In the current situation the first pressure calculation will show an incorrect readout after compensate_pressure