Contiki 2.5
pressure-bmp085.h
Go to the documentation of this file.
1 /* Copyright (c) 2010, Ulf Kulau
2  *
3  * Permission is hereby granted, free of charge, to any person
4  * obtaining a copy of this software and associated documentation
5  * files (the "Software"), to deal in the Software without
6  * restriction, including without limitation the rights to use,
7  * copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following
10  * conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 /**
26  * \addtogroup Device Interfaces
27  * @{
28  *
29  * \defgroup Bosch BMP085 Digital Pressure Sensor
30  *
31  * <p>With an pressure sensor it is possible to measure the activity of
32  * a person. Especially the Bosch BMP085 allows the registration of small
33  * height fluctuations by sensing the air pressure. In some related papers,
34  * a concrete application was implemented, to show how a fall analysis could
35  * be done</p>
36  *
37  * @{
38  *
39  */
40 
41 /**
42  * \file
43  * Bosch BMP085 Digital Pressure Sensor
44  * \author
45  * Ulf Kulau <kulau@ibr.cs.tu-bs.de>
46  */
47 #include "../drv/i2c-drv.h"
48 #include <util/delay.h>
49 
50 #ifndef PRESSUREBMP085_H_
51 #define PRESSUREBMP085_H_
52 /*Pressure Sensor BMP085 device address*/
53 /*!
54  * I2C address to read data
55  */
56 #define BMP085_DEV_ADDR_R 0xEF
57 /*!
58  * I2C address to write data
59  */
60 #define BMP085_DEV_ADDR_W 0xEE
61 /*Control register address*/
62 /*!
63  * Basic control register address
64  */
65 #define BMP085_CTRL_REG_ADDR 0xF4
66 /*!
67  * Control register address for temperature
68  */
69 #define BMP085_CTRL_REG_TEMP 0x2E
70 /*!
71  * Control register address for oversampling mode 0
72  */
73 #define BMP085_CTRL_REG_PRESS_0 0x34
74 /*!
75  * Control register address for oversampling mode 1
76  */
77 #define BMP085_CTRL_REG_PRESS_1 0x74
78 /*!
79  * Control register address for oversampling mode 2
80  */
81 #define BMP085_CTRL_REG_PRESS_2 0xB4
82 /*!
83  * Control register address for oversampling mode 3
84  */
85 #define BMP085_CTRL_REG_PRESS_3 0xF4
86 /*Data register*/
87 /*!
88  * Main data register address
89  */
90 #define BMP085_DATA_REG_N 0xF6
91 /*!
92  * Extended data register address for 19bit
93  * resolution
94  */
95 #define BMP085_DATA_REG_X 0xF8
96 /*EEPROM Register addresses for calibration data*/
97 /*!
98  * Coefficient AC1 eeprom address
99  */
100 #define BMP085_AC1_ADDR 0xAA
101 /*!
102  * Coefficient AC2 eeprom address
103  */
104 #define BMP085_AC2_ADDR 0xAC
105 /*!
106  * Coefficient AC3 eeprom address
107  */
108 #define BMP085_AC3_ADDR 0xAE
109 /*!
110  * Coefficient AC4 eeprom address
111  */
112 #define BMP085_AC4_ADDR 0xB0
113 /*!
114  * Coefficient AC5 eeprom address
115  */
116 #define BMP085_AC5_ADDR 0xB2
117 /*!
118  * Coefficient AC6 eeprom address
119  */
120 #define BMP085_AC6_ADDR 0xB4
121 /*!
122  * Coefficient B1 eeprom address
123  */
124 #define BMP085_B1_ADDR 0xB6
125 /*!
126  * Coefficient B2 eeprom address
127  */
128 #define BMP085_B2_ADDR 0xB8
129 /*!
130  * Coefficient MB eeprom address
131  */
132 #define BMP085_MB_ADDR 0xBA
133 /*!
134  * Coefficient MC eeprom address
135  */
136 #define BMP085_MC_ADDR 0xBC
137 /*!
138  * Coefficient MD eeprom address
139  */
140 #define BMP085_MD_ADDR 0xBE
141 /*!
142  * Hold all coefficients
143  */
144 typedef struct {
145  volatile int16_t ac1;
146  volatile int16_t ac2;
147  volatile int16_t ac3;
148  volatile uint16_t ac4;
149  volatile uint16_t ac5;
150  volatile uint16_t ac6;
151  volatile int16_t b1;
152  volatile int16_t b2;
153  volatile int16_t mb;
154  volatile int16_t mc;
155  volatile int16_t md;
157 /*!
158  * Hold all coefficients
159  */
160 static bmp085_calib_data bmp085_coeff;
161 
162 /**
163  * \brief Initialize the MPL115A Pressure Sensor
164  *
165  * \return <ul>
166  * <li> 0 at45db available
167  * <li> -1 at45db not available
168  * </ul>
169  */
170 int8_t bmp085_init(void);
171 
172 /**
173  * \brief This functions reads the raw value of one
174  * temperature conversion
175  *
176  * \return Temperature raw value (not compensated)
177  */
178 int32_t bmp085_read_temperature(void);
179 
180 /**
181  * \brief This function reads the raw temperature value and
182  * converts it to real temerature
183  *
184  * return Temerature in 0.1 Degree
185  */
186 int32_t bmp085_read_comp_temperature(void);
187 /**
188  * \brief This functions reads the raw value of one
189  * pressure conversion.
190  *
191  * \param mode <table border="1">
192  * <tr>
193  * <th> 0 </th>
194  * <th> 1 </th>
195  * <th> 2 </th>
196  * <th> 3 </th>
197  * </tr>
198  * <tr>
199  * <td> ultra low power </td>
200  * <td> standard </td>
201  * <td> high resolution </td>
202  * <td> ultra high resolution </td>
203  * </tr>
204  * </table>
205  *
206  * \return Temperature raw value (not compensated)
207  */
208 int32_t bmp085_read_pressure(uint8_t mode);
209 
210 /**
211  * \brief This functions reads the temperature compensated
212  * value of one pressure conversion
213  *
214  *
215  * \param mode <table border="1">
216  * <tr>
217  * <th> 0 </th>
218  * <th> 1 </th>
219  * <th> 2 </th>
220  * <th> 3 </th>
221  * </tr>
222  * <tr>
223  * <td> ultra low power </td>
224  * <td> standard </td>
225  * <td> high resolution </td>
226  * <td> ultra high resolution </td>
227  * </tr>
228  * </table>
229  *
230  * \return Temperature raw value (not compensated)
231  */
232 int32_t bmp085_read_comp_pressure(uint8_t mode);
233 
234 /**
235  * \brief Reads all coefficients from eeprom
236  */
237 void bmp085_read_calib_data(void);
238 
239 /**
240  * \brief Generic minor function to read two byte
241  * sequentially
242  *
243  * \return 16Bit (two Byte) data from bmp085
244  */
245 uint16_t bmp085_read16bit_data(uint8_t addr);
246 
247 /**
248  * \brief Generic minor function to read one byte
249  *
250  * \return 8Bit (one Byte) data from bmp085
251  */
252 uint8_t bmp085_read8bit_data(uint8_t addr);
253 
254 #endif /* PRESSUREBMP085_H_ */