This is a fork of MS5803-01 library by Raig Kaufer adapted for the MS5803-14BA.

Dependents:   MS5803_demo ARNSRS_SERVOS_USB_TFT pdiot-MS5803-test

Committer:
frada
Date:
Wed Jun 29 09:14:44 2016 +0000
Revision:
1:373f735e50e2
Parent:
0:a5f77652b3bb
Many improvements done; among all the most relevant is the use of second order temperature compensation for temperature and pressure readings (as specified in the MS5803-14BA datasheet from Measurement Specitalties).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frada 0:a5f77652b3bb 1 /*
frada 0:a5f77652b3bb 2 Permission is hereby granted, free of charge, to any person obtaining a copy
frada 0:a5f77652b3bb 3 of this software and associated documentation files (the "Software"), to deal
frada 0:a5f77652b3bb 4 in the Software without restriction, including without limitation the rights
frada 0:a5f77652b3bb 5 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
frada 0:a5f77652b3bb 6 copies of the Software, and to permit persons to whom the Software is
frada 0:a5f77652b3bb 7 furnished to do so, subject to the following conditions:
frada 0:a5f77652b3bb 8
frada 0:a5f77652b3bb 9 The above copyright notice and this permission notice shall be included in
frada 0:a5f77652b3bb 10 all copies or substantial portions of the Software.
frada 0:a5f77652b3bb 11
frada 0:a5f77652b3bb 12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
frada 0:a5f77652b3bb 13 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
frada 0:a5f77652b3bb 14 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
frada 0:a5f77652b3bb 15 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
frada 0:a5f77652b3bb 16 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
frada 0:a5f77652b3bb 17 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
frada 0:a5f77652b3bb 18 THE SOFTWARE.
frada 0:a5f77652b3bb 19
frada 0:a5f77652b3bb 20 * Demo Program
frada 0:a5f77652b3bb 21 * Barometer Sensor (Altimeter) MS5803-01BA of MEAS Switzerland (www.meas-spec.com).
frada 0:a5f77652b3bb 22 * The driver uses I2C mode (sensor PS pin low).
frada 0:a5f77652b3bb 23 * Other types of MEAS are compatible but not tested.
frada 0:a5f77652b3bb 24 * Written by Raig Kaufer distribute freely!
frada 0:a5f77652b3bb 25 *
frada 0:a5f77652b3bb 26 * Modified for MS5803-14BA by Francesco Adamo, Italy
frada 0:a5f77652b3bb 27 */
frada 0:a5f77652b3bb 28
frada 0:a5f77652b3bb 29 #include "mbed.h"
frada 0:a5f77652b3bb 30
frada 0:a5f77652b3bb 31 #ifndef MS5803_14BA_H
frada 0:a5f77652b3bb 32 #define MS5803_14BA_H
frada 0:a5f77652b3bb 33
frada 0:a5f77652b3bb 34 #define MS5803_RX_DEPTH 3
frada 0:a5f77652b3bb 35 #define MS5803_TX_DEPTH 2
frada 0:a5f77652b3bb 36
frada 0:a5f77652b3bb 37
frada 1:373f735e50e2 38 #define MS5803_ADDRC_L (uint8_t) 0x77 //0b01110111 CSB Pin is low
frada 1:373f735e50e2 39 #define MS5803_ADDRC_H (uint8_t) 0x76 //0b01110110 CSB Pin is high
frada 0:a5f77652b3bb 40
frada 1:373f735e50e2 41 #define MS5803_BASE_ADDR MS5803_ADDRC_H // choose your connection here
frada 0:a5f77652b3bb 42
frada 0:a5f77652b3bb 43 #define COMMAND_RESET 0x1E // Sensor Reset
frada 0:a5f77652b3bb 44
frada 1:373f735e50e2 45 #define D1_OSR_256 0x40 // Convert D1 OSR 256
frada 0:a5f77652b3bb 46 #define D1_OSR_512 0x42 // Convert D1 OSR 512
frada 0:a5f77652b3bb 47 #define D1_OSR_1024 0x44 // Convert D1 OSR 1024
frada 0:a5f77652b3bb 48 #define D1_OSR_2048 0x46 // Convert D1 OSR 2048
frada 0:a5f77652b3bb 49 #define D1_OSR_4096 0x48 // Convert D1 OSR 4096
frada 0:a5f77652b3bb 50
frada 0:a5f77652b3bb 51 #define D2_OSR_256 0x50 // Convert D2 OSR 256
frada 0:a5f77652b3bb 52 #define D2_OSR_512 0x52 // Convert D2 OSR 512
frada 0:a5f77652b3bb 53 #define D2_OSR_1024 0x54 // Convert D2 OSR 1024
frada 0:a5f77652b3bb 54 #define D2_OSR_2048 0x56 // Convert D2 OSR 2048
frada 0:a5f77652b3bb 55 #define D2_OSR_4096 0x58 // Convert D2 OSR 4096
frada 0:a5f77652b3bb 56
frada 0:a5f77652b3bb 57 #define COMMAND_READ_ADC 0x00 // read ADC command
frada 0:a5f77652b3bb 58 #define COMMAND_READ_PROM 0xA0 // read PROM command base address
frada 0:a5f77652b3bb 59
frada 0:a5f77652b3bb 60 class MS5803_14BA {
frada 0:a5f77652b3bb 61 private:
frada 0:a5f77652b3bb 62 I2C _i2c;
frada 1:373f735e50e2 63 uint8_t _address, _d1_osr, _d2_osr;
frada 0:a5f77652b3bb 64
frada 0:a5f77652b3bb 65 uint32_t D1, D2;
frada 0:a5f77652b3bb 66 uint16_t C[8];
frada 0:a5f77652b3bb 67 /* Data buffers */
frada 0:a5f77652b3bb 68 char MS5803_rx_data[MS5803_RX_DEPTH];
frada 0:a5f77652b3bb 69 char MS5803_tx_data[MS5803_TX_DEPTH];
frada 0:a5f77652b3bb 70
frada 0:a5f77652b3bb 71 public:
frada 1:373f735e50e2 72 float temperature, pressure;
frada 1:373f735e50e2 73
frada 1:373f735e50e2 74 MS5803_14BA(PinName sda, PinName scl, uint8_t MS5803_ADDR);
frada 1:373f735e50e2 75 MS5803_14BA(PinName sda, PinName scl, uint8_t MS5803_ADDR, uint8_t d1_osr, uint8_t d2_osr);
frada 0:a5f77652b3bb 76
frada 0:a5f77652b3bb 77 void reset(void);
frada 0:a5f77652b3bb 78 void readPROM(void);
frada 0:a5f77652b3bb 79 void convert(void);
frada 1:373f735e50e2 80 int32_t readADC();
frada 0:a5f77652b3bb 81 };
frada 0:a5f77652b3bb 82 #endif