Line 1... |
Line -... |
1 |
#include "main.h" |
- |
|
2 |
|
- |
|
3 |
void SHT25_soft_reset() |
- |
|
4 |
{ |
1 |
/* |
5 |
i2c_start(); // Start condition |
- |
|
6 |
i2c_write(0x80); // Device address |
- |
|
7 |
i2c_write(0xFE); // Device command |
- |
|
8 |
i2c_stop(); // Stop condition |
- |
|
9 |
} |
- |
|
10 |
|
- |
|
11 |
#define SHT25_HEATER_ON 0x04 |
- |
|
12 |
#define SHT25_HEATER_OFF 0x00 |
- |
|
13 |
#define SHT25_OTP_reload_off 0x02 |
- |
|
14 |
#define SHT25_RH12_T14 0x00 |
- |
|
15 |
#define SHT25_RH8_T12 0x01 |
- |
|
16 |
#define SHT25_RH10_T13 0x80 |
- |
|
17 |
#define SHT25_RH11_T11 0x81 |
- |
|
18 |
|
- |
|
19 |
#define SHT25_ADDR 0x80 |
- |
|
20 |
|
- |
|
21 |
unsigned int8 SHT25_setup(unsigned int8 setup_reg ) // writes to status register and returns its value |
- |
|
22 |
{ |
- |
|
23 |
unsigned int8 reg; |
- |
|
24 |
|
- |
|
25 |
i2c_start(); // Start condition |
- |
|
26 |
i2c_write(SHT25_ADDR); // Device address |
- |
|
27 |
i2c_write(0xE7); // Device command |
- |
|
28 |
|
- |
|
29 |
i2c_start(); // Start condition |
- |
|
30 |
i2c_write(SHT25_ADDR+1); // Device address |
- |
|
31 |
reg=i2c_read(0); // Read status actual status register |
- |
|
32 |
|
- |
|
33 |
reg = (reg & 0x3A) | setup_reg; |
2 |
SHT25 sensor demo firmware |
34 |
|
- |
|
35 |
i2c_start(); // Start condition |
- |
|
36 |
i2c_write(SHT25_ADDR); // Device address |
- |
|
37 |
i2c_write(0xE7); // Write to status register |
- |
|
38 |
i2c_write(reg); // Device command |
- |
|
39 |
i2c_stop(); // Stop condition |
- |
|
40 |
|
- |
|
41 |
return (reg); |
- |
|
42 |
} |
- |
|
43 |
|
- |
|
44 |
|
- |
|
45 |
float SHT25_get_temp() |
- |
|
46 |
{ |
- |
|
47 |
unsigned int8 MSB, LSB, Check; |
- |
|
48 |
unsigned int16 data; |
- |
|
49 |
|
- |
|
50 |
i2c_start(); |
- |
|
51 |
I2C_Write(SHT25_ADDR); |
- |
|
52 |
I2C_write(0xE3); |
- |
|
53 |
i2c_stop(); |
- |
|
54 |
|
3 |
*/ |
55 |
delay_ms(100); |
- |
|
56 |
|
- |
|
57 |
i2c_start(); |
- |
|
58 |
I2C_Write(SHT25_ADDR+1); |
- |
|
59 |
MSB=i2c_read(1); |
- |
|
60 |
LSB=i2c_read(1); |
- |
|
61 |
Check=i2c_read(0); |
- |
|
62 |
i2c_stop(); |
- |
|
63 |
|
- |
|
64 |
LSB = LSB >> 2; // trow out status bits |
- |
|
65 |
|
- |
|
66 |
data = (((unsigned int16) MSB << 8) + (LSB << 4)); |
- |
|
67 |
return(-46.85 + 175.72*((float)data/0xFFFF)); |
- |
|
68 |
} |
- |
|
69 |
|
- |
|
70 |
float SHT25_get_hum() |
- |
|
71 |
{ |
- |
|
72 |
unsigned int8 MSB, LSB, Check; |
- |
|
73 |
unsigned int16 data; |
- |
|
74 |
|
- |
|
75 |
i2c_start(); //RH |
- |
|
76 |
I2C_Write(SHT25_ADDR); |
- |
|
77 |
I2C_write(0xE5); |
- |
|
78 |
// i2c_stop(); |
- |
|
79 |
|
- |
|
80 |
delay_ms(100); |
- |
|
81 |
|
- |
|
82 |
i2c_start(); |
- |
|
83 |
I2C_Write(SHT25_ADDR+1); |
- |
|
84 |
MSB=i2c_read(1); |
- |
|
85 |
LSB=i2c_read(1); |
- |
|
86 |
Check=i2c_read(0); |
- |
|
87 |
i2c_stop(); |
- |
|
88 |
|
- |
|
89 |
// printf("%X %X %X\r\n",MSB, LSB, Check); |
- |
|
90 |
|
- |
|
91 |
LSB = LSB >> 2; // trow out status bits |
- |
|
92 |
|
- |
|
93 |
data = (((unsigned int16) MSB << 8) + (LSB << 4) ); |
- |
|
94 |
return( -6.0 + 125.0*((float)data/0xFFFF)); |
- |
|
95 |
} |
- |
|
96 |
|
4 |
|
- |
|
5 |
#include "main.h" |
- |
|
6 |
#include "SHT25.h" |
97 |
|
7 |
|
98 |
void main() |
8 |
void main() |
99 |
{ |
9 |
{ |
100 |
unsigned int8 i=0; |
10 |
unsigned int8 i=0, sht_config; |
101 |
|
11 |
|
102 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
12 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
103 |
setup_adc(ADC_CLOCK_DIV_2); |
13 |
setup_adc(ADC_CLOCK_DIV_2); |
104 |
setup_spi(SPI_SS_DISABLED); |
14 |
setup_spi(SPI_SS_DISABLED); |
105 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
15 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
Line 112... |
Line 22... |
112 |
printf("SHT25 humidity and temperature sensor example \r\n",); |
22 |
printf("SHT25 humidity and temperature sensor example \r\n",); |
113 |
delay_ms (500); |
23 |
delay_ms (500); |
114 |
|
24 |
|
115 |
while(TRUE) |
25 |
while(TRUE) |
116 |
{ |
26 |
{ |
117 |
if (i<10) |
- |
|
118 |
printf("setup: %X \r\n",SHT25_setup(SHT25_RH12_T14 | SHT25_HEATER_OFF)); |
27 |
if (i<10) sht_config = SHT25_RH12_T14 | SHT25_HEATER_OFF; // loop alters on chip heater on and off to check correct function |
119 |
else |
28 |
else |
120 |
{ |
29 |
{ |
121 |
printf("setup: %X \r\n",SHT25_setup(SHT25_RH12_T14 | SHT25_HEATER_ON)); |
30 |
sht_config = SHT25_RH12_T14 | SHT25_HEATER_ON; |
122 |
i = 0; |
31 |
if (i > 20) i = 0; |
123 |
} |
32 |
} |
- |
|
33 |
printf("setup: %X %X \r\n",SHT25_setup(sht_config),sht_config); |
124 |
delay_ms (500); |
34 |
delay_ms (500); |
125 |
printf("Temp: %f \r\n",SHT25_get_temp()); |
35 |
printf("Temp: %f \r\n",SHT25_get_temp()); |
126 |
delay_ms (500); |
36 |
delay_ms (500); |
127 |
printf("Hum: %f \r\n",SHT25_get_hum()); |
37 |
printf("Hum: %f \r\n",SHT25_get_hum()); |
128 |
delay_ms (1000); |
38 |
delay_ms (1000); |