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