1 |
void SHT25_soft_reset() |
1 |
void SHT25_soft_reset() |
2 |
{ |
2 |
{ |
3 |
i2c_start(); // Start condition |
3 |
i2c_start(); // Start condition |
4 |
i2c_write(0x80); // Device address |
4 |
i2c_write(0x80); // Device address |
5 |
i2c_write(0xFE); // Device command |
5 |
i2c_write(0xFE); // Device command |
6 |
i2c_stop(); // Stop condition |
6 |
i2c_stop(); // Stop condition |
7 |
} |
7 |
} |
8 |
|
8 |
|
9 |
unsigned int8 SHT25_setup(unsigned int8 setup_reg ) // writes to status register and returns its value |
9 |
unsigned int8 SHT25_setup(unsigned int8 setup_reg ) // writes to status register and returns its value |
10 |
{ |
10 |
{ |
11 |
unsigned int8 reg; |
11 |
unsigned int8 reg; |
12 |
|
12 |
|
13 |
i2c_start(); // Start condition |
13 |
i2c_start(); // Start condition |
14 |
i2c_write(SHT25_ADDR); // Device address |
14 |
i2c_write(SHT25_ADDR); // Device address |
15 |
i2c_write(0xE7); // Device command |
15 |
i2c_write(0xE7); // Device command |
16 |
|
16 |
|
17 |
i2c_start(); // Start condition |
17 |
i2c_start(); // Start condition |
18 |
i2c_write(SHT25_ADDR+1); // Device address |
18 |
i2c_write(SHT25_ADDR+1); // Device address |
19 |
reg=i2c_read(0); // Read status actual status register |
19 |
reg=i2c_read(0); // Read status actual status register |
20 |
|
20 |
|
21 |
reg = (reg & 0x3A) | setup_reg; |
21 |
reg = (reg & 0x3A) | setup_reg; |
22 |
|
22 |
|
23 |
i2c_start(); // Start condition |
23 |
i2c_start(); // Start condition |
24 |
i2c_write(SHT25_ADDR); // Device address |
24 |
i2c_write(SHT25_ADDR); // Device address |
25 |
i2c_write(0xE6); // Write to status register |
25 |
i2c_write(0xE6); // Write to status register |
26 |
i2c_write(reg); // Device command |
26 |
i2c_write(reg); // Device command |
27 |
i2c_stop(); // Stop condition |
27 |
i2c_stop(); // Stop condition |
28 |
|
28 |
|
29 |
delay_ms(10); |
29 |
delay_ms(10); |
30 |
|
30 |
|
31 |
i2c_start(); // Start condition |
31 |
i2c_start(); // Start condition |
32 |
i2c_write(SHT25_ADDR); // Device address |
32 |
i2c_write(SHT25_ADDR); // Device address |
33 |
i2c_write(0xE7); // Device command |
33 |
i2c_write(0xE7); // Device command |
34 |
|
34 |
|
35 |
i2c_start(); // Start condition |
35 |
i2c_start(); // Start condition |
36 |
i2c_write(SHT25_ADDR+1); // Device address |
36 |
i2c_write(SHT25_ADDR+1); // Device address |
37 |
reg=i2c_read(0); // Read status actual status register |
37 |
reg=i2c_read(0); // Read status actual status register |
38 |
|
38 |
|
39 |
return (reg); |
39 |
return (reg); |
40 |
} |
40 |
} |
41 |
|
41 |
|
42 |
|
42 |
|
43 |
float SHT25_get_temp() |
43 |
float SHT25_get_temp() |
44 |
{ |
44 |
{ |
45 |
unsigned int8 MSB, LSB, Check; |
45 |
unsigned int8 MSB, LSB, Check; |
46 |
unsigned int16 data; |
46 |
unsigned int16 data; |
47 |
|
47 |
|
48 |
i2c_start(); |
48 |
i2c_start(); |
49 |
i2c_write(SHT25_ADDR); |
49 |
i2c_write(SHT25_ADDR); |
50 |
i2c_write(0xE3); |
50 |
i2c_write(0xE3); |
51 |
i2c_stop(); |
51 |
i2c_stop(); |
52 |
|
52 |
|
53 |
delay_ms(100); |
53 |
delay_ms(100); |
54 |
|
54 |
|
55 |
i2c_start(); |
55 |
i2c_start(); |
56 |
i2c_write(SHT25_ADDR+1); |
56 |
i2c_write(SHT25_ADDR+1); |
57 |
MSB=i2c_read(1); |
57 |
MSB=i2c_read(1); |
58 |
LSB=i2c_read(1); |
58 |
LSB=i2c_read(1); |
59 |
Check=i2c_read(0); |
59 |
Check=i2c_read(0); |
60 |
i2c_stop(); |
60 |
i2c_stop(); |
61 |
|
61 |
|
62 |
LSB = LSB >> 2; // trow out status bits |
62 |
LSB = LSB & 0xFC ; // trow out status bits |
63 |
|
63 |
|
64 |
data = (((unsigned int16) MSB << 8) + (LSB << 4)); |
64 |
data = make16(MSB,LSB); |
65 |
return(-46.85 + 175.72*((float)data/0xFFFF)); |
65 |
return(-46.85 + 175.72*((float)data/0xFFFF)); |
66 |
} |
66 |
} |
67 |
|
67 |
|
68 |
float SHT25_get_hum() |
68 |
float SHT25_get_hum() |
69 |
{ |
69 |
{ |
70 |
unsigned int8 MSB, LSB, Check; |
70 |
unsigned int8 MSB, LSB, Check; |
71 |
unsigned int16 data; |
71 |
unsigned int16 data; |
72 |
|
72 |
|
73 |
i2c_start(); //RH |
73 |
i2c_start(); //RH |
74 |
i2c_write(SHT25_ADDR); |
74 |
i2c_write(SHT25_ADDR); |
75 |
i2c_write(0xE5); |
75 |
i2c_write(0xE5); |
76 |
|
76 |
|
77 |
delay_ms(100); |
77 |
delay_ms(100); |
78 |
|
78 |
|
79 |
i2c_start(); |
79 |
i2c_start(); |
80 |
i2c_write(SHT25_ADDR+1); |
80 |
i2c_write(SHT25_ADDR+1); |
81 |
MSB=i2c_read(1); |
81 |
MSB=i2c_read(1); |
82 |
LSB=i2c_read(1); |
82 |
LSB=i2c_read(1); |
83 |
Check=i2c_read(0); |
83 |
Check=i2c_read(0); |
84 |
i2c_stop(); |
84 |
i2c_stop(); |
85 |
|
85 |
|
86 |
LSB = LSB >> 2; // trow out status bits |
86 |
LSB = LSB & 0xFC ; // trow out status bits |
87 |
|
87 |
|
88 |
data = (((unsigned int16) MSB << 8) + (LSB << 4) ); |
88 |
data = make16(MSB,LSB); |
89 |
return( -6.0 + 125.0*((float)data/0xFFFF)); |
89 |
return( -6.0 + 125.0*((float)data/0xFFFF)); |
90 |
} |
90 |
} |
91 |
|
91 |
|