Raig Kaufer / Mbed 2 deprecated MS5803-Demo

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MS5803.h Source File

MS5803.h

00001 /*
00002     Permission is hereby granted, free of charge, to any person obtaining a copy
00003     of this software and associated documentation files (the "Software"), to deal
00004     in the Software without restriction, including without limitation the rights
00005     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00006     copies of the Software, and to permit persons to whom the Software is
00007     furnished to do so, subject to the following conditions:
00008 
00009     The above copyright notice and this permission notice shall be included in
00010     all copies or substantial portions of the Software.
00011 
00012     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00013     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00014     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00015     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00016     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00017     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00018     THE SOFTWARE.
00019 
00020   * Barometer Sensor (Altimeter) MS5803-01BA of MEAS Switzerland     (www.meas-spec.com).
00021   * The driver uses I2C mode (sensor PS pin low).
00022   * Other types of MEAS are compatible but not tested.
00023   * Written by Raig Kaufer distribute freely!
00024  */
00025 #include "mbed.h"
00026 
00027 #ifndef MS5803_H
00028 #define MS5803_H
00029 
00030 #define MS5803_RX_DEPTH 3
00031 #define MS5803_TX_DEPTH 2
00032 
00033 
00034 #define ms5803_addrCL 0x77 //0b1110111  CSB Pin is low
00035 #define ms5803_addrCH 0x76 //0b1110110  CSB Pin is high 
00036 
00037 #define ms5803_base_addr ms5803_addrCL // choose your connection here
00038 
00039 #define ms5803_reset       0x1E // Sensor Reset
00040 
00041 #define ms5803_convD1_256  0x40 // Convert D1 OSR 256
00042 #define ms5803_convD1_512  0x42 // Convert D1 OSR  512
00043 #define ms5803_convD1_1024 0x44 // Convert D1 OSR 1024
00044 #define ms5803_convD1_2048 0x46 // Convert D1 OSR 2048
00045 #define ms5803_convD1_4096 0x48 // Convert D1 OSR 2048
00046 
00047 #define ms5803_convD1 ms5803_convD1_4096 // choose your sampling rate here
00048 
00049 #define ms5803_convD2_256  0x50 // Convert D2 OSR  256
00050 #define ms5803_convD2_512  0x52 // Convert D2 OSR  512
00051 #define ms5803_convD2_1024 0x54 // Convert D2 OSR 1024
00052 #define ms5803_convD2_2048 0x56 // Convert D2 OSR 2048
00053 #define ms5803_convD2_4096 0x58 // Convert D2 OSR 2048
00054 
00055 #define ms5803_convD2 ms5803_convD2_4096 // choose your sampling rate here
00056 
00057 #define ms5803_ADCread     0x00 // read ADC command
00058 #define ms5803_PROMread    0xA0 // read PROM command base address
00059 
00060 class MS5803 : public Base {
00061 private:
00062     int D1, D2, Temp, C[8];
00063     float T_MS5803, P_MS5803;
00064     /* Data buffers */
00065     char ms5803_rx_data[MS5803_RX_DEPTH];
00066     char ms5803_tx_data[MS5803_TX_DEPTH];
00067 
00068 public:
00069     MS5803 (PinName sda, PinName scl,
00070             char ms5803_addr = ms5803_base_addr  )
00071             : i2c( sda, scl ), device_address( ms5803_addr << 1 ) {
00072     }
00073     void MS5803Reset(void);
00074     void MS5803ReadProm(void);
00075     void MS5803ConvertD1(void);
00076     void MS5803ConvertD2(void);
00077     int32_t MS5803ReadADC(void);
00078     float MS5803_Pressure (void);
00079     float MS5803_Temperature (void);
00080     void Barometer_MS5803(void);
00081 
00082 
00083 private:
00084     I2C     i2c;
00085     char    device_address;
00086 
00087 };
00088 #endif