Sensorian  1.0
C API Reference Guide Library
MPL3115A2.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (C) 2015 Sensorian
3  * *
4  * This file is part of Sensorian. *
5  * *
6  * Sensorian is free software: you can redistribute it and/or modify it *
7  * under the terms of the GNU Lesser General Public License as published *
8  * by the Free Software Foundation, either version 3 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * Sensorian is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with Sensorian. *
18  * If not, see <http://www.gnu.org/licenses/>. *
19  ****************************************************************************/
20 
29 #ifndef __MPL3115A2_H__
30 #define __MPL3115A2_H__
31 
32 #include <stdint.h>
33 
34 #define TRUE 1
35 #define FALSE 0
36 
40 #define MPL3115A2_ADDRESS 0x60 // 7-bit I2C address for sensor
41 
42 #define STATUS 0x00
43 #define OUT_P_MSB 0x01 //Altitude data
44 #define OUT_P_CSB 0x02
45 #define OUT_P_LSB 0x03
46 #define OUT_T_MSB 0x04
47 #define OUT_T_LSB 0x05
48 #define DR_STATUS 0x06
49 #define OUT_P_DELTA_MSB 0x07
50 #define OUT_P_DELTA_CSB 0x08
51 #define OUT_P_DELTA_LSB 0x09
52 #define OUT_T_DELTA_MSB 0x0A
53 #define OUT_T_DELTA_LSB 0x0B
54 #define WHO_AM_I 0x0C
55 #define F_STATUS 0x0D
56 #define F_DATA 0x0E
57 #define F_SETUP 0x0F
58 #define TIME_DLY 0x10
59 #define SYSMOD 0x11
60 #define INT_SOURCE 0x12
61 #define PT_DATA_CFG 0x13
62 #define BAR_IN_MSB 0x14
63 #define BAR_IN_LSB 0x15
64 #define P_TGT_MSB 0x16
65 #define P_TGT_LSB 0x17
66 #define T_TGT 0x18
67 #define P_WND_MSB 0x19
68 #define P_WND_LSB 0x1A
69 #define T_WND 0x1B
70 #define P_MIN_MSB 0x1C
71 #define P_MIN_CSB 0x1D
72 #define P_MIN_LSB 0x1E
73 #define T_MIN_MSB 0x1F
74 #define T_MIN_LSB 0x20
75 #define P_MAX_MSB 0x21
76 #define P_MAX_CSB 0x22
77 #define P_MAX_LSB 0x23
78 #define T_MAX_MSB 0x24
79 #define T_MAX_LSB 0x25
80 #define CTRL_REG1 0x26
81 #define CTRL_REG2 0x27
82 #define CTRL_REG3 0x28
83 #define CTRL_REG4 0x29
84 #define CTRL_REG5 0x2A
85 #define OFF_P 0x2B
86 #define OFF_T 0x2C
87 #define OFF_H 0x2D
88 
89 /**********************DR Status **************************************/
90 #define PTOW 0x80
91 #define POW 0x40 //Pressure overwrite
92 #define TOW 0x20
93 #define PTDR 0x08 //Pressure/Altitude OR Temperature data ready
94 #define PDR 0x04 //Pressure/Altitude new data available
95 #define TDR 0x02 //Temperature new Data Available.
96 
97 
98 /**********************Control Register 1****************************/
99 #define ALT 0x80
100 #define RAW 0x40
101 #define OS2 0x20
102 #define OS1 0x10
103 #define OS0 0x08
104 #define RST 0x04
105 #define OST 0x02
106 #define SBYB 0x01 //Active mode
107 
108 // Oversample Ratio 1
109 #define OS_1 0x00 // 6 ms min between samples
110 #define OS_2 OS0 // 10 ms
111 #define OS_4 OS1 // 18 ms
112 #define OS_8 OS1 | OS0 // 34 ms
113 #define OS_16 OS2 // 66 ms
114 #define OS_32 OS2 | OS0 // 130 ms
115 #define OS_64 OS2 | OS1 // 258 ms
116 #define OS_128 OS2 | OS1 | OS0 // 512 ms
117 
118 #define BAR_MASK 0x80
119 #define ALT_MASK 0xEF
120 #define ACTIVE_MASK 0xF1
121 #define STANDBY_MASK 0xFE
122 
123 /**********************Control Register 2****************************/
124 #define ALARM_SEL 0x20
125 #define LOAD_OUTPUT 0x10
126 #define ST3 0x08
127 #define ST2 0x04
128 #define ST1 0x02
129 #define ST0 0x01
130 #define CLEAR_ST 0xF0
131 
132 /**********************Control Register 3****************************/
133 #define IPOL1 0x10 //Set to 1 for Active HIGH on INT1
134 #define PP_OD1 0x08 //Set to 0 for internal pull up
135 #define IPOL2 0x02 //1 Active high, 0 Active Low Interrupt on Pad2
136 #define PP_OD2 0x01 //Set to 0 for internal pull up
137 
138 /**********************Control Register 4****************************/
139 #define INT_EN_DRDY 0x80 //Set to 1: Data Ready interrupt enabled
140 #define INT_EN_FIFO 0x40 //Set to 1: FIFO interrupt enabled
141 #define INT_EN_PW 0x20 //Set to 1: Pressure window interrupt enabled
142 #define INT_EN_TW 0x10 //Set to 1: Temperature window interrupt enabled
143 #define INT_EN_PTH 0x08 //Set to 1: Pressure Threshold interrupt enabled
144 #define INT_EN_TTH 0x04 //Set to 1: Temperature Threshold interrupt enabled
145 #define INT_EN_PCHG 0x02 //Set to 1: Pressure Change interrupt enabled.
146 #define INT_EN_TCHG 0x01 //Set to 1: Temperature Change interrupt enabled
147 #define INT_EN_CLEAR 0x00
148 
149 /**********************Control Register 5****************************/
150 
151 #define INT_CFG_DRDY 0x80 //1: Interrupt is routed to INT1
152 #define INT_CFG_FIFO 0x40
153 #define INT_CFG_PW 0x20
154 #define INT_CFG_TW 0x10
155 #define INT_CFG_PTH 0x08
156 #define INT_CFG_TTH 0x04
157 #define INT_CFG_PCHG 0x02
158 #define INT_CFG_TCHG 0x01
159 
160 #define INT_CFG_CLEAR 0x00
161 
162 #define INT2 0
163 #define INT1 1
164 /**************************************************************************/
165 
166 #define DISABLED 0x00
167 #define CIRCULAR 0x40
168 #define FULL_STOP 0x80
169 #define F_MODE DISABLED
170 /******************PT_DATA_CFG - Sensor data event flag register***********/
171 #define DREM 0x04 // Data Ready Event Mode
172 #define PDEFE 0x02 // Pressure Data Event Flag Enabled
173 #define TDEFE 0x01 // Temperature Data Event Flag Enabled
174 
175 /*************************** INT_SOURCE Register*****************************/
176 
177 #define SRC_DRDY 0x80
178 #define SRC_FIFO 0x40
179 #define SRC_PW 0x20
180 #define SRC_TW 0x10
181 #define SRC_PTH 0x08
182 #define SRC_TTH 0x04
183 #define SRC_PCHG 0x02
184 #define SRC_TCHG 0x01
185 
186 /*******************************************************************************/
187 
188 typedef enum { PSI,
191 
192 typedef enum { SR1 = OS_1,
193  SR2 = OS_2,
194  SR3 = OS_4,
195  SR4 = OS_8,
197  SR6 = OS_32,
198  SR7 = OS_64,
200 
201 void MPL3115A2_Initialize(void);
202 unsigned char MPL3115A2_ID(void);
203 unsigned char MPL3115A2_GetMode(void);
204 void MPL3115A2_StandbyMode(void); // Puts the sensor into Standby mode. Required when changing CTRL1 register.
205 void MPL3115A2_ActiveMode(void); // Start taking measurements!
206 
207 void MPL3115A2_AltimeterMode(void); // Puts the sensor into altimetery mode.
208 float MPL3115A2_ReadAltitude(void); // Returns float with meters above sealevel. Ex: 1638.94
209 void MPL3115A2_SetAltimeterOffset(unsigned char H_Offset);
210 
211 void MPL3115A2_BarometerMode(void); // Puts the sensor into Pascal measurement mode.
212 void MPL3115A2_SetPressureOffset(unsigned char P_Offset);
213 float MPL3115A2_GetMinimumPressure(void);
214 float MPL3115A2_GetMaximumPressure(void);
215 unsigned int MPL3115A2_ReadBarometicPressureInput(void);
216 float MPL3115A2_ReadBarometricPressure(void); // Returns float with barometric pressure in Pa
217 float MPL3115A2_ReadPressure(unitsType units);
218 void MPL3115A2_SetPressureAlarmThreshold(unsigned int thresh);
219 void MPL3115A2_SetPressureTargetWindow(unsigned int target,unsigned int window);
220 
221 float MPL3115A2_ReadTemperature(void); // Returns float with current temperature in Celsius
224 void MPL3115A2_SetTempTargetWindow(unsigned int target,unsigned int window);
225 void MPL3115A2_SetTemperatureThreshold(unsigned char thresh);
226 void MPL3115A2_SetTempOffset(char T_Offset);
227 
228 void MPL3115A2_OutputSampleRate(unsigned char); // Sets the # of samples from 1 to 128. See datasheet.
229 void MPL3115A2_SetAcquisitionTimeStep(unsigned char); // Sets the # of time steps
230 void MPL3115A2_EnableEventFlags(void); // Sets the fundamental event flags. Required during setup.
231 void MPL3115A2_ToggleOneShot(void);
232 
233 void MPL3115A2_ClearInterrupts(void);
234 void MPL3115A2_ConfigureInterruptPin(unsigned char intrrpt,unsigned char pin);
237 
238 unsigned char MPL3115A2_ReadByte(char reg);
239 void MPL3115A2_ReadByteArray(char reg,char *buffer, unsigned int length);
240 void MPL3115A2_WriteByte(char reg, char value);
241 void MPL3115A2_WriteByteArray(char reg, char* buffer, unsigned int length);
242 
243 #endif
float MPL3115A2_ReadPressure(unitsType units)
Get a barometric pressure reading.
Definition: MPL3115A2.c:230
#define OS_8
Definition: MPL3115A2.h:112
Definition: MPL3115A2.h:194
#define OS_2
Definition: MPL3115A2.h:110
#define OS_16
Definition: MPL3115A2.h:113
unitsType
Definition: MPL3115A2.h:188
void MPL3115A2_SetPressureAlarmThreshold(unsigned int thresh)
Configure alarm threshold.
Definition: MPL3115A2.c:251
unsigned char buffer[256]
Definition: main.c:74
unsigned char MPL3115A2_ID(void)
Returns the Factory Chip ID.
Definition: MPL3115A2.c:51
void MPL3115A2_SetTempTargetWindow(unsigned int target, unsigned int window)
Configures the temperature target and window for the interrupts.
Definition: MPL3115A2.c:329
#define OS_1
Definition: MPL3115A2.h:109
Definition: MPL3115A2.h:193
float MPL3115A2_ReadTemperature(void)
Get a temperature reading from the sensor.
Definition: MPL3115A2.c:282
Definition: MPL3115A2.h:196
float MPL3115A2_ReadAltitude(void)
Returns the number of meters above sea level,Returns -1 if no new data is available.
Definition: MPL3115A2.c:107
Definition: MPL3115A2.h:188
void MPL3115A2_BarometerMode(void)
Configure the sensor in Barometer mode.
Definition: MPL3115A2.c:135
void MPL3115A2_ConfigurePressureInterrupt(void)
Configure Pressure Interrupt.
Definition: MPL3115A2.c:432
void MPL3115A2_WriteByte(char reg, char value)
Write a single byte to the register.
Definition: MPL3115A2.c:490
Definition: MPL3115A2.h:195
void MPL3115A2_ReadByteArray(char reg, char *buffer, unsigned int length)
Read byte value from register.
Definition: MPL3115A2.c:479
void MPL3115A2_ClearInterrupts(void)
Clear any existing interrupts.
Definition: MPL3115A2.c:450
void MPL3115A2_ToggleOneShot(void)
Causes the sensor to immediately take another reading , needed to sample faster than 1Hz...
Definition: MPL3115A2.c:407
#define OS_32
Definition: MPL3115A2.h:114
void MPL3115A2_SetPressureOffset(unsigned char P_Offset)
Set the pressure offset correction.
Definition: MPL3115A2.c:150
Definition: MPL3115A2.h:199
void MPL3115A2_SetAcquisitionTimeStep(unsigned char)
Set the acquisition time step in seconds.
Definition: MPL3115A2.c:380
#define OS_128
Definition: MPL3115A2.h:116
float MPL3115A2_GetMinimumPressure(void)
Get minimum stored pressure.
Definition: MPL3115A2.c:162
float MPL3115A2_GetMinimumTemperature(void)
Get minimum recorded temperature reading.
Definition: MPL3115A2.c:297
#define OS_4
Definition: MPL3115A2.h:111
unsigned char MPL3115A2_GetMode(void)
Return a bool value indicating wheather the sensor is in Active or Standby mode.
Definition: MPL3115A2.c:61
float MPL3115A2_ReadBarometricPressure(void)
Reads the current pressure in Pa.
Definition: MPL3115A2.c:205
void MPL3115A2_SetTempOffset(char T_Offset)
Used to correct the measured sensor temeperature by a particular offset.
Definition: MPL3115A2.c:351
void MPL3115A2_ConfigureInterruptPin(unsigned char intrrpt, unsigned char pin)
Configure Interrupt pins.
Definition: MPL3115A2.c:423
void MPL3115A2_Initialize(void)
Initialize the sensor and enable interrupts.
Definition: MPL3115A2.c:40
Definition: MPL3115A2.h:192
void MPL3115A2_SetTemperatureThreshold(unsigned char thresh)
Configure the temeperature threshold.
Definition: MPL3115A2.c:340
void MPL3115A2_EnableEventFlags(void)
Enables the pressure and temp measurement event flags so that we can test against them...
Definition: MPL3115A2.c:398
Definition: MPL3115A2.h:198
OverSample_t
Definition: MPL3115A2.h:192
void MPL3115A2_AltimeterMode(void)
Sets the mode to Altimeter.
Definition: MPL3115A2.c:93
void MPL3115A2_WriteByteArray(char reg, char *buffer, unsigned int length)
Writes an array of bytes to the sensor.
Definition: MPL3115A2.c:502
unsigned char MPL3115A2_ReadByte(char reg)
Read byte value from register.
Definition: MPL3115A2.c:467
void MPL3115A2_SetAltimeterOffset(unsigned char H_Offset)
Set the altimeter offset correction.
Definition: MPL3115A2.c:123
float MPL3115A2_GetMaximumTemperature(void)
Get maximum recorded temperature reading.
Definition: MPL3115A2.c:312
Definition: MPL3115A2.h:197
void MPL3115A2_ActiveMode(void)
Puts the sensor in active mode, needed is the sensor is in standby mode.
Definition: MPL3115A2.c:82
void MPL3115A2_StandbyMode(void)
Puts the sensor in standby mode, the user must do this in order to modify the major control registers...
Definition: MPL3115A2.c:71
void MPL3115A2_SetPressureTargetWindow(unsigned int target, unsigned int window)
Configure alarm target and window.
Definition: MPL3115A2.c:265
void MPL3115A2_OutputSampleRate(unsigned char)
Configures the output sample rate.The higher the oversample rate the greater the time between data sa...
Definition: MPL3115A2.c:361
#define OS_64
Definition: MPL3115A2.h:115
unsigned int MPL3115A2_ReadBarometicPressureInput(void)
Returns barometric pressure input used for calculating altitude.
Definition: MPL3115A2.c:193
float MPL3115A2_GetMaximumPressure(void)
Get maximum stored pressure.
Definition: MPL3115A2.c:178
void MPL3115A2_ConfigureAltitudeInterrupt(void)
Configure altitude interrupt pin.
Definition: MPL3115A2.c:441