BMP280 driver: Forced mode. Soft reset.
This commit is contained in:
parent
4a2679271e
commit
440ad67834
3 changed files with 93 additions and 5 deletions
|
|
@ -163,6 +163,10 @@ bool bmp280_init(bmp280_params_t *params, uint8_t scl_pin, uint8_t sda_pin)
|
|||
uint8_t oversampling_temp =
|
||||
(params->oversampling == BMP280_ULTRA_HIGH_RES) ? 2 : 1;
|
||||
|
||||
if (params->mode == BMP280_MODE_FORCED) {
|
||||
params->mode = BMP280_MODE_SLEEP; // initial mode for forced is sleep
|
||||
}
|
||||
|
||||
uint8_t ctrl = (oversampling_temp << 5) | (params->oversampling << 2)
|
||||
| (params->mode);
|
||||
|
||||
|
|
@ -176,7 +180,25 @@ bool bmp280_init(bmp280_params_t *params, uint8_t scl_pin, uint8_t sda_pin)
|
|||
|
||||
bool bmp280_force_measurement()
|
||||
{
|
||||
// TODO: implement
|
||||
uint8_t ctrl = read_register8(BMP280_REG_CTRL);
|
||||
ctrl &= ~0b11; // clear two lower bits
|
||||
ctrl |= BMP280_MODE_FORCED;
|
||||
debug("Writing ctrl reg=%x", ctrl);
|
||||
if (!write_register8(BMP280_REG_CTRL, ctrl)) {
|
||||
debug("Failed starting forced mode");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bmp280_is_measuring()
|
||||
{
|
||||
uint8_t status = read_register8(BMP280_REG_STATUS);
|
||||
if (status & (1<<3)) {
|
||||
debug("Status: measuring");
|
||||
return true;
|
||||
}
|
||||
debug("Status: idle");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -255,3 +277,12 @@ bool bmp280_read(float *temperature, float *pressure)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bmp280_soft_reset()
|
||||
{
|
||||
if (!write_register8(BMP280_REG_RESET, BMP280_RESET_VALUE)) {
|
||||
debug("Failed resetting sensor");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
/**
|
||||
* Uncomment to enable debug output.
|
||||
*/
|
||||
#define BMP280_DEBUG
|
||||
// #define BMP280_DEBUG
|
||||
|
||||
/**
|
||||
* BMP280 address is 0x77 if SDO pin is high,
|
||||
|
|
@ -44,6 +44,7 @@
|
|||
* Normal - Continues measurement.
|
||||
*/
|
||||
typedef enum {
|
||||
BMP280_MODE_SLEEP = 0,
|
||||
BMP280_MODE_FORCED = 1,
|
||||
BMP280_MODE_NORMAL = 3
|
||||
} BMP280_Mode;
|
||||
|
|
@ -95,7 +96,11 @@ typedef struct {
|
|||
|
||||
/**
|
||||
* Initialize default parameters.
|
||||
* Default configuration is NORMAL mode.
|
||||
* Default configuration:
|
||||
* mode: NORAML
|
||||
* filter: OFF
|
||||
* oversampling: x4
|
||||
* standby time: 250ms
|
||||
*/
|
||||
void bmp280_init_default_params(bmp280_params_t *params);
|
||||
|
||||
|
|
@ -111,9 +116,22 @@ bool bmp280_init(bmp280_params_t *params, uint8_t scl_pin, uint8_t sda_pin);
|
|||
*/
|
||||
bool bmp280_force_measurement();
|
||||
|
||||
/**
|
||||
* Check if BMP280 is busy with measuring temperature/pressure.
|
||||
* Return true if BMP280 is busy.
|
||||
*/
|
||||
bool bmp280_is_measuring();
|
||||
|
||||
/**
|
||||
* Read compensated temperature and pressure data.
|
||||
* Temperature in degrees Celsius.
|
||||
* Pressure in Pascals.
|
||||
*/
|
||||
bool bmp280_read(float *temperature, float *pressure);
|
||||
|
||||
/**
|
||||
* Restart BMP280 module.
|
||||
*/
|
||||
bool bmp280_soft_reset();
|
||||
|
||||
#endif // __BMP280_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue