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