960 |
jacho |
1 |
void mpl3115_setA (void) //nastavení pro výku |
|
|
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; |
|
|
79 |
unsigned int8 c; |
|
|
80 |
float l, a; |
|
|
81 |
|
|
|
82 |
m= mpl3115_read (0x01); |
|
|
83 |
c= mpl3115_read (0x02); |
|
|
84 |
l= (float)(mpl3115_read(0x03)>>4)/16.0; |
|
|
85 |
a = (float)((m << 8)|c) + l; |
|
|
86 |
return a; |
|
|
87 |
} |
|
|
88 |
|
|
|
89 |
|
|
|
90 |
float mpl3115_P (void) //tlak v Pa |
|
|
91 |
{ |
|
|
92 |
unsigned int32 m; |
|
|
93 |
unsigned int16 c; |
|
|
94 |
unsigned int8 l,l2; |
|
|
95 |
float p, l1; |
|
|
96 |
|
|
|
97 |
m= mpl3115_read (0x01); |
|
|
98 |
c= mpl3115_read (0x02); |
|
|
99 |
l=mpl3115_read(0x03); |
|
|
100 |
l2=l<<2; |
|
|
101 |
l1= (float)(l>>6)/4.0; |
|
|
102 |
p = (float)((m << 10)|(c<<2)|(l>>6)) + l1; |
|
|
103 |
|
|
|
104 |
return p; |
|
|
105 |
} |