Test for MS5803 and MS5837 pressure sensors (pressure and temp readings) and QEI testing for encoder.

Dependencies:   MS5803 QEI mbed

Committer:
alex93
Date:
Sun Mar 20 03:05:25 2016 +0000
Revision:
0:f8bc804eadbc
Test for MS5803 and MS5837 pressure sensors (pressure and temp readings) and QEI testing for encoder.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alex93 0:f8bc804eadbc 1 #include "mbed.h"
alex93 0:f8bc804eadbc 2
alex93 0:f8bc804eadbc 3 #ifndef MS5837_H
alex93 0:f8bc804eadbc 4 #define MS5837_H
alex93 0:f8bc804eadbc 5
alex93 0:f8bc804eadbc 6 #define MS5837_RX_DEPTH 3 //
alex93 0:f8bc804eadbc 7 #define MS5837_TX_DEPTH 2 //
alex93 0:f8bc804eadbc 8
alex93 0:f8bc804eadbc 9 // choose your connection here
alex93 0:f8bc804eadbc 10 #define ms5837_addr_no_CS 0x76 //0b1110110
alex93 0:f8bc804eadbc 11
alex93 0:f8bc804eadbc 12 #define ms5837_reset 0x1E // Sensor Reset
alex93 0:f8bc804eadbc 13
alex93 0:f8bc804eadbc 14 #define ms5837_convD1_256 0x40 // Convert D1 OSR 256
alex93 0:f8bc804eadbc 15 #define ms5837_convD1_512 0x42 // Convert D1 OSR 512
alex93 0:f8bc804eadbc 16 #define ms5837_convD1_1024 0x44 // Convert D1 OSR 1024
alex93 0:f8bc804eadbc 17 #define ms5837_convD1_2048 0x46 // Convert D1 OSR 2048
alex93 0:f8bc804eadbc 18 #define ms5837_convD1_4096 0x48 // Convert D1 OSR 4096
alex93 0:f8bc804eadbc 19 #define ms5837_convD1_8192 0x4A // Convert D1 OSR 8192
alex93 0:f8bc804eadbc 20
alex93 0:f8bc804eadbc 21 #define ms5837_convD1 ms5837_convD1_4096 // choose your sampling rate here
alex93 0:f8bc804eadbc 22
alex93 0:f8bc804eadbc 23 #define ms5837_convD2_256 0x50 // Convert D2 OSR 256
alex93 0:f8bc804eadbc 24 #define ms5837_convD2_512 0x52 // Convert D2 OSR 512
alex93 0:f8bc804eadbc 25 #define ms5837_convD2_1024 0x54 // Convert D2 OSR 1024
alex93 0:f8bc804eadbc 26 #define ms5837_convD2_2048 0x56 // Convert D2 OSR 2048
alex93 0:f8bc804eadbc 27 #define ms5837_convD2_4096 0x58 // Convert D2 OSR 4096
alex93 0:f8bc804eadbc 28 #define ms5837_convD2_8192 0x5A // Convert D2 OSR 8192
alex93 0:f8bc804eadbc 29
alex93 0:f8bc804eadbc 30 #define ms5837_convD2 ms5837_convD2_4096 // choose your sampling rate here
alex93 0:f8bc804eadbc 31
alex93 0:f8bc804eadbc 32 #define ms5837_ADCread 0x00 // read ADC command
alex93 0:f8bc804eadbc 33 #define ms5837_PROMread 0xA0 // read PROM command base address
alex93 0:f8bc804eadbc 34
alex93 0:f8bc804eadbc 35 class MS5837{
alex93 0:f8bc804eadbc 36 private:
alex93 0:f8bc804eadbc 37 int D1, D2, Temp, C[8];
alex93 0:f8bc804eadbc 38 float T_MS5837, P_MS5837;
alex93 0:f8bc804eadbc 39 /* Data buffers */
alex93 0:f8bc804eadbc 40 char ms5837_rx_data[MS5837_RX_DEPTH];
alex93 0:f8bc804eadbc 41 char ms5837_tx_data[MS5837_TX_DEPTH];
alex93 0:f8bc804eadbc 42
alex93 0:f8bc804eadbc 43 public:
alex93 0:f8bc804eadbc 44 MS5837 (PinName sda, PinName scl,
alex93 0:f8bc804eadbc 45 char ms5837_addr = ms5837_addr_no_CS )
alex93 0:f8bc804eadbc 46 : i2c( sda, scl ), device_address( ms5837_addr << 1 ) {
alex93 0:f8bc804eadbc 47 }
alex93 0:f8bc804eadbc 48 void MS5837Init(void);
alex93 0:f8bc804eadbc 49 void MS5837Reset(void);
alex93 0:f8bc804eadbc 50 void MS5837ReadProm(void);
alex93 0:f8bc804eadbc 51 void MS5837ConvertD1(void);
alex93 0:f8bc804eadbc 52 void MS5837ConvertD2(void);
alex93 0:f8bc804eadbc 53 int32_t MS5837ReadADC(void);
alex93 0:f8bc804eadbc 54 float MS5837_Pressure (void);
alex93 0:f8bc804eadbc 55 float MS5837_Temperature (void);
alex93 0:f8bc804eadbc 56 void Barometer_MS5837(void);
alex93 0:f8bc804eadbc 57
alex93 0:f8bc804eadbc 58
alex93 0:f8bc804eadbc 59 private:
alex93 0:f8bc804eadbc 60 I2C i2c;
alex93 0:f8bc804eadbc 61 char device_address;
alex93 0:f8bc804eadbc 62
alex93 0:f8bc804eadbc 63 };
alex93 0:f8bc804eadbc 64 #endif