Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MS5837.h
00001 #include "mbed.h" 00002 00003 #ifndef MS5837_H 00004 #define MS5837_H 00005 00006 #define MS5837_RX_DEPTH 3 // 00007 #define MS5837_TX_DEPTH 2 // 00008 00009 // choose your connection here 00010 #define ms5837_addr_no_CS 0x76 //0b1110110 00011 00012 #define ms5837_reset 0x1E // Sensor Reset 00013 00014 #define ms5837_convD1_256 0x40 // Convert D1 OSR 256 00015 #define ms5837_convD1_512 0x42 // Convert D1 OSR 512 00016 #define ms5837_convD1_1024 0x44 // Convert D1 OSR 1024 00017 #define ms5837_convD1_2048 0x46 // Convert D1 OSR 2048 00018 #define ms5837_convD1_4096 0x48 // Convert D1 OSR 4096 00019 #define ms5837_convD1_8192 0x4A // Convert D1 OSR 8192 00020 00021 #define ms5837_convD1 ms5837_convD1_4096 // choose your sampling rate here 00022 00023 #define ms5837_convD2_256 0x50 // Convert D2 OSR 256 00024 #define ms5837_convD2_512 0x52 // Convert D2 OSR 512 00025 #define ms5837_convD2_1024 0x54 // Convert D2 OSR 1024 00026 #define ms5837_convD2_2048 0x56 // Convert D2 OSR 2048 00027 #define ms5837_convD2_4096 0x58 // Convert D2 OSR 4096 00028 #define ms5837_convD2_8192 0x5A // Convert D2 OSR 8192 00029 00030 #define ms5837_convD2 ms5837_convD2_4096 // choose your sampling rate here 00031 00032 #define ms5837_ADCread 0x00 // read ADC command 00033 #define ms5837_PROMread 0xA0 // read PROM command base address 00034 00035 //#define fluidDensity 1029 //kg/m^3 (seawater) 00036 #define fluidDensity 997 // kg/m^3 (freshwater) 00037 00038 class MS5837{ 00039 private: 00040 int D1, D2, Temp, C[8]; 00041 float T_MS5837, P_MS5837; 00042 /* Data buffers */ 00043 char ms5837_rx_data[MS5837_RX_DEPTH]; 00044 char ms5837_tx_data[MS5837_TX_DEPTH]; 00045 00046 public: 00047 MS5837 (PinName sda, PinName scl, 00048 char ms5837_addr = ms5837_addr_no_CS ) 00049 : i2c( sda, scl ), device_address( ms5837_addr << 1 ) { 00050 } 00051 void MS5837Init(void); 00052 void MS5837Reset(void); 00053 void MS5837ReadProm(void); 00054 void MS5837ConvertD1(void); 00055 void MS5837ConvertD2(void); 00056 int32_t MS5837ReadADC(void); 00057 float MS5837_Pressure (void); 00058 float MS5837_Temperature (void); 00059 void Barometer_MS5837(void); 00060 float depth(void); 00061 float altitude(void); 00062 00063 private: 00064 I2C i2c; 00065 char device_address; 00066 00067 }; 00068 #endif
Generated on Mon Sep 26 2022 18:48:51 by
1.7.2