-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSparkFunBME280.h
181 lines (152 loc) · 5.26 KB
/
SparkFunBME280.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/******************************************************************************
SparkFunBME280.h
BME280 Particle Photon and Core Driver
Orginal by: Marshall Taylor @ SparkFun Electronics
Particle adaption by: Markus Haack (https://github.com/mhaack)
https://github.com/mhaack/SparkFun_BME280
Development environment specifics:
Particle IDE or Web IDE
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
Please review the LICENSE.md file included with this example. If you have any questions
or concerns with licensing, please contact [email protected].
Distributed as-is; no warranty is given.
******************************************************************************/
// Test derived class for base class SparkFunIMU
#ifndef __BME280_H__
#define __BME280_H__
#include "application.h"
#define I2C_MODE 0
#define SPI_MODE 1
//Register names:
#define BME280_DIG_T1_LSB_REG 0x88
#define BME280_DIG_T1_MSB_REG 0x89
#define BME280_DIG_T2_LSB_REG 0x8A
#define BME280_DIG_T2_MSB_REG 0x8B
#define BME280_DIG_T3_LSB_REG 0x8C
#define BME280_DIG_T3_MSB_REG 0x8D
#define BME280_DIG_P1_LSB_REG 0x8E
#define BME280_DIG_P1_MSB_REG 0x8F
#define BME280_DIG_P2_LSB_REG 0x90
#define BME280_DIG_P2_MSB_REG 0x91
#define BME280_DIG_P3_LSB_REG 0x92
#define BME280_DIG_P3_MSB_REG 0x93
#define BME280_DIG_P4_LSB_REG 0x94
#define BME280_DIG_P4_MSB_REG 0x95
#define BME280_DIG_P5_LSB_REG 0x96
#define BME280_DIG_P5_MSB_REG 0x97
#define BME280_DIG_P6_LSB_REG 0x98
#define BME280_DIG_P6_MSB_REG 0x99
#define BME280_DIG_P7_LSB_REG 0x9A
#define BME280_DIG_P7_MSB_REG 0x9B
#define BME280_DIG_P8_LSB_REG 0x9C
#define BME280_DIG_P8_MSB_REG 0x9D
#define BME280_DIG_P9_LSB_REG 0x9E
#define BME280_DIG_P9_MSB_REG 0x9F
#define BME280_DIG_H1_REG 0xA1
#define BME280_CHIP_ID_REG 0xD0 //Chip ID
#define BME280_RST_REG 0xE0 //Softreset Reg
#define BME280_DIG_H2_LSB_REG 0xE1
#define BME280_DIG_H2_MSB_REG 0xE2
#define BME280_DIG_H3_REG 0xE3
#define BME280_DIG_H4_MSB_REG 0xE4
#define BME280_DIG_H4_LSB_REG 0xE5
#define BME280_DIG_H5_MSB_REG 0xE6
#define BME280_DIG_H6_REG 0xE7
#define BME280_CTRL_HUMIDITY_REG 0xF2 //Ctrl Humidity Reg
#define BME280_STAT_REG 0xF3 //Status Reg
#define BME280_CTRL_MEAS_REG 0xF4 //Ctrl Measure Reg
#define BME280_CONFIG_REG 0xF5 //Configuration Reg
#define BME280_PRESSURE_MSB_REG 0xF7 //Pressure MSB
#define BME280_PRESSURE_LSB_REG 0xF8 //Pressure LSB
#define BME280_PRESSURE_XLSB_REG 0xF9 //Pressure XLSB
#define BME280_TEMPERATURE_MSB_REG 0xFA //Temperature MSB
#define BME280_TEMPERATURE_LSB_REG 0xFB //Temperature LSB
#define BME280_TEMPERATURE_XLSB_REG 0xFC //Temperature XLSB
#define BME280_HUMIDITY_MSB_REG 0xFD //Humidity MSB
#define BME280_HUMIDITY_LSB_REG 0xFE //Humidity LSB
//Class SensorSettings. This object is used to hold settings data. The application
//uses this classes' data directly. The settings are adopted and sent to the sensor
//at special times, such as .begin. Some are used for doing math.
//
//This is a kind of bloated way to do this. The trade-off is that the user doesn't
//need to deal with #defines or enums with bizarre names.
//
//A power user would strip out SensorSettings entirely, and send specific read and
//write command directly to the IC. (ST #defines below)
//
struct SensorSettings
{
public:
//Main Interface and mode settings
uint8_t commInterface;
uint8_t I2CAddress;
uint8_t chipSelectPin;
uint8_t runMode;
uint8_t tStandby;
uint8_t filter;
uint8_t tempOverSample;
uint8_t pressOverSample;
uint8_t humidOverSample;
};
//Used to hold the calibration constants. These are used
//by the driver as measurements are being taking
struct SensorCalibration
{
public:
uint16_t dig_T1;
int16_t dig_T2;
int16_t dig_T3;
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;
uint8_t dig_H1;
int16_t dig_H2;
uint8_t dig_H3;
int16_t dig_H4;
int16_t dig_H5;
uint8_t dig_H6;
};
//This is the man operational class of the driver.
class BME280
{
public:
//settings
SensorSettings settings;
SensorCalibration calibration;
int32_t t_fine;
//Constructor generates default SensorSettings.
//(over-ride after construction if desired)
BME280( void );
//~BME280() = default;
//Call to apply SensorSettings.
//This also gets the SensorCalibration constants
uint8_t begin( void );
//Software reset routine
void reset( void );
//Returns the values as floats.
float readFloatPressure( void );
float readFloatAltitudeMeters( void );
float readFloatAltitudeFeet( void );
float readFloatHumidity( void );
//Temperature related methods
float readTempC( void );
float readTempF( void );
//The following utilities read and write
//ReadRegisterRegion takes a uint8 array address as input and reads
//a chunk of memory into that array.
void readRegisterRegion(uint8_t*, uint8_t, uint8_t );
//readRegister reads one register
uint8_t readRegister(uint8_t);
//Reads two regs, LSByte then MSByte order, and concatenates them
//Used for two-byte reads
int16_t readRegisterInt16( uint8_t offset );
//Writes a byte;
void writeRegister(uint8_t, uint8_t);
};
#endif // End of __BME280_H__ definition check