Skip to content

Commit

Permalink
update bmp280
Browse files Browse the repository at this point in the history
  • Loading branch information
PonomarevDA committed Dec 17, 2023
1 parent c9f5d6b commit 5b50ed9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 11 additions & 4 deletions sensors/barometer/bmp280.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,21 @@ void bmp280Calibrate() {

int8_t bmp280CollectData() {
uint8_t tx[1] = {PRESS_REG};
BMP280_measurement_registers_t data;
i2cTransmit(I2C_ID, tx, 1);
i2cReceive(I2C_ID + 1, (uint8_t*)&data, 6);
BMP280_measurement_registers_t data = {};

int8_t res = LIBPERIPH_BPM280_OK;
if (i2cTransmit(I2C_ID, tx, 1) < 0) {
res = LIBPERIPH_BPM280_NO_RESPONSE;
}

if (i2cReceive(I2C_ID + 1, (uint8_t*)&data, 6) < 0) {
res = LIBPERIPH_BPM280_NO_RESPONSE;
}

bmp280.static_pressure = (float)(data.p_msb << 12 | data.p_lsb << 4 | data.p_xlsb >> 4);
bmp280.static_temperature = (float)(data.t_msb << 12 | data.t_lsb << 4 | data.t_xlsb >> 4);

return LIBPERIPH_OK;
return res;
}


Expand Down
9 changes: 9 additions & 0 deletions sensors/barometer/bmp280.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@ extern "C" {

#define BMP280_MAX_MEASUREMENT_FREQUENCY 50

#define LIBPERIPH_BPM280_OK 0
#define LIBPERIPH_BPM280_NO_RESPONSE -1
#define LIBPERIPH_BPM280_BAD_RESPONSE -2

int8_t bmp280Init();
bool bmp280IsInitialized();
void bmp280Calibrate();

/**
* @return LIBPERIPH_BPM280_OK is ok, otherwise error code < 0
*/
int8_t bmp280CollectData();

void bmp280ParseData();

float bmp280GetStaticPressure();
Expand Down

0 comments on commit 5b50ed9

Please sign in to comment.