sht15.h File Reference
Support for SHT15 and SHT11 digital humidity sensors.
More...
Go to the source code of this file.
Detailed Description
Include the following in your config.h:
- - - - - - - - - - - sht15 defines
- - - - - - - - - - -
define sht15_sck_port PORTA define sht15_sck_pin 1 define sht15_sda_port PORTA define sht15_sda_pin 0
Function Documentation
uns16 sht15_fix_humidity |
( |
uns16 |
sensor_out |
) |
|
00328 {
00329
00330 long result;
00331
00332 if ( sensor_out <= 1712 ) {
00333 result = 143 * sensor_out;
00334 result = result - 8192;
00335
00336
00337 } else {
00338 result = 111 *sensor_out + 46288;
00339
00340
00341 }
00342
00343 result = result / 4096;
00344 return result;
00345 }
uns16 sht15_fix_humidity_l |
( |
uns8 |
sensor_out |
) |
|
00348 {
00349
00350 uns16 result;
00351
00352 if ( sensor_out <= 107 ) {
00353 result = 143 * sensor_out;
00354 if (result < 512) { result = 512; }
00355 result -= 512;
00356 } else {
00357 result = 111 * sensor_out;
00358 result += 2893;
00359 if (result > 25600) { result = 25600; }
00360 }
00361
00362 result = result >> 8;
00363 return result;
00364 }
uns16 sht15_fix_humidity_r |
( |
uns16 |
sensor_out |
) |
|
00305 {
00306
00307 int32 c1 = -40000000;
00308 int32 c2 = 405000;
00309 int32 c3 = 28;
00310 int32 s;
00311 int32 final;
00312
00313
00314 s = sensor_out;
00315
00316 s = s * 10000000;
00317
00318 final = c1 + c2 * s + c3 * s * s;
00319
00320 final = final / 10000;
00321
00322 return final;
00323 }
int16 sht15_fix_temperature_h |
( |
uns16 |
sensor_out |
) |
|
00367 {
00368 int16 result;
00369
00370
00371 result = -4001 + sensor_out;
00372 return result;
00373 }
uns16 sht15_read_byte16 |
( |
void |
|
) |
|
00217 {
00218 uns8 j;
00219 uns16 in_byte;
00220 uns8 crc;
00221
00222
00223
00224 clear_pin(sht15_sck_port, sht15_sck_pin);
00225
00226 sht15_read_sda();
00227
00228 for(j = 0 ; j < 8 ; j++)
00229 {
00230 set_pin(sht15_sck_port, sht15_sck_pin);
00231 delay_us(10);
00232 in_byte = in_byte << 1;
00233 in_byte.0 = test_pin(sht15_sda_port, sht15_sda_pin);
00234
00235 clear_pin(sht15_sck_port, sht15_sck_pin);
00236 delay_us(10);
00237 }
00238 delay_us(100);
00239
00240
00241 sht15_write_sda();
00242 clear_pin(sht15_sda_port, sht15_sda_pin);
00243
00244 set_pin(sht15_sck_port, sht15_sck_pin);
00245 delay_us(10);
00246 clear_pin(sht15_sck_port, sht15_sck_pin);
00247 delay_us(10);
00248
00249 sht15_read_sda();
00250 delay_us(100);
00251
00252
00253 for(j = 0 ; j < 8 ; j++)
00254 {
00255 set_pin(sht15_sck_port, sht15_sck_pin);
00256 delay_us(10);
00257 in_byte = in_byte << 1;
00258 in_byte.0 = test_pin(sht15_sda_port, sht15_sda_pin);
00259
00260 clear_pin(sht15_sck_port, sht15_sck_pin);
00261 delay_us(10);
00262 }
00263
00264
00265 sht15_write_sda();
00266 clear_pin(sht15_sda_port, sht15_sda_pin);
00267
00268 set_pin(sht15_sck_port, sht15_sck_pin);
00269 delay_us(10);
00270 clear_pin(sht15_sck_port, sht15_sck_pin);
00271 delay_us(10);
00272
00273 sht15_read_sda();
00274 delay_us(100);
00275
00276
00277 for(j = 0 ; j < 8 ; j++)
00278 {
00279 set_pin(sht15_sck_port, sht15_sck_pin);
00280 delay_us(10);
00281 crc = crc << 1;
00282 crc.0 = test_pin(sht15_sda_port, sht15_sda_pin);
00283
00284 clear_pin(sht15_sck_port, sht15_sck_pin);
00285 delay_us(10);
00286 }
00287
00288
00289 sht15_write_sda();
00290 clear_pin(sht15_sda_port, sht15_sda_pin);
00291
00292 set_pin(sht15_sck_port, sht15_sck_pin);
00293 delay_us(10);
00294 clear_pin(sht15_sck_port, sht15_sck_pin);
00295 delay_us(10);
00296
00297 sht15_read_sda();
00298 delay_us(100);
00299
00300
00301 return(in_byte);
00302 }
uns16 sht15_read_humidity |
( |
void |
|
) |
|
uns16 sht15_read_temperature |
( |
void |
|
) |
|
void sht15_send_byte |
( |
uns8 |
sht15_command |
) |
|
00119 {
00120 uns8 i;
00121
00122
00123 sht15_write_sda();
00124
00125
00126 clear_pin(sht15_sck_port, sht15_sck_pin);
00127 for(i = 0 ; i < 8 ; i++)
00128 {
00129 delay_us(10);
00130 change_pin(sht15_sda_port, sht15_sda_pin, sht15_command.7);
00131 sht15_command = sht15_command << 1;
00132 delay_us(10);
00133 set_pin(sht15_sck_port, sht15_sck_pin);
00134 delay_us(10);
00135 clear_pin(sht15_sck_port, sht15_sck_pin);
00136 }
00137 delay_us(100);
00138
00139
00140 sht15_read_sda();
00141
00142
00143
00144 set_pin(sht15_sck_port, sht15_sck_pin);
00145
00146
00147 delay_us(10);
00148 clear_pin(sht15_sck_port, sht15_sck_pin);
00149
00150 while (test_pin(sht15_sda_port, sht15_sda_pin) == 0);
00151
00152
00153
00154 i = 0;
00155 while ((test_pin(sht15_sda_port, sht15_sda_pin) == 1))
00156 {
00157 i++;
00158 if (i == 255) break;
00159
00160 delay_ms(10);
00161 }
00162
00163
00164 i *= 10;
00165 serial_print_str("\nRt=");
00166 serial_print_int(i);
00167 serial_print_str("ms\n");
00168
00169 }
void sht15_setup_io |
( |
void |
|
) |
|
00052 {
00053 clear_pin(sht15_sck_port, sht15_sck_pin);
00054 clear_pin(sht15_sda_pin, sht15_sda_pin);
00055 make_output(sht15_sda_port, sht15_sda_pin);
00056 make_output(sht15_sck_port, sht15_sck_pin);
00057 }
void sht15_start |
( |
void |
|
) |
|
00173 {
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 sht15_write_sda();
00185
00186
00187
00188 clear_pin(sht15_sck_port, sht15_sck_pin);
00189 set_pin(sht15_sda_port, sht15_sda_pin);
00190 delay_us(10);
00191
00192 set_pin(sht15_sck_port, sht15_sck_pin);
00193 delay_us(10);
00194
00195
00196 clear_pin(sht15_sda_port, sht15_sda_pin);
00197 delay_us(10);
00198
00199
00200 clear_pin(sht15_sck_port, sht15_sck_pin);
00201 delay_us(10);
00202 set_pin(sht15_sck_port, sht15_sck_pin);
00203 delay_us(10);
00204
00205
00206 set_pin(sht15_sda_port, sht15_sda_pin);
00207 delay_us(10);
00208
00209
00210 clear_pin(sht15_sck_port, sht15_sck_pin);
00211 delay_us(10);
00212
00213 }