RocketLogger  1.1.5
bme280.h
Go to the documentation of this file.
1 
32 #ifndef SENSOR_BME280_H_
33 #define SENSOR_BME280_H_
34 
35 #include <errno.h>
36 #include <math.h>
37 #include <stdint.h>
38 #include <stdio.h>
39 #include <unistd.h>
40 
41 #include <fcntl.h>
42 #include <linux/i2c-dev.h>
43 #include <sys/ioctl.h>
44 #include <sys/stat.h>
45 #include <sys/types.h>
46 
47 #include "../log.h"
48 #include "../types.h"
49 
50 #define BME280_I2C_ADDRESS_LEFT 0x76
51 
52 #define BME280_I2C_ADDRESSES \
53  { (BME280_I2C_ADDRESS_LEFT) }
54 
55 #define BME280_CHANNEL_TEMPERATURE 0
56 #define BME280_CHANNEL_HUMIDITY 1
57 #define BME280_CHANNEL_PREASURE 2
58 
59 // register definitions
60 #define BME280_ID 0x60
61 
62 #define BME280_REG_CALIBRATION_BLOCK1 0x88
63 #define BME280_REG_ID 0xD0
64 #define BME280_REG_RESET 0xE0
65 #define BME280_REG_CALIBRATION_BLOCK2 0xE1
66 #define BME280_REG_CONTROL_HUMIDITY 0xF2
67 #define BME280_REG_STATUS 0xF3
68 #define BME280_REG_CONTROL_MEASURE 0xF4
69 #define BME280_REG_CONFIG 0xF5
70 #define BME280_REG_PREASURE_MSB 0xF7
71 #define BME280_REG_PREASURE_LSB 0xF8
72 #define BME280_REG_PREASURE_XLSB 0xF9
73 #define BME280_REG_TEMPERATURE_MSB 0xFA
74 #define BME280_REG_TEMPERATURE_LSB 0xFB
75 #define BME280_REG_TEMPERATURE_XLSB 0xFC
76 #define BME280_REG_HUMIDITY_MSB 0xFD
77 #define BME280_REG_HUMIDITY_LSB 0xFE
78 
79 #define BME280_CALIBRATION_BLOCK1_SIZE 26
80 #define BME280_CALIBRATION_BLOCK2_SIZE 7
81 
82 #define BME280_DATA_BLOCK_SIZE 8
83 
84 #define BME280_RESET_VALUE 0xB6
85 
86 #define BME280_OVERSAMPLE_HUMIDITY_OFF 0x00
87 #define BME280_OVERSAMPLE_HUMIDITY_1 0x01
88 #define BME280_OVERSAMPLE_HUMIDITY_2 0x02
89 #define BME280_OVERSAMPLE_HUMIDITY_4 0x03
90 #define BME280_OVERSAMPLE_HUMIDITY_8 0x04
91 #define BME280_OVERSAMPLE_HUMIDITY_16 0x0f
92 
93 #define BME280_MEASURING 0x03
94 #define BME280_UPDATE 0x1
95 
96 #define BME280_OVERSAMPLE_TEMPERATURE_OFF 0x00
97 #define BME280_OVERSAMPLE_TEMPERATURE_1 0x20
98 #define BME280_OVERSAMPLE_TEMPERATURE_2 0x40
99 #define BME280_OVERSAMPLE_TEMPERATURE_4 0x60
100 #define BME280_OVERSAMPLE_TEMPERATURE_8 0x80
101 #define BME280_OVERSAMPLE_TEMPERATURE_16 0xA0
102 #define BME280_OVERSAMPLE_PREASURE_OFF 0x00
103 #define BME280_OVERSAMPLE_PREASURE_1 0x04
104 #define BME280_OVERSAMPLE_PREASURE_2 0x08
105 #define BME280_OVERSAMPLE_PREASURE_4 0x0C
106 #define BME280_OVERSAMPLE_PREASURE_8 0x10
107 #define BME280_OVERSAMPLE_PREASURE_16 0x14
108 #define BME280_MODE_SLEEP 0x00
109 #define BME280_MODE_FORCE 0x01
110 #define BME280_MODE_NORMAL 0x03
111 
112 #define BME280_STANDBY_DURATION_0_5 0x00
113 #define BME280_STANDBY_DURATION_62 0x20
114 #define BME280_STANDBY_DURATION_125 0x40
115 #define BME280_STANDBY_DURATION_250 0x60
116 #define BME280_STANDBY_DURATION_500 0x80
117 #define BME280_STANDBY_DURATION_1000 0xA0
118 #define BME280_STANDBY_DURATION_10 0xC0
119 #define BME280_STANDBY_DURATION_20 0xE0
120 #define BME280_FILTER_OFF 0x00
121 #define BME280_FILTER_2 0x04
122 #define BME280_FILTER_4 0x08
123 #define BME280_FILTER_8 0x0C
124 #define BME280_FILTER_16 0x10
125 #define BME280_SPI_EN 0x01
126 
127 /*
128  * Data Structures
129  */
131  // temperature
132  uint16_t T1;
133  int16_t T2;
134  int16_t T3;
135 
136  // preasure
137  uint16_t P1;
138  int16_t P2;
139  int16_t P3;
140  int16_t P4;
141  int16_t P5;
142  int16_t P6;
143  int16_t P7;
144  int16_t P8;
145  int16_t P9;
146 
147  // humidity
148  uint8_t H1;
149  int16_t H2;
150  uint8_t H3;
151  int16_t H4;
152  int16_t H5;
153  int8_t H6;
154 };
155 
156 /*
157  * API FUNCTIONS
158  */
159 int BME280_init(int);
160 void BME280_close(int);
161 int BME280_read(int);
162 int32_t BME280_getValue(int, int);
163 
164 /*
165  * Helper FUNCTIONS
166  */
167 int BME280_getID(void);
168 int BME280_readCalibration(int);
169 int BME280_setParameters(int);
170 int BME280_getIndex(int);
171 
172 int32_t BME280_compensate_temperature_fine(int, int32_t);
173 int32_t BME280_compensate_temperature(int, int32_t);
174 uint32_t BME280_compensate_preasure(int, int32_t, int32_t);
175 uint32_t BME280_compensate_humidity(int, int32_t, int32_t);
176 
177 #endif /* SENSOR_BME280_H_ */
int BME280_setParameters(int)
Definition: bme280.c:253
int BME280_getID(void)
Definition: bme280.c:170
void BME280_close(int)
Definition: bme280.c:90
int BME280_read(int)
Definition: bme280.c:99
uint32_t BME280_compensate_preasure(int, int32_t, int32_t)
Definition: bme280.c:353
int BME280_getIndex(int)
Definition: bme280.c:294
int BME280_readCalibration(int)
Definition: bme280.c:186
int BME280_init(int)
Definition: bme280.c:49
int32_t BME280_compensate_temperature(int, int32_t)
Definition: bme280.c:338
int32_t BME280_compensate_temperature_fine(int, int32_t)
Definition: bme280.c:311
uint32_t BME280_compensate_humidity(int, int32_t, int32_t)
Definition: bme280.c:398
int32_t BME280_getValue(int, int)
Definition: bme280.c:147