![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
first publish
Sensors/MS5837.h@2:359f1f075c72, 2017-06-04 (annotated)
- Committer:
- roger_wee
- Date:
- Sun Jun 04 06:46:28 2017 +0000
- Revision:
- 2:359f1f075c72
- Parent:
- MS5837.h@0:ce3ac53af6e4
9-dof implementation using madgwick's filter
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
roger_wee | 0:ce3ac53af6e4 | 1 | #include "mbed.h" |
roger_wee | 0:ce3ac53af6e4 | 2 | |
roger_wee | 0:ce3ac53af6e4 | 3 | #ifndef MS5837_H |
roger_wee | 0:ce3ac53af6e4 | 4 | #define MS5837_H |
roger_wee | 0:ce3ac53af6e4 | 5 | |
roger_wee | 0:ce3ac53af6e4 | 6 | #define MS5837_RX_DEPTH 3 // |
roger_wee | 0:ce3ac53af6e4 | 7 | #define MS5837_TX_DEPTH 2 // |
roger_wee | 0:ce3ac53af6e4 | 8 | |
roger_wee | 0:ce3ac53af6e4 | 9 | // choose your connection here |
roger_wee | 0:ce3ac53af6e4 | 10 | #define ms5837_addr_no_CS 0x76 //0b1110110 |
roger_wee | 0:ce3ac53af6e4 | 11 | |
roger_wee | 0:ce3ac53af6e4 | 12 | #define ms5837_reset 0x1E // Sensor Reset |
roger_wee | 0:ce3ac53af6e4 | 13 | |
roger_wee | 0:ce3ac53af6e4 | 14 | #define ms5837_convD1_256 0x40 // Convert D1 OSR 256 |
roger_wee | 0:ce3ac53af6e4 | 15 | #define ms5837_convD1_512 0x42 // Convert D1 OSR 512 |
roger_wee | 0:ce3ac53af6e4 | 16 | #define ms5837_convD1_1024 0x44 // Convert D1 OSR 1024 |
roger_wee | 0:ce3ac53af6e4 | 17 | #define ms5837_convD1_2048 0x46 // Convert D1 OSR 2048 |
roger_wee | 0:ce3ac53af6e4 | 18 | #define ms5837_convD1_4096 0x48 // Convert D1 OSR 4096 |
roger_wee | 0:ce3ac53af6e4 | 19 | #define ms5837_convD1_8192 0x4A // Convert D1 OSR 8192 |
roger_wee | 0:ce3ac53af6e4 | 20 | |
roger_wee | 0:ce3ac53af6e4 | 21 | #define ms5837_convD1 ms5837_convD1_4096 // choose your sampling rate here |
roger_wee | 0:ce3ac53af6e4 | 22 | |
roger_wee | 0:ce3ac53af6e4 | 23 | #define ms5837_convD2_256 0x50 // Convert D2 OSR 256 |
roger_wee | 0:ce3ac53af6e4 | 24 | #define ms5837_convD2_512 0x52 // Convert D2 OSR 512 |
roger_wee | 0:ce3ac53af6e4 | 25 | #define ms5837_convD2_1024 0x54 // Convert D2 OSR 1024 |
roger_wee | 0:ce3ac53af6e4 | 26 | #define ms5837_convD2_2048 0x56 // Convert D2 OSR 2048 |
roger_wee | 0:ce3ac53af6e4 | 27 | #define ms5837_convD2_4096 0x58 // Convert D2 OSR 4096 |
roger_wee | 0:ce3ac53af6e4 | 28 | #define ms5837_convD2_8192 0x5A // Convert D2 OSR 8192 |
roger_wee | 0:ce3ac53af6e4 | 29 | |
roger_wee | 0:ce3ac53af6e4 | 30 | #define ms5837_convD2 ms5837_convD2_4096 // choose your sampling rate here |
roger_wee | 0:ce3ac53af6e4 | 31 | |
roger_wee | 0:ce3ac53af6e4 | 32 | #define ms5837_ADCread 0x00 // read ADC command |
roger_wee | 0:ce3ac53af6e4 | 33 | #define ms5837_PROMread 0xA0 // read PROM command base address |
roger_wee | 0:ce3ac53af6e4 | 34 | |
roger_wee | 0:ce3ac53af6e4 | 35 | class MS5837{ |
roger_wee | 0:ce3ac53af6e4 | 36 | private: |
roger_wee | 0:ce3ac53af6e4 | 37 | int D1, D2, Temp, C[8]; |
roger_wee | 0:ce3ac53af6e4 | 38 | float T_MS5837, P_MS5837; |
roger_wee | 0:ce3ac53af6e4 | 39 | /* Data buffers */ |
roger_wee | 0:ce3ac53af6e4 | 40 | char ms5837_rx_data[MS5837_RX_DEPTH]; |
roger_wee | 0:ce3ac53af6e4 | 41 | char ms5837_tx_data[MS5837_TX_DEPTH]; |
roger_wee | 0:ce3ac53af6e4 | 42 | |
roger_wee | 0:ce3ac53af6e4 | 43 | public: |
roger_wee | 0:ce3ac53af6e4 | 44 | MS5837 (PinName sda, PinName scl, |
roger_wee | 0:ce3ac53af6e4 | 45 | char ms5837_addr = ms5837_addr_no_CS ) |
roger_wee | 0:ce3ac53af6e4 | 46 | : i2c( sda, scl ), device_address( ms5837_addr << 1 ) { |
roger_wee | 0:ce3ac53af6e4 | 47 | } |
roger_wee | 0:ce3ac53af6e4 | 48 | void MS5837Init(void); |
roger_wee | 0:ce3ac53af6e4 | 49 | void MS5837Reset(void); |
roger_wee | 0:ce3ac53af6e4 | 50 | void MS5837ReadProm(void); |
roger_wee | 0:ce3ac53af6e4 | 51 | void MS5837ConvertD1(void); |
roger_wee | 0:ce3ac53af6e4 | 52 | void MS5837ConvertD2(void); |
roger_wee | 0:ce3ac53af6e4 | 53 | int32_t MS5837ReadADC(void); |
roger_wee | 0:ce3ac53af6e4 | 54 | float MS5837_Pressure (void); |
roger_wee | 0:ce3ac53af6e4 | 55 | float MS5837_Temperature (void); |
roger_wee | 0:ce3ac53af6e4 | 56 | void Barometer_MS5837(void); |
roger_wee | 0:ce3ac53af6e4 | 57 | |
roger_wee | 0:ce3ac53af6e4 | 58 | |
roger_wee | 0:ce3ac53af6e4 | 59 | private: |
roger_wee | 0:ce3ac53af6e4 | 60 | I2C i2c; |
roger_wee | 0:ce3ac53af6e4 | 61 | char device_address; |
roger_wee | 0:ce3ac53af6e4 | 62 | |
roger_wee | 0:ce3ac53af6e4 | 63 | }; |
roger_wee | 0:ce3ac53af6e4 | 64 | #endif |