source: ctrl/firmware/Main/SES/Core/Inc/bme280.h

Last change on this file was 88, checked in by Zed, 3 months ago

BME280 data transfer works ok. Device returns its ID 0x60.

File size: 5.8 KB
Line 
1/*
2 * bme280.h
3 *
4 * Created: 05.01.2024 11:06:53
5 *  Author: ecs
6 */
7
8
9#ifndef BME280_H_
10#define BME280_H_
11
12#include <stdint.h>
13
14#define BME280_CHIP_ID                                          0x60
15#define BME680_CHIP_ID                                          0x61
16#define BMP280_CHIP_ID                                          0x58
17
18#define BME280_STATUS_MEAS_MSK                          0x08
19#define BME280_STATUS_MEAS_POS                          3U
20#define BME280_STATUS_IMUPD_MSK                         0x01
21#define BME280_STATUS_IMUPD_POS                         0U
22
23#define BME280_CTRL_HUM_MSK                                     0x07
24#define BME280_CTRL_HUM_POS                                     0U
25#define BME280_CTRL_HUM_OVSMP_OFF                       0U
26#define BME280_CTRL_HUM_OVSMP_X1                        1U
27#define BME280_CTRL_HUM_OVSMP_X2                        2U
28#define BME280_CTRL_HUM_OVSMP_X4                        3U
29#define BME280_CTRL_HUM_OVSMP_X8                        4U
30#define BME280_CTRL_HUM_OVSMP_X16                       5U      // 5,6,7
31
32#define BME280_CTRL_MEAS_OSRS_T_MSK                     0x07
33#define BME280_CTRL_MEAS_OSRS_T_POS                     5U
34#define BME280_CTRL_MEAS_OSRS_T_OVSMP_OFF       0U
35#define BME280_CTRL_MEAS_OSRS_T_OVSMP_X1        1U
36#define BME280_CTRL_MEAS_OSRS_T_OVSMP_X2        2U
37#define BME280_CTRL_MEAS_OSRS_T_OVSMP_X4        3U
38#define BME280_CTRL_MEAS_OSRS_T_OVSMP_X8        4U
39#define BME280_CTRL_MEAS_OSRS_T_OVSMP_X16       5U      // 5,6,7
40
41#define BME280_CTRL_MEAS_OSRS_P_MSK                     0x07
42#define BME280_CTRL_MEAS_OSRS_P_POS                     2U
43#define BME280_CTRL_MEAS_OSRS_P_OVSMP_OFF       0U
44#define BME280_CTRL_MEAS_OSRS_P_OVSMP_X1        1U
45#define BME280_CTRL_MEAS_OSRS_P_OVSMP_X2        2U
46#define BME280_CTRL_MEAS_OSRS_P_OVSMP_X4        3U
47#define BME280_CTRL_MEAS_OSRS_P_OVSMP_X8        4U
48#define BME280_CTRL_MEAS_OSRS_P_OVSMP_X16       5U      // 5,6,7
49
50#define BME280_CTRL_MEAS_MODE_MSK                       0x03
51#define BME280_CTRL_MEAS_MODE_POS                       0U
52#define BME280_CTRL_MEAS_MODE_SLEEP                     0U
53#define BME280_CTRL_MEAS_MODE_FORCED            1U      // or 2
54#define BME280_CTRL_MEAS_MODE_NORMAL            3U
55
56#define BME280_CONFIG_STANDBY_DUR_MSK           0x07
57#define BME280_CONFIG_STANDBY_DUR_POS           5U
58#define BME280_CONFIG_STANDBY_DUR_0_5_MS        0U
59#define BME280_CONFIG_STANDBY_DUR_62_5_MS       1U
60#define BME280_CONFIG_STANDBY_DUR_125_MS        2U
61#define BME280_CONFIG_STANDBY_DUR_250_MS        3U
62#define BME280_CONFIG_STANDBY_DUR_500_MS        4U
63#define BME280_CONFIG_STANDBY_DUR_1000_MS       5U
64#define BME280_CONFIG_STANDBY_DUR_10_MS         6U
65#define BME280_CONFIG_STANDBY_DUR_20_MS         7U
66
67#define BME280_CONFIG_IIR_MSK                           0x07
68#define BME280_CONFIG_IIR_POS                           2U
69#define BME280_CONFIG_IIR_FILTER_OFF            0U
70#define BME280_CONFIG_IIR_FILTER_X2                     1U
71#define BME280_CONFIG_IIR_FILTER_X4                     2U
72#define BME280_CONFIG_IIR_FILTER_X8                     3U
73#define BME280_CONFIG_IIR_FILTER_X16            4U      // or 5,6,7
74
75#define BME280_CONFIG_SPI_3_PIN_MSK                     0x01
76#define BME280_CONFIG_SPI_3_PIN_POS                     0U
77#define BME280_CONFIG_SPI_3_PIN_ENABLE          1U
78#define BME280_CONFIG_SPI_3_PIN_DISABLE         0U
79
80typedef int32_t BME280_S32_t;
81typedef uint32_t BME280_U32_t;
82typedef int64_t BME280_S64_t;
83typedef uint16_t BME280_U16_t;
84
85typedef enum BME280_REG_enum
86{
87        BME280_REG_calib00              = 0x88,
88        BME280_REG_calib01              = 0x89,
89        BME280_REG_calib02              = 0x8A,
90        BME280_REG_calib03              = 0x8B,
91        BME280_REG_calib04              = 0x8C,
92        BME280_REG_calib05              = 0x8D,
93        BME280_REG_calib06              = 0x8E,
94        BME280_REG_calib07              = 0x8F,
95        BME280_REG_calib08              = 0x90,
96        BME280_REG_calib09              = 0x91,
97        BME280_REG_calib10              = 0x92,
98        BME280_REG_calib11              = 0x93,
99        BME280_REG_calib12              = 0x94,
100        BME280_REG_calib13              = 0x95,
101        BME280_REG_calib14              = 0x96,
102        BME280_REG_calib15              = 0x97,
103        BME280_REG_calib16              = 0x98,
104        BME280_REG_calib17              = 0x99,
105        BME280_REG_calib18              = 0x9A,
106        BME280_REG_calib19              = 0x9B,
107        BME280_REG_calib20              = 0x9C,
108        BME280_REG_calib21              = 0x9D,
109        BME280_REG_calib22              = 0x9E,
110        BME280_REG_calib23              = 0x9F,
111        BME280_REG_calib24              = 0xA0,
112        BME280_REG_calib25              = 0xA1,
113
114        BME280_REG_id                   = 0xD0,
115
116        BME280_REG_reset                = 0xE0,
117
118        BME280_REG_calib26              = 0xE1,
119        BME280_REG_calib27              = 0xE2,
120        BME280_REG_calib28              = 0xE3,
121        BME280_REG_calib29              = 0xE4,
122        BME280_REG_calib30              = 0xE5,
123        BME280_REG_calib31              = 0xE6,
124        BME280_REG_calib32              = 0xE7,
125        BME280_REG_calib33              = 0xE8,
126        BME280_REG_calib34              = 0xE9,
127        BME280_REG_calib35              = 0xEA,
128        BME280_REG_calib36              = 0xEB,
129        BME280_REG_calib37              = 0xEC,
130        BME280_REG_calib38              = 0xED,
131        BME280_REG_calib39              = 0xEE,
132        BME280_REG_calib40              = 0xEF,
133        BME280_REG_calib41              = 0xF0,
134
135        BME280_REG_ctrl_hum             = 0xF2,
136        BME280_REG_status               = 0xF3,
137        BME280_REG_ctrl_meas    = 0xF4,
138        BME280_REG_config               = 0xF5,
139        BME280_REG_press_msb    = 0xF7,
140        BME280_REG_press_lsb    = 0xF8,
141        BME280_REG_press_xlsb   = 0xF9,
142        BME280_REG_temp_msb             = 0xFA,
143        BME280_REG_temp_lsb             = 0xFB,
144        BME280_REG_temp_xlsb    = 0xFC,
145        BME280_REG_hum_msb              = 0xFD,
146        BME280_REG_hume_lsb             = 0xFE,
147
148} BME280_REG_t;
149
150typedef struct BME280_Calib_0
151{
152        uint16_t        dig_T1;                 // 0x88,0x89
153        int16_t         dig_T2;                 // 0x8A,0x8B
154        int16_t         dig_T3;                 // 0x8C,0x8D
155        uint16_t        dig_P1;                 // 0x8E,0x8F
156        int16_t         dig_P2;                 // 0x90,0x91
157        int16_t         dig_P3;                 // 0x92,0x93
158        int16_t         dig_P4;                 // 0x94,0x95
159        int16_t         dig_P5;                 // 0x96,0x97
160        int16_t         dig_P6;                 // 0x98,0x99
161        int16_t         dig_P7;                 // 0x9A,0x9B
162        int16_t         dig_P8;                 // 0x9C,0x9D
163        int16_t         dig_P9;                 // 0x9E,0x9F
164        uint8_t         reserved_0;             // 0xA0
165        uint8_t         dig_H1;                 // 0xA1
166}
167BME280_Calib_0_t;
168
169typedef struct BME280_Calib_1
170{
171        int16_t dig_H2;
172        uint8_t dig_H3;
173        int16_t dig_H4;
174        int8_t  dig_H5;
175        int8_t  dig_H6;
176}
177BME280_Calib_1_t;
178
179/*uint8_t                       BME280_ReadDeviceID(TWI_Master_t* twi);
180uint8_t                 BME280_ReadDeviceStatus(TWI_Master_t* twi);
181uint32_t                BME280_ReadPress(TWI_Master_t* twi);
182uint32_t                BME280_ReadTemp(TWI_Master_t* twi);
183uint16_t                BME280_ReadHum(TWI_Master_t* twi);
184int                             BME280_Calib00_25(TWI_Master_t* twi, BME280_Calib_0_t* digs);
185int                             BME280_Calib26_32(TWI_Master_t* twi, BME280_Calib_1_t* digs);
186BME280_S32_t    BME280_compensate_T(BME280_S32_t adc_T, BME280_Calib_0_t* digs);
187void                    BME280_compensate_P_step1(BME280_Calib_0_t* digs);
188BME280_U32_t    BME280_compensate_P_step2(BME280_S32_t adc_P, BME280_Calib_0_t* digs);
189BME280_U32_t    BME280_compensate_H(BME280_S32_t adc_H, BME280_Calib_0_t* dig0s, BME280_Calib_1_t* dig1s);*/
190
191#endif /* BME280_H_ */
Note: See TracBrowser for help on using the repository browser.