Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1993 | - | 1 | /* |
2 | MS5611-01BA.h - Interfaces a Measurement Specialities MS5611-01BA with Arduino |
||
3 | See http://www.meas-spec.com/downloads/MS5611-01BA01.pdf for the device datasheet |
||
4 | |||
5 | Copyright (C) 2011 Fabio Varesano <fvaresano@yahoo.it> |
||
6 | |||
7 | Development of this code has been supported by the Department of Computer Science, Universita' degli Studi di Torino, Italy within the Piemonte Project http://www.piemonte.di.unito.it/ |
||
8 | |||
9 | |||
10 | This program is free software: you can redistribute it and/or modify |
||
11 | it under the terms of the version 3 GNU General Public License as |
||
12 | published by the Free Software Foundation. |
||
13 | |||
14 | This program is distributed in the hope that it will be useful, |
||
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
17 | GNU General Public License for more details. |
||
18 | |||
19 | You should have received a copy of the GNU General Public License |
||
20 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
21 | |||
22 | */ |
||
23 | |||
24 | |||
25 | |||
26 | #ifndef MS561101BA_h |
||
27 | #define MS561101BA_h |
||
28 | |||
29 | #ifndef cbi |
||
30 | #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) |
||
31 | #endif |
||
32 | |||
33 | #include "WProgram.h" |
||
34 | #include <Wire.h> |
||
35 | |||
36 | //#define DEBUG_V |
||
37 | //#define DEBUG |
||
38 | //#include <DebugUtils.h> |
||
39 | |||
40 | // addresses of the device |
||
41 | #define MS561101BA_ADDR_CSB_HIGH 0x76 //CBR=1 0x76 I2C address when CSB is connected to HIGH (VCC) |
||
42 | #define MS561101BA_ADDR_CSB_LOW 0x77 //CBR=0 0x77 I2C address when CSB is connected to LOW (GND) |
||
43 | |||
44 | // registers of the device |
||
45 | #define MS561101BA_D1 0x40 |
||
46 | #define MS561101BA_D2 0x50 |
||
47 | #define MS561101BA_RESET 0x1E |
||
48 | |||
49 | // D1 and D2 result size (bytes) |
||
50 | #define MS561101BA_D1D2_SIZE 3 |
||
51 | |||
52 | // OSR (Over Sampling Ratio) constants |
||
53 | #define MS561101BA_OSR_256 0x00 |
||
54 | #define MS561101BA_OSR_512 0x02 |
||
55 | #define MS561101BA_OSR_1024 0x04 |
||
56 | #define MS561101BA_OSR_2048 0x06 |
||
57 | #define MS561101BA_OSR_4096 0x08 |
||
58 | |||
59 | #define MS561101BA_PROM_BASE_ADDR 0xA2 // by adding ints from 0 to 6 we can read all the prom configuration values. |
||
60 | // C1 will be at 0xA2 and all the subsequent are multiples of 2 |
||
61 | #define MS561101BA_PROM_REG_COUNT 6 // number of registers in the PROM |
||
62 | #define MS561101BA_PROM_REG_SIZE 2 // size in bytes of a prom registry. |
||
63 | |||
64 | |||
65 | |||
66 | class MS561101BA { |
||
67 | public: |
||
68 | MS561101BA(); |
||
69 | void init(uint8_t addr); |
||
70 | float getPressure(uint8_t OSR); |
||
71 | float getTemperature(uint8_t OSR); |
||
72 | int64_t getDeltaTemp(uint8_t OSR); |
||
73 | int32_t rawPressure(uint8_t OSR); |
||
74 | int32_t rawTemperature(uint8_t OSR); |
||
75 | int readPROM(); |
||
76 | void reset(); |
||
77 | private: |
||
78 | unsigned long doConversion(uint8_t command); |
||
79 | uint8_t _addr; |
||
80 | uint16_t _C[MS561101BA_PROM_REG_COUNT]; |
||
81 | }; |
||
82 | |||
83 | #endif // MS561101BA_h |