-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmp280_i2c.h
92 lines (78 loc) · 2.32 KB
/
bmp280_i2c.h
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// Created by XINJIAWEI on 24-7-30.
//
#include <cstdint>
#ifndef PICO_EXAMPLES_BMP280_I2C_H
#define PICO_EXAMPLES_BMP280_I2C_H
#endif //PICO_EXAMPLES_BMP280_I2C_H
#define BMP280_I2C i2c1
#define BMP280_I2C_SDA_PIN 10
#define BMP280_I2C_SCL_PIN 11
// device has default bus address of 0x76
#define ADDR _u(0x76)
// hardware registers
#define REG_CONFIG _u(0xF5)
#define REG_CTRL_MEAS _u(0xF4)
#define REG_RESET _u(0xE0)
#define REG_TEMP_XLSB _u(0xFC)
#define REG_TEMP_LSB _u(0xFB)
#define REG_TEMP_MSB _u(0xFA)
#define REG_PRESSURE_XLSB _u(0xF9)
#define REG_PRESSURE_LSB _u(0xF8)
#define REG_PRESSURE_MSB _u(0xF7)
// calibration registers
#define REG_DIG_T1_LSB _u(0x88)
#define REG_DIG_T1_MSB _u(0x89)
#define REG_DIG_T2_LSB _u(0x8A)
#define REG_DIG_T2_MSB _u(0x8B)
#define REG_DIG_T3_LSB _u(0x8C)
#define REG_DIG_T3_MSB _u(0x8D)
#define REG_DIG_P1_LSB _u(0x8E)
#define REG_DIG_P1_MSB _u(0x8F)
#define REG_DIG_P2_LSB _u(0x90)
#define REG_DIG_P2_MSB _u(0x91)
#define REG_DIG_P3_LSB _u(0x92)
#define REG_DIG_P3_MSB _u(0x93)
#define REG_DIG_P4_LSB _u(0x94)
#define REG_DIG_P4_MSB _u(0x95)
#define REG_DIG_P5_LSB _u(0x96)
#define REG_DIG_P5_MSB _u(0x97)
#define REG_DIG_P6_LSB _u(0x98)
#define REG_DIG_P6_MSB _u(0x99)
#define REG_DIG_P7_LSB _u(0x9A)
#define REG_DIG_P7_MSB _u(0x9B)
#define REG_DIG_P8_LSB _u(0x9C)
#define REG_DIG_P8_MSB _u(0x9D)
#define REG_DIG_P9_LSB _u(0x9E)
#define REG_DIG_P9_MSB _u(0x9F)
// number of calibration registers to be read
#define NUM_CALIB_PARAMS 24
struct bmp280CalibParam {
// temperature params
uint16_t dig_t1;
int16_t dig_t2;
int16_t dig_t3;
// pressure params
uint16_t dig_p1;
int16_t dig_p2;
int16_t dig_p3;
int16_t dig_p4;
int16_t dig_p5;
int16_t dig_p6;
int16_t dig_p7;
int16_t dig_p8;
int16_t dig_p9;
};
struct bmp280Reading{
float pressure_kpa;//湿度
float temp_c;//温度-摄氏度的
};
void bmp280_init();
void bmp280_read_raw(int32_t* temp, int32_t* pressure);
void bmp280_reset();
int32_t bmp280_convert(int32_t temp, struct bmp280CalibParam * params);
int32_t bmp280_convert_temp(int32_t temp, struct bmp280CalibParam * params);
int32_t bmp280_convert_pressure(int32_t pressure, int32_t temp, struct bmp280CalibParam * params);
void bmp280_get_calib_params(struct bmp280CalibParam * params);
bool init_pressureS();
bmp280Reading get_pressureS();