Demonstrate the usage of MS5803-01BA Miniature Variometer Module.

Dependencies:   mbed

Committer:
Raig
Date:
Sat Apr 07 14:18:42 2012 +0000
Revision:
0:f0809a7877ff
Demo of MS5803 barometer sensor. Dont forget the pull up resistors of 10kOhm on the SDA and SCL lines!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Raig 0:f0809a7877ff 1 /*
Raig 0:f0809a7877ff 2 Permission is hereby granted, free of charge, to any person obtaining a copy
Raig 0:f0809a7877ff 3 of this software and associated documentation files (the "Software"), to deal
Raig 0:f0809a7877ff 4 in the Software without restriction, including without limitation the rights
Raig 0:f0809a7877ff 5 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Raig 0:f0809a7877ff 6 copies of the Software, and to permit persons to whom the Software is
Raig 0:f0809a7877ff 7 furnished to do so, subject to the following conditions:
Raig 0:f0809a7877ff 8
Raig 0:f0809a7877ff 9 The above copyright notice and this permission notice shall be included in
Raig 0:f0809a7877ff 10 all copies or substantial portions of the Software.
Raig 0:f0809a7877ff 11
Raig 0:f0809a7877ff 12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Raig 0:f0809a7877ff 13 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Raig 0:f0809a7877ff 14 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Raig 0:f0809a7877ff 15 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Raig 0:f0809a7877ff 16 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Raig 0:f0809a7877ff 17 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Raig 0:f0809a7877ff 18 THE SOFTWARE.
Raig 0:f0809a7877ff 19
Raig 0:f0809a7877ff 20 * Barometer Sensor (Altimeter) MS5803-01BA of MEAS Switzerland (www.meas-spec.com).
Raig 0:f0809a7877ff 21 * The driver uses I2C mode (sensor PS pin low).
Raig 0:f0809a7877ff 22 * Other types of MEAS are compatible but not tested.
Raig 0:f0809a7877ff 23 * Written by Raig Kaufer distribute freely!
Raig 0:f0809a7877ff 24 */
Raig 0:f0809a7877ff 25 #include "mbed.h"
Raig 0:f0809a7877ff 26
Raig 0:f0809a7877ff 27 #ifndef MS5803_H
Raig 0:f0809a7877ff 28 #define MS5803_H
Raig 0:f0809a7877ff 29
Raig 0:f0809a7877ff 30 #define MS5803_RX_DEPTH 3
Raig 0:f0809a7877ff 31 #define MS5803_TX_DEPTH 2
Raig 0:f0809a7877ff 32
Raig 0:f0809a7877ff 33
Raig 0:f0809a7877ff 34 #define ms5803_addrCL 0x77 //0b1110111 CSB Pin is low
Raig 0:f0809a7877ff 35 #define ms5803_addrCH 0x76 //0b1110110 CSB Pin is high
Raig 0:f0809a7877ff 36
Raig 0:f0809a7877ff 37 #define ms5803_base_addr ms5803_addrCL // choose your connection here
Raig 0:f0809a7877ff 38
Raig 0:f0809a7877ff 39 #define ms5803_reset 0x1E // Sensor Reset
Raig 0:f0809a7877ff 40
Raig 0:f0809a7877ff 41 #define ms5803_convD1_256 0x40 // Convert D1 OSR 256
Raig 0:f0809a7877ff 42 #define ms5803_convD1_512 0x42 // Convert D1 OSR 512
Raig 0:f0809a7877ff 43 #define ms5803_convD1_1024 0x44 // Convert D1 OSR 1024
Raig 0:f0809a7877ff 44 #define ms5803_convD1_2048 0x46 // Convert D1 OSR 2048
Raig 0:f0809a7877ff 45 #define ms5803_convD1_4096 0x48 // Convert D1 OSR 2048
Raig 0:f0809a7877ff 46
Raig 0:f0809a7877ff 47 #define ms5803_convD1 ms5803_convD1_4096 // choose your sampling rate here
Raig 0:f0809a7877ff 48
Raig 0:f0809a7877ff 49 #define ms5803_convD2_256 0x50 // Convert D2 OSR 256
Raig 0:f0809a7877ff 50 #define ms5803_convD2_512 0x52 // Convert D2 OSR 512
Raig 0:f0809a7877ff 51 #define ms5803_convD2_1024 0x54 // Convert D2 OSR 1024
Raig 0:f0809a7877ff 52 #define ms5803_convD2_2048 0x56 // Convert D2 OSR 2048
Raig 0:f0809a7877ff 53 #define ms5803_convD2_4096 0x58 // Convert D2 OSR 2048
Raig 0:f0809a7877ff 54
Raig 0:f0809a7877ff 55 #define ms5803_convD2 ms5803_convD2_4096 // choose your sampling rate here
Raig 0:f0809a7877ff 56
Raig 0:f0809a7877ff 57 #define ms5803_ADCread 0x00 // read ADC command
Raig 0:f0809a7877ff 58 #define ms5803_PROMread 0xA0 // read PROM command base address
Raig 0:f0809a7877ff 59
Raig 0:f0809a7877ff 60 class MS5803 : public Base {
Raig 0:f0809a7877ff 61 private:
Raig 0:f0809a7877ff 62 int D1, D2, Temp, C[8];
Raig 0:f0809a7877ff 63 float T_MS5803, P_MS5803;
Raig 0:f0809a7877ff 64 /* Data buffers */
Raig 0:f0809a7877ff 65 char ms5803_rx_data[MS5803_RX_DEPTH];
Raig 0:f0809a7877ff 66 char ms5803_tx_data[MS5803_TX_DEPTH];
Raig 0:f0809a7877ff 67
Raig 0:f0809a7877ff 68 public:
Raig 0:f0809a7877ff 69 MS5803 (PinName sda, PinName scl,
Raig 0:f0809a7877ff 70 char ms5803_addr = ms5803_base_addr )
Raig 0:f0809a7877ff 71 : i2c( sda, scl ), device_address( ms5803_addr << 1 ) {
Raig 0:f0809a7877ff 72 }
Raig 0:f0809a7877ff 73 void MS5803Reset(void);
Raig 0:f0809a7877ff 74 void MS5803ReadProm(void);
Raig 0:f0809a7877ff 75 void MS5803ConvertD1(void);
Raig 0:f0809a7877ff 76 void MS5803ConvertD2(void);
Raig 0:f0809a7877ff 77 int32_t MS5803ReadADC(void);
Raig 0:f0809a7877ff 78 float MS5803_Pressure (void);
Raig 0:f0809a7877ff 79 float MS5803_Temperature (void);
Raig 0:f0809a7877ff 80 void Barometer_MS5803(void);
Raig 0:f0809a7877ff 81
Raig 0:f0809a7877ff 82
Raig 0:f0809a7877ff 83 private:
Raig 0:f0809a7877ff 84 I2C i2c;
Raig 0:f0809a7877ff 85 char device_address;
Raig 0:f0809a7877ff 86
Raig 0:f0809a7877ff 87 };
Raig 0:f0809a7877ff 88 #endif