Here is my best guess at how to implement high res sampling.
This is my first attempt at adjusting sensor register values so it might be wrong.
Use at own risk.
The serial print won't work for some reason in .ccp so I don't quite know how to confirm it is in the correct mode.
If someone could tell me why serial print statements don't work in this library even though wire.h is included I would be grateful.
Anyway.
This is to set into high res mode for indoor navigation use as per the data sheet.
2x temperature oversampling. (data sheet makes a note that this is the preferred option with 16x oversampling on the pressure)
16x Pressure oversampling.
From the datasheet.
Config Register 0xF5
Bit's 7,6,5 set to 0 0 0 Controls inactive duration tstandby in normal mode, set to 0.5ms
Bit's 4.3.2 set to 1 1 1 Controls the time constant of the IIR filter, set to x16 oversampling.
Bit 1 left alone as it is a reserved bit.
Bit 0 set to 0 (4 wire SPI.. not 3)
So the config register 0xF5 needs to be set to 0001 11X0 (X = reserved bit). = 1C. the bitmask will leave X as it is.
Control register 0xF4
Bit's 7,6,5 set to 0 1 0 Controls oversampling of temperature data, set to times 2 in this case
Bit's 4.3.2 set to 1 1 1 Controls oversampling of pressure data, set to times 16 in this case
Bit 1, 0 set to 1 1 Controls the power mode of the device, set to Normal mode.
So 0101 1111 for x2 temp oversample and x16 pressure oversample = 5F
because we can't touch bit 1 (X) in the 0xF5 register we need a mask.
The mask is a value with all bits to be changed (and only them) set to 1
newvalue is a value that contains the new state of those bits - all other bits are essentially ignored.
Adafruit_BMP280.cpp
Code: Select all
readCoefficients();
//write8(BMP280_REGISTER_CONTROL, 0x3F);
_mask = 0xFD; //FD = 1111 1101
_newvalue = 0x1C; //1C = 0001 1100
_SetRegister = (read8(BMP280_REGISTER_CONFIG) & ~_mask) | (_newvalue & _mask);
write8(BMP280_REGISTER_CONFIG, _SetRegister);
write8(BMP280_REGISTER_CONTROL, 0x5F);
Serial.println(F(_SetRegister));
Serial.println(F("SetRegister"));
Added 3 lines to Adafruit_BMP280.h
Code: Select all
class Adafruit_BMP280
{
public:
Adafruit_BMP280(void);
Adafruit_BMP280(int8_t cspin);
Adafruit_BMP280(int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin);
bool begin(uint8_t addr = BMP280_ADDRESS);
float readTemperature(void);
float readPressure(void);
float readAltitude(float seaLevelhPa = 1013.25);
private:
void readCoefficients(void);
uint8_t spixfer(uint8_t x);
void write8(byte reg, byte value);
uint8_t read8(byte reg);
uint16_t read16(byte reg);
uint32_t read24(byte reg);
int16_t readS16(byte reg);
uint16_t read16_LE(byte reg); // little endian
int16_t readS16_LE(byte reg); // little endian
uint8_t _i2caddr;
int32_t _sensorID;
int32_t t_fine;
int8_t _cs, _mosi, _miso, _sck;
bmp280_calib_data _bmp280_calib;
byte _mask;
byte _newvalue;
byte _SetRegister;
};
I have not done much testing yet. So please be careful about my coding !