Rev Author Line No. Line
2773 kaklik 1 #ifndef MPL115A1_H
2 #define MPL115A1_H
3  
4 #include "mbed.h"
5  
6 /** barometric pressure and temperature sensor MPL115A1 control class, based on SPI
7 *
8 * Example:
9 * @code
10 * #include "mbed.h"
11 * #include "MPL115A1.h"
12 *
13 * SPI spi(p11,p12,p13);
14 * MPL115A1 bar(spi, p14);
15 *
16 * Serial pc(USBTX, USBRX);
17 *
18 * int main() {
19 * while(1) {
20 * wait(10);
21 * pc.printf("Pressure is %f\n", bar.readPressure());
22 * pc.printf("Temperature is %f\n", bar.readTemperature());
23 * }
24 * }
25 * @endcode
26 */
27  
28 // real addresses, in read_register: address |= 0x80
29 #define MPL115A1_PRESH 0x00 // 80
30 #define MPL115A1_PRESL 0x02 // 82
31 #define MPL115A1_TEMPH 0x04 // 84
32 #define MPL115A1_TEMPL 0x06 // 86
33  
34 #define MPL115A1_A0MSB 0x08 // 88
35 #define MPL115A1_A0LSB 0x0A // 8A
36 #define MPL115A1_B1MSB 0x0C // 8C
37 #define MPL115A1_B1LSB 0x0E // 8E
38 #define MPL115A1_B2MSB 0x10 // 90
39 #define MPL115A1_B2LSB 0x12 // 92
40 #define MPL115A1_C12MSB 0x14 // 94
41 #define MPL115A1_C12LSB 0x16 // 96
42 #define MPL115A1_C11MSB 0x18 // 98
43 #define MPL115A1_C11LSB 0x1A // 9A
44 #define MPL115A1_C22MSB 0x1C // 9C
45 #define MPL115A1_C22LSB 0x1E // 9E
46  
47 #define MPL115A1_STARTPRES 0x20 // start pressure measurement
48 #define MPL115A1_STARTTEMP 0x22 // start temperature measurement
49 #define MPL115A1_STARTBOTH 0x24 // start both simultaneously
50  
51 class MPL115A1 {
52 private:
53 SPI& _spi;
54 DigitalOut _cs; // chip select, active low
55 //DigitalOut sdn; // shutdown pin, high=on, low=off
56  
57 public:
58 /** Create a barometer object connected to the SPI bus and specified chip select pin
59 *
60 * @param spi SPI master object
61 * @param ncs chip select pin
62 */
63 MPL115A1(SPI& spi, PinName ncs);
64 /** start measurement, read registers, calculate and return pressure */
65 float readPressure();
66 /** start measurement, read registers, calculate and return temperature */
67 float readTemperature();
68  
69 private:
70 void write_register(uint8_t address, char data);
71 char read_register(uint8_t address);
72  
73 signed char sia0MSB, sia0LSB;
74 signed char sib1MSB, sib1LSB;
75 signed char sib2MSB, sib2LSB;
76 signed char sic12MSB, sic12LSB;
77 signed char sic11MSB, sic11LSB;
78 signed char sic22MSB, sic22LSB;
79 signed int sia0, sib1, sib2, sic12, sic11, sic22, siPcomp;
80 float decPcomp;
81 signed long lt1, lt2, lt3, si_c11x1, si_a11, si_c12x2;
82 signed long si_a1, si_c22x2, si_a2, si_a1x1, si_y1, si_a2x2;
83 unsigned int uiPadc, uiTadc;
84 unsigned char uiPH, uiPL, uiTH, uiTL;
85 };
86  
87 #endif