Improved BME280 humidity initialisation so that it does not override existing

oversampling rates that have been set up for the ctrl_meas register.

The humidity oversampling rate is set to 1 (as per Section 3.5 of the BME280
data sheet).

Signed-off-by: Graeme Cross <graeme@ceriumdesigns.com>
This commit is contained in:
Graeme Cross 2017-06-05 20:02:18 +10:00 committed by deadprogram
parent 44dec6d800
commit 95b0fe880f
1 changed files with 8 additions and 3 deletions

View File

@ -7,7 +7,6 @@ import (
)
const bme280RegisterControlHumidity = 0xF2
const bme280RegisterControl = 0xf4
const bme280RegisterHumidityMSB = 0xFD
const bme280RegisterCalibDigH1 = 0xa1
const bme280RegisterCalibDigH2LSB = 0xe1
@ -114,9 +113,15 @@ func (d *BME280Driver) initHumidity() (err error) {
d.hc.h5 = 0 + (int16(addrE6) << 4) | (int16(addrE5) >> 4)
d.connection.WriteByteData(bme280RegisterControlHumidity, 0x3F)
d.connection.WriteByteData(bmp280RegisterControl, 0x3F)
return nil
// The 'ctrl_hum' register sets the humidity data acquisition options of
// the device. Changes to this register only become effective after a write
// operation to 'ctrl_meas'. Read the current value in, then write it back
cmr, err := d.connection.ReadByteData(bmp280RegisterControl)
if err != nil {
d.connection.WriteByteData(bmp280RegisterControl, cmr)
}
return err
}
func (d *BME280Driver) rawHumidity() (uint32, error) {