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