Rev Author Line No. Line
3288 kaklik 1 void mpl3115_setA (void) //setup for altitude measurement
2 {
3  
4  
5 i2c_start(); //STANDBY mode
6 I2C_Write(MPL3115_ADDR_W);
7 I2C_write(0x26);
8 I2C_write(0xB8);
9 i2c_stop();
10  
11 i2c_start(); //PT_DATA_CFG set
12 I2C_Write(MPL3115_ADDR_W);
13 I2C_write(0x13);
14 I2C_write(0x07); //hodnota
15 i2c_stop();
16  
17 i2c_start(); //ACTIVE mode
18 I2C_Write(MPL3115_ADDR_W);
19 I2C_write(0x26);
20 I2C_write(0xB9);
21 i2c_stop();
22 }
23  
24 void mpl3115_setP (void) //nastavení pro tlak
25 {
26  
27  
28 i2c_start(); //STANDBY mode
29 I2C_Write(MPL3115_ADDR_W);
30 I2C_write(0x26);
31 I2C_write(0xB8);
32 i2c_stop();
33  
34 i2c_start(); //PT_DATA_CFG set
35 I2C_Write(MPL3115_ADDR_W);
36 I2C_write(0x13);
37 I2C_write(0x07); //hodnota
38 i2c_stop();
39  
40 i2c_start(); //ACTIVE mode
41 I2C_Write(MPL3115_ADDR_W);
42 I2C_write(0x26);
43 I2C_write(0x39);
44 i2c_stop();
45 }
46  
47  
48 byte mpl3115_read (byte reg)
49 {
50 byte i;
51  
52 i2c_start();
53 I2C_Write(MPL3115_ADDR_W);
54 I2C_write(reg);
55 i2c_start();
56 I2C_Write(MPL3115_ADDR_R);
57 i=i2c_read(0);
58 i2c_stop();
59  
60 return i;
61 }
62  
63  
64 float mpl3115_T (void) //teplota ve stupnich
65 {
66 int m;
67 float l, t;
68  
69 m = mpl3115_read (0x04);
70 l = (float)(mpl3115_read(0x05)>>4)/16.0;
71 t = (float)(M + L);
72 return t;
73 }
74  
75 float mpl3115_A (void) //vyska v m
76 {
77  
78 int16 m, c;
79 float l, a;
80  
81 m = mpl3115_read (0x01);
82 c = mpl3115_read (0x02);
83 l = (float)(mpl3115_read(0x03)>>4)/16.0;
84 a = (float)((m << 8)|c) + l;
85 return a;
86 }
87  
88  
89 float mpl3115_P (void) //tlak v Pa
90 {
91 unsigned int32 m;
92 unsigned int16 c;
93 unsigned int l;
94 float p, l1;
95  
96 m = mpl3115_read (0x01);
97 c = mpl3115_read (0x02);
98 l = mpl3115_read(0x03);
99  
100 l1= (float)(l>>4)/4.0;
101 p = (float)((m << 10)|(c<<2)|(l>>6)) + l1;
102  
103 return p;
104 }
105