Correction de la lib car erreur de format dans les calculs

Committer:
rkk
Date:
Thu Jul 24 04:47:54 2014 +0000
Revision:
1:a1f3bd291a0c
Parent:
0:d558dda1e821
Child:
2:3e5c7afef8f8
adjusted library to make it more universal;

Who changed what in which revision?

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