-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmp.c
45 lines (34 loc) · 964 Bytes
/
bmp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "i2c/i2c.h"
#include "bmp280/bmp280.h"
#define SCL 14
#define SDA 12
#define BUS_I2C 0
bmp280_t bmp280_dev;
float temperature = 0;
float pressure = 0;
void bmp_init() {
i2c_init(BUS_I2C, SCL, SDA, I2C_FREQ_100K);
gpio_enable(SCL, GPIO_OUTPUT);
// BMP280 configuration
bmp280_params_t params;
bmp280_init_default_params(¶ms);
params.mode = BMP280_MODE_FORCED;
bmp280_dev.i2c_dev.bus = BUS_I2C;
bmp280_dev.i2c_dev.addr = BMP280_I2C_ADDRESS_0;
bmp280_init(&bmp280_dev, ¶ms);
}
void bmp_task(void *pvParameters) {
while (1) {
bmp280_force_measurement(&bmp280_dev);
// wait for measurement to complete
while (bmp280_is_measuring(&bmp280_dev)) {
};
bmp280_read_float(&bmp280_dev, &temperature, &pressure, NULL);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}