LibDriver HDC302X
Loading...
Searching...
No Matches
driver_hdc302x.c
Go to the documentation of this file.
1
36
37#include "driver_hdc302x.h"
38
42#define CHIP_NAME "Texas Instruments HDC302X"
43#define MANUFACTURER_NAME "Texas Instruments"
44#define SUPPLY_VOLTAGE_MIN 1.62f
45#define SUPPLY_VOLTAGE_MAX 5.5f
46#define MAX_CURRENT 0.17f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 125.0f
49#define DRIVER_VERSION 1000
50
54#define HDC302X_COMMAND_SINGLE_MEASUREMENT_LPM0 0x2400U
55#define HDC302X_COMMAND_SINGLE_MEASUREMENT_LPM1 0x240BU
56#define HDC302X_COMMAND_SINGLE_MEASUREMENT_LPM2 0x2416U
57#define HDC302X_COMMAND_SINGLE_MEASUREMENT_LPM3 0x24FFU
58#define HDC302X_COMMAND_AUTO_MEASUREMENT_0P5_SECOND_LPM0 0x2032U
59#define HDC302X_COMMAND_AUTO_MEASUREMENT_0P5_SECOND_LPM1 0x2024U
60#define HDC302X_COMMAND_AUTO_MEASUREMENT_0P5_SECOND_LPM2 0x202FU
61#define HDC302X_COMMAND_AUTO_MEASUREMENT_0P5_SECOND_LPM3 0x20FFU
62#define HDC302X_COMMAND_AUTO_MEASUREMENT_1_SECOND_LPM0 0x2130U
63#define HDC302X_COMMAND_AUTO_MEASUREMENT_1_SECOND_LPM1 0x2126U
64#define HDC302X_COMMAND_AUTO_MEASUREMENT_1_SECOND_LPM2 0x212DU
65#define HDC302X_COMMAND_AUTO_MEASUREMENT_1_SECOND_LPM3 0x21FFU
66#define HDC302X_COMMAND_AUTO_MEASUREMENT_2_SECOND_LPM0 0x2236U
67#define HDC302X_COMMAND_AUTO_MEASUREMENT_2_SECOND_LPM1 0x2220U
68#define HDC302X_COMMAND_AUTO_MEASUREMENT_2_SECOND_LPM2 0x222BU
69#define HDC302X_COMMAND_AUTO_MEASUREMENT_2_SECOND_LPM3 0x22FFU
70#define HDC302X_COMMAND_AUTO_MEASUREMENT_4_SECOND_LPM0 0x2334U
71#define HDC302X_COMMAND_AUTO_MEASUREMENT_4_SECOND_LPM1 0x2322U
72#define HDC302X_COMMAND_AUTO_MEASUREMENT_4_SECOND_LPM2 0x2329U
73#define HDC302X_COMMAND_AUTO_MEASUREMENT_4_SECOND_LPM3 0x23FFU
74#define HDC302X_COMMAND_AUTO_MEASUREMENT_10_SECOND_LPM0 0x2737U
75#define HDC302X_COMMAND_AUTO_MEASUREMENT_10_SECOND_LPM1 0x2721U
76#define HDC302X_COMMAND_AUTO_MEASUREMENT_10_SECOND_LPM2 0x272AU
77#define HDC302X_COMMAND_AUTO_MEASUREMENT_10_SECOND_LPM3 0x27FFU
78#define HDC302X_COMMAND_EXIT 0x3093U
79#define HDC302X_COMMAND_AUTO_MEASUREMENT_READ_T_RH 0xE000U
80#define HDC302X_COMMAND_AUTO_MEASUREMENT_READ_RH 0xE001U
81#define HDC302X_COMMAND_AUTO_MEASUREMENT_READ_MIN_T 0xE002U
82#define HDC302X_COMMAND_AUTO_MEASUREMENT_READ_MAX_T 0xE003U
83#define HDC302X_COMMAND_AUTO_MEASUREMENT_READ_MIN_RH 0xE004U
84#define HDC302X_COMMAND_AUTO_MEASUREMENT_READ_MAX_RH 0xE005U
85#define HDC302X_COMMAND_WRITE_SET_LOW_ALERT 0x6100U
86#define HDC302X_COMMAND_WRITE_SET_HIGH_ALERT 0x611DU
87#define HDC302X_COMMAND_WRITE_CLEAR_LOW_ALERT 0x610BU
88#define HDC302X_COMMAND_WRITE_CLEAR_HIGH_ALERT 0x6116U
89#define HDC302X_COMMAND_READ_SET_LOW_ALERT 0xE102U
90#define HDC302X_COMMAND_READ_SET_HIGH_ALERT 0xE11FU
91#define HDC302X_COMMAND_READ_CLEAR_LOW_ALERT 0xE109U
92#define HDC302X_COMMAND_READ_CLEAR_HIGH_ALERT 0xE114U
93#define HDC302X_COMMAND_HEATER_ENABLE 0x306DU
94#define HDC302X_COMMAND_HEATER_DISABLE 0x3066U
95#define HDC302X_COMMAND_HEATER_CONFIG 0x306EU
96#define HDC302X_COMMAND_READ_STATUS 0xF32DU
97#define HDC302X_COMMAND_CLEAR_STATUS 0x3041U
98#define HDC302X_COMMAND_SOFT_RESET 0x30A2U
99#define HDC302X_COMMAND_READ_NIST_ID_BYTE5_BYTE4 0x3683U
100#define HDC302X_COMMAND_READ_NIST_ID_BYTE3_BYTE2 0x3684U
101#define HDC302X_COMMAND_READ_NIST_ID_BYTE1_BYTE0 0x3685U
102#define HDC302X_COMMAND_READ_ID 0x3781U
103#define HDC302X_COMMAND_PROGRAM_ALERT_THRESHOLD 0x6155U
104#define HDC302X_COMMAND_PROGRAM_READ_OFFSET 0xA004U
105#define HDC302X_COMMAND_PROGRAM_READ_EEPROM_CONFIG 0x61BBU
106
118static uint8_t a_hdc302x_iic_read(hdc302x_handle_t *handle, uint16_t command, uint8_t *buf, uint16_t len)
119{
120 if (handle->iic_read_address16(handle->iic_addr, command, (uint8_t *)buf, len) != 0) /* read data */
121 {
122 return 1; /* return error */
123 }
124
125 return 0; /* success return 0 */
126}
127
139static uint8_t a_hdc302x_iic_write(hdc302x_handle_t *handle, uint16_t command, uint8_t *buf, uint16_t len)
140{
141 if (handle->iic_write_address16(handle->iic_addr, command, (uint8_t *)buf, len) != 0) /* write data */
142 {
143 return 1; /* return error */
144 }
145
146 return 0; /* success return 0 */
147}
148
156static uint8_t a_hdc302x_crc(uint8_t *data, uint16_t len)
157{
158 const uint8_t POLYNOMIAL = 0x31;
159 uint8_t crc = 0xFF;
160 uint16_t i;
161 uint16_t j;
162
163 for (j = len; j != 0; --j) /* length-- */
164 {
165 crc ^= *data++; /* xor */
166 for (i = 8; i != 0; --i) /* 8 times */
167 {
168 crc = (crc & 0x80) ? (crc << 1) ^ POLYNOMIAL : (crc<<1); /* calculate crc */
169 }
170 }
171
172 return crc; /* return crc */
173}
174
186{
187 if (handle == NULL) /* check handle */
188 {
189 return 2; /* return error */
190 }
191 if (handle->inited != 1) /* check handle initialization */
192 {
193 return 3; /* return error */
194 }
195
196 handle->low_power_mode = (uint8_t)mode; /* set low power mode */
197
198 return 0; /* success return 0 */
199}
200
212{
213 if (handle == NULL) /* check handle */
214 {
215 return 2; /* return error */
216 }
217 if (handle->inited != 1) /* check handle initialization */
218 {
219 return 3; /* return error */
220 }
221
222 *mode = (hdc302x_low_power_mode_t)(handle->low_power_mode); /* set low power mode */
223
224 return 0; /* success return 0 */
225}
226
238{
239 if (handle == NULL) /* check handle */
240 {
241 return 2; /* return error */
242 }
243 if (handle->inited != 1) /* check handle initialization */
244 {
245 return 3; /* return error */
246 }
247
248 handle->auto_mode = (uint8_t)mode; /* set auto mode */
249
250 return 0; /* success return 0 */
251}
252
264{
265 if (handle == NULL) /* check handle */
266 {
267 return 2; /* return error */
268 }
269 if (handle->inited != 1) /* check handle initialization */
270 {
271 return 3; /* return error */
272 }
273
274 *mode = (hdc302x_auto_mode_t)(handle->auto_mode); /* set auto mode */
275
276 return 0; /* success return 0 */
277}
278
290{
291 uint8_t res;
292
293 if (handle == NULL) /* check handle */
294 {
295 return 2; /* return error */
296 }
297 if (handle->inited != 1) /* check handle initialization */
298 {
299 return 3; /* return error */
300 }
301
302 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_SOFT_RESET, NULL, 0); /* soft reset */
303 if (res != 0) /* check result */
304 {
305 handle->debug_print("hdc302x: soft reset failed.\n"); /* soft reset failed */
306
307 return 1; /* return error */
308 }
309 handle->delay_ms(5); /* delay 5ms */
310
311 return 0; /* success return 0 */
312}
313
327{
328 uint8_t res;
329
330 if (handle == NULL) /* check handle */
331 {
332 return 2; /* return error */
333 }
334 if (handle->inited != 1) /* check handle initialization */
335 {
336 return 3; /* return error */
337 }
338
339 if (handle->auto_mode == (uint8_t)HDC302X_AUTO_MODE_0P5_HZ) /* 0.5 hz */
340 {
341 if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_0) /* 12.5 ms */
342 {
343 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_0P5_SECOND_LPM0, NULL, 0); /* write command */
344 if (res != 0) /* check result */
345 {
346 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
347
348 return 1; /* return error */
349 }
350 }
351 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_1) /* 7.5 ms */
352 {
353 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_0P5_SECOND_LPM1, NULL, 0); /* write command */
354 if (res != 0) /* check result */
355 {
356 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
357
358 return 1; /* return error */
359 }
360 }
361 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_2) /* 5.0 ms */
362 {
363 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_0P5_SECOND_LPM2, NULL, 0); /* write command */
364 if (res != 0) /* check result */
365 {
366 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
367
368 return 1; /* return error */
369 }
370 }
371 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_3) /* 3.7 ms */
372 {
373 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_0P5_SECOND_LPM3, NULL, 0); /* write command */
374 if (res != 0) /* check result */
375 {
376 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
377
378 return 1; /* return error */
379 }
380 }
381 else /* invalid mode */
382 {
383 handle->debug_print("hdc302x: low power mode is invalid.\n"); /* low power mode is invalid */
384
385 return 4; /* return error */
386 }
387 handle->mode = 1; /* set continuous mode */
388
389 return 0; /* success return 0 */
390 }
391 else if (handle->auto_mode == (uint8_t)HDC302X_AUTO_MODE_1_HZ) /* 1 hz */
392 {
393 if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_0) /* 12.5 ms */
394 {
395 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_1_SECOND_LPM0, NULL, 0); /* write command */
396 if (res != 0) /* check result */
397 {
398 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
399
400 return 1; /* return error */
401 }
402 }
403 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_1) /* 7.5 ms */
404 {
405 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_1_SECOND_LPM1, NULL, 0); /* write command */
406 if (res != 0) /* check result */
407 {
408 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
409
410 return 1; /* return error */
411 }
412 }
413 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_2) /* 5.0 ms */
414 {
415 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_1_SECOND_LPM2, NULL, 0); /* write command */
416 if (res != 0) /* check result */
417 {
418 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
419
420 return 1; /* return error */
421 }
422 }
423 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_3) /* 3.7 ms */
424 {
425 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_1_SECOND_LPM3, NULL, 0); /* write command */
426 if (res != 0) /* check result */
427 {
428 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
429
430 return 1; /* return error */
431 }
432 }
433 else /* invalid mode */
434 {
435 handle->debug_print("hdc302x: low power mode is invalid.\n"); /* low power mode is invalid */
436
437 return 4; /* return error */
438 }
439 handle->mode = 1; /* set continuous mode */
440
441 return 0; /* success return 0 */
442 }
443 else if (handle->auto_mode == (uint8_t)HDC302X_AUTO_MODE_2_HZ) /* 2 hz */
444 {
445 if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_0) /* 12.5 ms */
446 {
447 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_2_SECOND_LPM0, NULL, 0); /* write command */
448 if (res != 0) /* check result */
449 {
450 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
451
452 return 1; /* return error */
453 }
454 }
455 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_1) /* 7.5 ms */
456 {
457 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_2_SECOND_LPM1, NULL, 0); /* write command */
458 if (res != 0) /* check result */
459 {
460 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
461
462 return 1; /* return error */
463 }
464 }
465 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_2) /* 5.0 ms */
466 {
467 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_2_SECOND_LPM2, NULL, 0); /* write command */
468 if (res != 0) /* check result */
469 {
470 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
471
472 return 1; /* return error */
473 }
474 }
475 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_3) /* 3.7 ms */
476 {
477 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_2_SECOND_LPM3, NULL, 0); /* write command */
478 if (res != 0) /* check result */
479 {
480 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
481
482 return 1; /* return error */
483 }
484 }
485 else /* invalid mode */
486 {
487 handle->debug_print("hdc302x: low power mode is invalid.\n"); /* low power mode is invalid */
488
489 return 4; /* return error */
490 }
491 handle->mode = 1; /* set continuous mode */
492
493 return 0; /* success return 0 */
494 }
495 else if (handle->auto_mode == (uint8_t)HDC302X_AUTO_MODE_4_HZ) /* 4 hz */
496 {
497 if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_0) /* 12.5 ms */
498 {
499 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_4_SECOND_LPM0, NULL, 0); /* write command */
500 if (res != 0) /* check result */
501 {
502 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
503
504 return 1; /* return error */
505 }
506 }
507 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_1) /* 7.5 ms */
508 {
509 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_4_SECOND_LPM1, NULL, 0); /* write command */
510 if (res != 0) /* check result */
511 {
512 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
513
514 return 1; /* return error */
515 }
516 }
517 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_2) /* 5.0 ms */
518 {
519 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_4_SECOND_LPM2, NULL, 0); /* write command */
520 if (res != 0) /* check result */
521 {
522 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
523
524 return 1; /* return error */
525 }
526 }
527 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_3) /* 3.7 ms */
528 {
529 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_4_SECOND_LPM3, NULL, 0); /* write command */
530 if (res != 0) /* check result */
531 {
532 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
533
534 return 1; /* return error */
535 }
536 }
537 else /* invalid mode */
538 {
539 handle->debug_print("hdc302x: low power mode is invalid.\n"); /* low power mode is invalid */
540
541 return 4; /* return error */
542 }
543 handle->mode = 1; /* set continuous mode */
544
545 return 0; /* success return 0 */
546 }
547 else if (handle->auto_mode == (uint8_t)HDC302X_AUTO_MODE_10_HZ) /* 10 hz */
548 {
549 if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_0) /* 12.5 ms */
550 {
551 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_10_SECOND_LPM0, NULL, 0); /* write command */
552 if (res != 0) /* check result */
553 {
554 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
555
556 return 1; /* return error */
557 }
558 }
559 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_1) /* 7.5 ms */
560 {
561 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_10_SECOND_LPM1, NULL, 0); /* write command */
562 if (res != 0) /* check result */
563 {
564 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
565
566 return 1; /* return error */
567 }
568 }
569 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_2) /* 5.0 ms */
570 {
571 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_10_SECOND_LPM2, NULL, 0); /* write command */
572 if (res != 0) /* check result */
573 {
574 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
575
576 return 1; /* return error */
577 }
578 }
579 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_3) /* 3.7 ms */
580 {
581 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_10_SECOND_LPM3, NULL, 0); /* write command */
582 if (res != 0) /* check result */
583 {
584 handle->debug_print("hdc302x: start continuous read failed.\n"); /* start continuous read failed */
585
586 return 1; /* return error */
587 }
588 }
589 else /* invalid mode */
590 {
591 handle->debug_print("hdc302x: low power mode is invalid.\n"); /* low power mode is invalid */
592
593 return 4; /* return error */
594 }
595 handle->mode = 1; /* set continuous mode */
596
597 return 0; /* success return 0 */
598 }
599 else /* invalid mode */
600 {
601 handle->debug_print("hdc302x: auto mode is invalid.\n"); /* auto mode is invalid */
602
603 return 5; /* return error */
604 }
605}
606
618{
619 uint8_t res;
620
621 if (handle == NULL) /* check handle */
622 {
623 return 2; /* return error */
624 }
625 if (handle->inited != 1) /* check handle initialization */
626 {
627 return 3; /* return error */
628 }
629
630 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_EXIT, NULL, 0); /* exit */
631 if (res != 0) /* check result */
632 {
633 handle->debug_print("hdc302x: exit failed.\n"); /* exit failed */
634
635 return 1; /* return error */
636 }
637 handle->mode = 0; /* set single mode */
638
639 return 0; /* success return 0 */
640}
641
658uint8_t hdc302x_continuous_read(hdc302x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s,
659 uint16_t *humidity_raw, float *humidity_s)
660{
661 uint8_t res;
662 uint8_t buf[6];
663
664 if (handle == NULL) /* check handle */
665 {
666 return 2; /* return error */
667 }
668 if (handle->inited != 1) /* check handle initialization */
669 {
670 return 3; /* return error */
671 }
672 if (handle->mode == 0) /* check mode */
673 {
674 handle->debug_print("hdc302x: current is not continuous mode.\n"); /* current is not continuous mode */
675
676 return 4; /* return error */
677 }
678
679 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_READ_T_RH, buf, 6); /* read data */
680 if (res != 0) /* check result */
681 {
682 handle->debug_print("hdc302x: read failed.\n"); /* read failed */
683
684 return 1; /* return error */
685 }
686 if (a_hdc302x_crc(buf + 0, 2) != buf[2]) /* check crc */
687 {
688 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
689
690 return 5; /* return error */
691 }
692 if (a_hdc302x_crc(buf + 3, 2) != buf[5]) /* check crc */
693 {
694 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
695
696 return 5; /* return error */
697 }
698 *temperature_raw = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set temperature raw */
699 *humidity_raw = (uint16_t)(((uint16_t)buf[3]) << 8) | buf[4]; /* set humidity raw */
700 *temperature_s = (float)(*temperature_raw) / 65535.0f * 175.0f - 45.0f; /* convert temperature */
701 *humidity_s = (float)(*humidity_raw) / 65535.0f * 100.0f; /* convert humidity */
702
703 return 0; /* success return 0 */
704}
705
723uint8_t hdc302x_single_read(hdc302x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s,
724 uint16_t *humidity_raw, float *humidity_s)
725{
726 uint8_t res;
727 uint8_t buf[6];
728 uint16_t command;
729
730 if (handle == NULL) /* check handle */
731 {
732 return 2; /* return error */
733 }
734 if (handle->inited != 1) /* check handle initialization */
735 {
736 return 3; /* return error */
737 }
738 if (handle->mode != 0) /* check mode */
739 {
740 handle->debug_print("hdc302x: continuous mode can't use this function.\n"); /* continuous mode can't use this function */
741
742 return 4; /* return error */
743 }
744
745 if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_0) /* low power mode 0 */
746 {
747 command = HDC302X_COMMAND_SINGLE_MEASUREMENT_LPM0; /* set command */
748 }
749 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_1) /* low power mode 1 */
750 {
751 command = HDC302X_COMMAND_SINGLE_MEASUREMENT_LPM1; /* set command */
752 }
753 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_2) /* low power mode 2 */
754 {
755 command = HDC302X_COMMAND_SINGLE_MEASUREMENT_LPM2; /* set command */
756 }
757 else if (handle->low_power_mode == (uint8_t)HDC302X_LOW_POWER_MODE_3) /* low power mode 3 */
758 {
759 command = HDC302X_COMMAND_SINGLE_MEASUREMENT_LPM3; /* set command */
760 }
761 else
762 {
763 handle->debug_print("hdc302x: low power mode is invalid.\n"); /* low power mode is invalid */
764
765 return 5; /* return error */
766 }
767 res = a_hdc302x_iic_read(handle, command, buf, 6); /* single read */
768 if (res != 0) /* check result */
769 {
770 handle->debug_print("hdc302x: single read failed.\n"); /* single read failed */
771
772 return 1; /* return error */
773 }
774 if (a_hdc302x_crc(buf + 0, 2) != buf[2]) /* check crc */
775 {
776 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
777
778 return 6; /* return error */
779 }
780 if (a_hdc302x_crc(buf + 3, 2) != buf[5]) /* check crc */
781 {
782 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
783
784 return 6; /* return error */
785 }
786 *temperature_raw = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set temperature raw */
787 *humidity_raw = (uint16_t)(((uint16_t)buf[3]) << 8) | buf[4]; /* set humidity raw */
788 *temperature_s = (float)(*temperature_raw) / 65535.0f * 175.0f - 45.0f; /* convert temperature */
789 *humidity_s = (float)(*humidity_raw) / 65535.0f * 100.0f; /* convert humidity */
790
791 return 0; /* success return 0 */
792}
793
808uint8_t hdc302x_continuous_read_humidity(hdc302x_handle_t *handle, uint16_t *humidity_raw, float *humidity_s)
809{
810 uint8_t res;
811 uint8_t buf[3];
812
813 if (handle == NULL) /* check handle */
814 {
815 return 2; /* return error */
816 }
817 if (handle->inited != 1) /* check handle initialization */
818 {
819 return 3; /* return error */
820 }
821 if (handle->mode == 0) /* check mode */
822 {
823 handle->debug_print("hdc302x: current is not continuous mode.\n"); /* current is not continuous mode */
824
825 return 4; /* return error */
826 }
827
828 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_READ_RH, buf, 3); /* read data */
829 if (res != 0) /* check result */
830 {
831 handle->debug_print("hdc302x: read failed.\n"); /* read failed */
832
833 return 1; /* return error */
834 }
835 if (a_hdc302x_crc(buf + 0, 2) != buf[2]) /* check crc */
836 {
837 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
838
839 return 5; /* return error */
840 }
841 *humidity_raw = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set humidity raw */
842 *humidity_s = (float)(*humidity_raw) / 65535.0f * 100.0f; /* convert humidity */
843
844 return 0; /* success return 0 */
845}
846
861uint8_t hdc302x_read_temperature_min(hdc302x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s)
862{
863 uint8_t res;
864 uint8_t buf[3];
865
866 if (handle == NULL) /* check handle */
867 {
868 return 2; /* return error */
869 }
870 if (handle->inited != 1) /* check handle initialization */
871 {
872 return 3; /* return error */
873 }
874 if (handle->mode == 0) /* check mode */
875 {
876 handle->debug_print("hdc302x: current is not continuous mode.\n"); /* current is not continuous mode */
877
878 return 4; /* return error */
879 }
880
881 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_READ_MIN_T, buf, 3); /* read data */
882 if (res != 0) /* check result */
883 {
884 handle->debug_print("hdc302x: read failed.\n"); /* read failed */
885
886 return 1; /* return error */
887 }
888 if (a_hdc302x_crc(buf + 0, 2) != buf[2]) /* check crc */
889 {
890 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
891
892 return 5; /* return error */
893 }
894 *temperature_raw = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set temperature raw */
895 *temperature_s = (float)(*temperature_raw) / 65535.0f * 175.0f - 45.0f; /* convert temperature */
896
897 return 0; /* success return 0 */
898}
899
914uint8_t hdc302x_read_temperature_max(hdc302x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s)
915{
916 uint8_t res;
917 uint8_t buf[3];
918
919 if (handle == NULL) /* check handle */
920 {
921 return 2; /* return error */
922 }
923 if (handle->inited != 1) /* check handle initialization */
924 {
925 return 3; /* return error */
926 }
927 if (handle->mode == 0) /* check mode */
928 {
929 handle->debug_print("hdc302x: current is not continuous mode.\n"); /* current is not continuous mode */
930
931 return 4; /* return error */
932 }
933
934 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_READ_MAX_T, buf, 3); /* read data */
935 if (res != 0) /* check result */
936 {
937 handle->debug_print("hdc302x: read failed.\n"); /* read failed */
938
939 return 1; /* return error */
940 }
941 if (a_hdc302x_crc(buf + 0, 2) != buf[2]) /* check crc */
942 {
943 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
944
945 return 5; /* return error */
946 }
947 *temperature_raw = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set temperature raw */
948 *temperature_s = (float)(*temperature_raw) / 65535.0f * 175.0f - 45.0f; /* convert temperature */
949
950 return 0; /* success return 0 */
951}
952
967uint8_t hdc302x_read_humidity_min(hdc302x_handle_t *handle, uint16_t *humidity_raw, float *humidity_s)
968{
969 uint8_t res;
970 uint8_t buf[3];
971
972 if (handle == NULL) /* check handle */
973 {
974 return 2; /* return error */
975 }
976 if (handle->inited != 1) /* check handle initialization */
977 {
978 return 3; /* return error */
979 }
980 if (handle->mode == 0) /* check mode */
981 {
982 handle->debug_print("hdc302x: current is not continuous mode.\n"); /* current is not continuous mode */
983
984 return 4; /* return error */
985 }
986
987 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_READ_MIN_RH, buf, 3); /* read data */
988 if (res != 0) /* check result */
989 {
990 handle->debug_print("hdc302x: read failed.\n"); /* read failed */
991
992 return 1; /* return error */
993 }
994 if (a_hdc302x_crc(buf + 0, 2) != buf[2]) /* check crc */
995 {
996 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
997
998 return 5; /* return error */
999 }
1000 *humidity_raw = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set humidity raw */
1001 *humidity_s = (float)(*humidity_raw) / 65535.0f * 100.0f; /* convert humidity */
1002
1003 return 0; /* success return 0 */
1004}
1005
1020uint8_t hdc302x_read_humidity_max(hdc302x_handle_t *handle, uint16_t *humidity_raw, float *humidity_s)
1021{
1022 uint8_t res;
1023 uint8_t buf[3];
1024
1025 if (handle == NULL) /* check handle */
1026 {
1027 return 2; /* return error */
1028 }
1029 if (handle->inited != 1) /* check handle initialization */
1030 {
1031 return 3; /* return error */
1032 }
1033 if (handle->mode == 0) /* check mode */
1034 {
1035 handle->debug_print("hdc302x: current is not continuous mode.\n"); /* current is not continuous mode */
1036
1037 return 4; /* return error */
1038 }
1039
1040 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_AUTO_MEASUREMENT_READ_MAX_RH, buf, 3); /* read data */
1041 if (res != 0) /* check result */
1042 {
1043 handle->debug_print("hdc302x: read failed.\n"); /* read failed */
1044
1045 return 1; /* return error */
1046 }
1047 if (a_hdc302x_crc(buf + 0, 2) != buf[2]) /* check crc */
1048 {
1049 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
1050
1051 return 5; /* return error */
1052 }
1053 *humidity_raw = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set humidity raw */
1054 *humidity_s = (float)(*humidity_raw) / 65535.0f * 100.0f; /* convert humidity */
1055
1056 return 0; /* success return 0 */
1057}
1058
1070uint8_t hdc302x_write_set_low_alert(hdc302x_handle_t *handle, uint16_t threshold)
1071{
1072 uint8_t res;
1073 uint8_t buf[3];
1074
1075 if (handle == NULL) /* check handle */
1076 {
1077 return 2; /* return error */
1078 }
1079 if (handle->inited != 1) /* check handle initialization */
1080 {
1081 return 3; /* return error */
1082 }
1083
1084 buf[0] = (threshold >> 8) & 0xFF; /* set msb */
1085 buf[1] = (threshold >> 0) & 0xFF; /* set lsb */
1086 buf[2] = a_hdc302x_crc(buf, 2); /* set crc */
1087 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_WRITE_SET_LOW_ALERT, buf, 3); /* write set low alert */
1088 if (res != 0) /* check result */
1089 {
1090 handle->debug_print("hdc302x: write set low alert failed.\n"); /* write set low alert failed */
1091
1092 return 1; /* return error */
1093 }
1094
1095 return 0; /* success return 0 */
1096}
1097
1109uint8_t hdc302x_write_clear_low_alert(hdc302x_handle_t *handle, uint16_t threshold)
1110{
1111 uint8_t res;
1112 uint8_t buf[3];
1113
1114 if (handle == NULL) /* check handle */
1115 {
1116 return 2; /* return error */
1117 }
1118 if (handle->inited != 1) /* check handle initialization */
1119 {
1120 return 3; /* return error */
1121 }
1122
1123 buf[0] = (threshold >> 8) & 0xFF; /* set msb */
1124 buf[1] = (threshold >> 0) & 0xFF; /* set lsb */
1125 buf[2] = a_hdc302x_crc(buf, 2); /* set crc */
1126 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_WRITE_CLEAR_LOW_ALERT, buf, 3); /* write clear low alert */
1127 if (res != 0) /* check result */
1128 {
1129 handle->debug_print("hdc302x: write clear low alert failed.\n"); /* write clear low alert failed */
1130
1131 return 1; /* return error */
1132 }
1133
1134 return 0; /* success return 0 */
1135}
1136
1148uint8_t hdc302x_write_set_high_alert(hdc302x_handle_t *handle, uint16_t threshold)
1149{
1150 uint8_t res;
1151 uint8_t buf[3];
1152
1153 if (handle == NULL) /* check handle */
1154 {
1155 return 2; /* return error */
1156 }
1157 if (handle->inited != 1) /* check handle initialization */
1158 {
1159 return 3; /* return error */
1160 }
1161
1162 buf[0] = (threshold >> 8) & 0xFF; /* set msb */
1163 buf[1] = (threshold >> 0) & 0xFF; /* set lsb */
1164 buf[2] = a_hdc302x_crc(buf, 2); /* set crc */
1165 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_WRITE_SET_HIGH_ALERT, buf, 3); /* write set high alert */
1166 if (res != 0) /* check result */
1167 {
1168 handle->debug_print("hdc302x: write set high alert failed.\n"); /* write set high alert failed */
1169
1170 return 1; /* return error */
1171 }
1172
1173 return 0; /* success return 0 */
1174}
1175
1187uint8_t hdc302x_write_clear_high_alert(hdc302x_handle_t *handle, uint16_t threshold)
1188{
1189 uint8_t res;
1190 uint8_t buf[3];
1191
1192 if (handle == NULL) /* check handle */
1193 {
1194 return 2; /* return error */
1195 }
1196 if (handle->inited != 1) /* check handle initialization */
1197 {
1198 return 3; /* return error */
1199 }
1200
1201 buf[0] = (threshold >> 8) & 0xFF; /* set msb */
1202 buf[1] = (threshold >> 0) & 0xFF; /* set lsb */
1203 buf[2] = a_hdc302x_crc(buf, 2); /* set crc */
1204 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_WRITE_CLEAR_HIGH_ALERT, buf, 3); /* write clear high alert */
1205 if (res != 0) /* check result */
1206 {
1207 handle->debug_print("hdc302x: write clear high alert failed.\n"); /* write clear high alert failed */
1208
1209 return 1; /* return error */
1210 }
1211
1212 return 0; /* success return 0 */
1213}
1214
1227uint8_t hdc302x_read_set_low_alert(hdc302x_handle_t *handle, uint16_t *threshold)
1228{
1229 uint8_t res;
1230 uint8_t buf[3];
1231
1232 if (handle == NULL) /* check handle */
1233 {
1234 return 2; /* return error */
1235 }
1236 if (handle->inited != 1) /* check handle initialization */
1237 {
1238 return 3; /* return error */
1239 }
1240
1241 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_READ_SET_LOW_ALERT, buf, 3); /* read set low alert */
1242 if (res != 0) /* check result */
1243 {
1244 handle->debug_print("hdc302x: read set low alert failed.\n"); /* read set low alert failed */
1245
1246 return 1; /* return error */
1247 }
1248 if (a_hdc302x_crc(buf, 2) != buf[2]) /* check crc */
1249 {
1250 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
1251
1252 return 4; /* return error */
1253 }
1254 *threshold = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set threshold */
1255
1256 return 0; /* success return 0 */
1257}
1258
1271uint8_t hdc302x_read_set_high_alert(hdc302x_handle_t *handle, uint16_t *threshold)
1272{
1273 uint8_t res;
1274 uint8_t buf[3];
1275
1276 if (handle == NULL) /* check handle */
1277 {
1278 return 2; /* return error */
1279 }
1280 if (handle->inited != 1) /* check handle initialization */
1281 {
1282 return 3; /* return error */
1283 }
1284
1285 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_READ_SET_HIGH_ALERT, buf, 3); /* read set high alert */
1286 if (res != 0) /* check result */
1287 {
1288 handle->debug_print("hdc302x: read set high alert failed.\n"); /* read set high alert failed */
1289
1290 return 1; /* return error */
1291 }
1292 if (a_hdc302x_crc(buf, 2) != buf[2]) /* check crc */
1293 {
1294 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
1295
1296 return 4; /* return error */
1297 }
1298 *threshold = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set threshold */
1299
1300 return 0; /* success return 0 */
1301}
1302
1315uint8_t hdc302x_read_clear_low_alert(hdc302x_handle_t *handle, uint16_t *threshold)
1316{
1317 uint8_t res;
1318 uint8_t buf[3];
1319
1320 if (handle == NULL) /* check handle */
1321 {
1322 return 2; /* return error */
1323 }
1324 if (handle->inited != 1) /* check handle initialization */
1325 {
1326 return 3; /* return error */
1327 }
1328
1329 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_READ_CLEAR_LOW_ALERT, buf, 3); /* read clear low alert */
1330 if (res != 0) /* check result */
1331 {
1332 handle->debug_print("hdc302x: read clear low alert failed.\n"); /* read clear low alert failed */
1333
1334 return 1; /* return error */
1335 }
1336 if (a_hdc302x_crc(buf, 2) != buf[2]) /* check crc */
1337 {
1338 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
1339
1340 return 4; /* return error */
1341 }
1342 *threshold = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set threshold */
1343
1344 return 0; /* success return 0 */
1345}
1346
1359uint8_t hdc302x_read_clear_high_alert(hdc302x_handle_t *handle, uint16_t *threshold)
1360{
1361 uint8_t res;
1362 uint8_t buf[3];
1363
1364 if (handle == NULL) /* check handle */
1365 {
1366 return 2; /* return error */
1367 }
1368 if (handle->inited != 1) /* check handle initialization */
1369 {
1370 return 3; /* return error */
1371 }
1372
1373 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_READ_CLEAR_HIGH_ALERT, buf, 3); /* read clear high alert */
1374 if (res != 0) /* check result */
1375 {
1376 handle->debug_print("hdc302x: read clear high alert failed.\n"); /* read clear high alert failed */
1377
1378 return 1; /* return error */
1379 }
1380 if (a_hdc302x_crc(buf, 2) != buf[2]) /* check crc */
1381 {
1382 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
1383
1384 return 4; /* return error */
1385 }
1386 *threshold = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set threshold */
1387
1388 return 0; /* success return 0 */
1389}
1390
1402{
1403 uint8_t res;
1404
1405 if (handle == NULL) /* check handle */
1406 {
1407 return 2; /* return error */
1408 }
1409 if (handle->inited != 1) /* check handle initialization */
1410 {
1411 return 3; /* return error */
1412 }
1413
1414 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_PROGRAM_ALERT_THRESHOLD, NULL, 0); /* nvm program */
1415 if (res != 0) /* check result */
1416 {
1417 handle->debug_print("hdc302x: nvm program alert threshold failed.\n"); /* nvm program alert threshold failed */
1418
1419 return 1; /* return error */
1420 }
1421 handle->delay_ms(80); /* delay 80 ms */
1422
1423 return 0; /* success return 0 */
1424}
1425
1438{
1439 uint8_t res;
1440 uint8_t buf[3];
1441
1442 if (handle == NULL) /* check handle */
1443 {
1444 return 2; /* return error */
1445 }
1446 if (handle->inited != 1) /* check handle initialization */
1447 {
1448 return 3; /* return error */
1449 }
1450
1451 buf[0] = (offset >> 8) & 0xFF; /* set msb */
1452 buf[1] = (offset >> 0) & 0xFF; /* set lsb */
1453 buf[2] = a_hdc302x_crc(buf, 2); /* set crc */
1454 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_PROGRAM_READ_OFFSET, buf, 3); /* nvm program */
1455 if (res != 0) /* check result */
1456 {
1457 handle->debug_print("hdc302x: nvm program offset failed.\n"); /* nvm program offset failed */
1458
1459 return 1; /* return error */
1460 }
1461 handle->delay_ms(80); /* delay 80 ms */
1462
1463 return 0; /* success return 0 */
1464}
1465
1479{
1480 uint8_t res;
1481 uint8_t buf[3];
1482
1483 if (handle == NULL) /* check handle */
1484 {
1485 return 2; /* return error */
1486 }
1487 if (handle->inited != 1) /* check handle initialization */
1488 {
1489 return 3; /* return error */
1490 }
1491
1492 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_PROGRAM_READ_OFFSET, buf, 3); /* nvm read */
1493 if (res != 0) /* check result */
1494 {
1495 handle->debug_print("hdc302x: nvm read offset failed.\n"); /* nvm read offset failed */
1496
1497 return 1; /* return error */
1498 }
1499 if (a_hdc302x_crc(buf, 2) != buf[2]) /* check crc */
1500 {
1501 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
1502
1503 return 4; /* return error */
1504 }
1505 *offset = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set offset */
1506
1507 return 0; /* success return 0 */
1508}
1509
1521uint8_t hdc302x_nvm_program_config(hdc302x_handle_t *handle, uint16_t config)
1522{
1523 uint8_t res;
1524 uint8_t buf[3];
1525
1526 if (handle == NULL) /* check handle */
1527 {
1528 return 2; /* return error */
1529 }
1530 if (handle->inited != 1) /* check handle initialization */
1531 {
1532 return 3; /* return error */
1533 }
1534
1535 buf[0] = (config >> 8) & 0xFF; /* set msb */
1536 buf[1] = (config >> 0) & 0xFF; /* set lsb */
1537 buf[2] = a_hdc302x_crc(buf, 2); /* set crc */
1538 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_PROGRAM_READ_EEPROM_CONFIG, buf, 3); /* nvm program */
1539 if (res != 0) /* check result */
1540 {
1541 handle->debug_print("hdc302x: nvm program config failed.\n"); /* nvm program config failed */
1542
1543 return 1; /* return error */
1544 }
1545 handle->delay_ms(80); /* delay 80 ms */
1546
1547 return 0; /* success return 0 */
1548}
1549
1562uint8_t hdc302x_nvm_read_config(hdc302x_handle_t *handle, uint16_t *config)
1563{
1564 uint8_t res;
1565 uint8_t buf[3];
1566
1567 if (handle == NULL) /* check handle */
1568 {
1569 return 2; /* return error */
1570 }
1571 if (handle->inited != 1) /* check handle initialization */
1572 {
1573 return 3; /* return error */
1574 }
1575
1576 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_PROGRAM_READ_EEPROM_CONFIG, buf, 3); /* nvm read */
1577 if (res != 0) /* check result */
1578 {
1579 handle->debug_print("hdc302x: nvm read config failed.\n"); /* nvm read config failed */
1580
1581 return 1; /* return error */
1582 }
1583 if (a_hdc302x_crc(buf, 2) != buf[2]) /* check crc */
1584 {
1585 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
1586
1587 return 4; /* return error */
1588 }
1589 *config = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set offset */
1590
1591 return 0; /* success return 0 */
1592}
1593
1605{
1606 uint8_t res;
1607
1608 if (handle == NULL) /* check handle */
1609 {
1610 return 2; /* return error */
1611 }
1612 if (handle->inited != 1) /* check handle initialization */
1613 {
1614 return 3; /* return error */
1615 }
1616
1617 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_HEATER_ENABLE, NULL, 0); /* enable heater */
1618 if (res != 0) /* check result */
1619 {
1620 handle->debug_print("hdc302x: enable heater failed.\n"); /* enable heater failed */
1621
1622 return 1; /* return error */
1623 }
1624
1625 return 0; /* success return 0 */
1626}
1627
1639{
1640 uint8_t res;
1641
1642 if (handle == NULL) /* check handle */
1643 {
1644 return 2; /* return error */
1645 }
1646 if (handle->inited != 1) /* check handle initialization */
1647 {
1648 return 3; /* return error */
1649 }
1650
1651 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_HEATER_DISABLE, NULL, 0); /* disable heater */
1652 if (res != 0) /* check result */
1653 {
1654 handle->debug_print("hdc302x: disable heater failed.\n"); /* disable heater failed */
1655
1656 return 1; /* return error */
1657 }
1658
1659 return 0; /* success return 0 */
1660}
1661
1692uint8_t hdc302x_set_heater_power(hdc302x_handle_t *handle, uint16_t power)
1693{
1694 uint8_t res;
1695 uint8_t buf[3];
1696
1697 if (handle == NULL) /* check handle */
1698 {
1699 return 2; /* return error */
1700 }
1701 if (handle->inited != 1) /* check handle initialization */
1702 {
1703 return 3; /* return error */
1704 }
1705 if (power > 0x3FFF) /* check power */
1706 {
1707 handle->debug_print("hdc302x: power > 0x3FFF.\n"); /* power > 0x3FFF */
1708
1709 return 4; /* return error */
1710 }
1711
1712 buf[0] = (power >> 8) & 0xFF; /* set msb */
1713 buf[1] = (power >> 0) & 0xFF; /* set lsb */
1714 buf[2] = a_hdc302x_crc(buf, 2); /* set crc */
1715 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_HEATER_CONFIG, buf, 3); /* heater config */
1716 if (res != 0) /* check result */
1717 {
1718 handle->debug_print("hdc302x: set heater power failed.\n"); /* set heater power failed */
1719
1720 return 1; /* return error */
1721 }
1722
1723 return 0; /* success return 0 */
1724}
1725
1738uint8_t hdc302x_get_heater_power(hdc302x_handle_t *handle, uint16_t *power)
1739{
1740 uint8_t res;
1741 uint8_t buf[3];
1742
1743 if (handle == NULL) /* check handle */
1744 {
1745 return 2; /* return error */
1746 }
1747 if (handle->inited != 1) /* check handle initialization */
1748 {
1749 return 3; /* return error */
1750 }
1751
1752 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_HEATER_CONFIG, buf, 3); /* heater config */
1753 if (res != 0) /* check result */
1754 {
1755 handle->debug_print("hdc302x: get heater power failed.\n"); /* get heater power failed */
1756
1757 return 1; /* return error */
1758 }
1759 if (a_hdc302x_crc(buf, 2) != buf[2]) /* check crc */
1760 {
1761 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
1762
1763 return 4; /* return error */
1764 }
1765 *power = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set power */
1766
1767 return 0; /* success return 0 */
1768}
1769
1782uint8_t hdc302x_get_nist_id(hdc302x_handle_t *handle, uint8_t id[6])
1783{
1784 uint8_t res;
1785 uint8_t buf[3];
1786
1787 if (handle == NULL) /* check handle */
1788 {
1789 return 2; /* return error */
1790 }
1791 if (handle->inited != 1) /* check handle initialization */
1792 {
1793 return 3; /* return error */
1794 }
1795
1796 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_READ_NIST_ID_BYTE5_BYTE4, buf, 3); /* read nist id */
1797 if (res != 0) /* check result */
1798 {
1799 handle->debug_print("hdc302x: read nist id failed.\n"); /* read nist id failed */
1800
1801 return 1; /* return error */
1802 }
1803 if (a_hdc302x_crc(buf, 2) != buf[2]) /* check crc */
1804 {
1805 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
1806
1807 return 4; /* return error */
1808 }
1809 id[5] = buf[0]; /* set id */
1810 id[4] = buf[1]; /* set id */
1811 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_READ_NIST_ID_BYTE3_BYTE2, buf, 3); /* read nist id */
1812 if (res != 0) /* check result */
1813 {
1814 handle->debug_print("hdc302x: read nist id failed.\n"); /* read nist id failed */
1815
1816 return 1; /* return error */
1817 }
1818 if (a_hdc302x_crc(buf, 2) != buf[2]) /* check crc */
1819 {
1820 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
1821
1822 return 4; /* return error */
1823 }
1824 id[3] = buf[0]; /* set id */
1825 id[2] = buf[1]; /* set id */
1826 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_READ_NIST_ID_BYTE1_BYTE0, buf, 3); /* read nist id */
1827 if (res != 0) /* check result */
1828 {
1829 handle->debug_print("hdc302x: read nist id failed.\n"); /* read nist id failed */
1830
1831 return 1; /* return error */
1832 }
1833 if (a_hdc302x_crc(buf, 2) != buf[2]) /* check crc */
1834 {
1835 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
1836
1837 return 4; /* return error */
1838 }
1839 id[1] = buf[0]; /* set id */
1840 id[0] = buf[1]; /* set id */
1841
1842 return 0; /* success return 0 */
1843}
1844
1857uint8_t hdc302x_get_status(hdc302x_handle_t *handle, uint16_t *status)
1858{
1859 uint8_t res;
1860 uint8_t buf[3];
1861
1862 if (handle == NULL) /* check handle */
1863 {
1864 return 2; /* return error */
1865 }
1866 if (handle->inited != 1) /* check handle initialization */
1867 {
1868 return 3; /* return error */
1869 }
1870
1871 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_READ_STATUS, buf, 3); /* get status */
1872 if (res != 0) /* check result */
1873 {
1874 handle->debug_print("hdc302x: get status failed.\n"); /* get status failed */
1875
1876 return 1; /* return error */
1877 }
1878 if (a_hdc302x_crc(buf, 2) != buf[2]) /* check crc */
1879 {
1880 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
1881
1882 return 4; /* return error */
1883 }
1884 *status = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set status */
1885
1886 return 0; /* success return 0 */
1887}
1888
1900{
1901 uint8_t res;
1902
1903 if (handle == NULL) /* check handle */
1904 {
1905 return 2; /* return error */
1906 }
1907 if (handle->inited != 1) /* check handle initialization */
1908 {
1909 return 3; /* return error */
1910 }
1911
1912 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_CLEAR_STATUS, NULL, 0); /* clear status */
1913 if (res != 0) /* check result */
1914 {
1915 handle->debug_print("hdc302x: clear status failed.\n"); /* clear status failed */
1916
1917 return 1; /* return error */
1918 }
1919
1920 return 0; /* success return 0 */
1921}
1922
1936{
1937 uint8_t res;
1938 uint8_t buf[3];
1939 uint16_t id;
1940
1941 if (handle == NULL) /* check handle */
1942 {
1943 return 2; /* return error */
1944 }
1945 if (handle->debug_print == NULL) /* check debug_print */
1946 {
1947 return 3; /* return error */
1948 }
1949 if (handle->iic_init == NULL) /* check iic_init */
1950 {
1951 handle->debug_print("hdc302x: iic_init is null.\n"); /* iic_init is null */
1952
1953 return 3; /* return error */
1954 }
1955 if (handle->iic_deinit == NULL) /* check iic_deinit */
1956 {
1957 handle->debug_print("hdc302x: iic_deinit is null.\n"); /* iic_deinit is null */
1958
1959 return 3; /* return error */
1960 }
1961 if (handle->iic_read_address16 == NULL) /* check iic_read_address16 */
1962 {
1963 handle->debug_print("hdc302x: iic_read_address16 is null.\n"); /* iic_read_address16 is null */
1964
1965 return 3; /* return error */
1966 }
1967 if (handle->iic_write_address16 == NULL) /* check iic_write_address16 */
1968 {
1969 handle->debug_print("hdc302x: iic_write_address16 is null.\n"); /* iic_write_address16 is null */
1970
1971 return 3; /* return error */
1972 }
1973 if (handle->delay_ms == NULL) /* check delay_ms */
1974 {
1975 handle->debug_print("hdc302x: delay_ms is null.\n"); /* delay_ms is null */
1976
1977 return 3; /* return error */
1978 }
1979
1980 if (handle->iic_init() != 0) /* iic init */
1981 {
1982 handle->debug_print("hdc302x: iic init failed.\n"); /* iic init failed */
1983
1984 return 1; /* return error */
1985 }
1986 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_READ_ID, buf, 3); /* get id */
1987 if (res != 0) /* check result */
1988 {
1989 handle->debug_print("hdc302x: get id failed.\n"); /* get id failed */
1990
1991 return 1; /* return error */
1992 }
1993 if (a_hdc302x_crc(buf, 2) != buf[2]) /* check crc */
1994 {
1995 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
1996
1997 return 4; /* return error */
1998 }
1999 id = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set id */
2000 if (id != 0x3000) /* check id */
2001 {
2002 handle->debug_print("hdc302x: id is invalid.\n"); /* id is invalid */
2003
2004 return 4; /* return error */
2005 }
2006 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_SOFT_RESET, NULL, 0); /* soft reset */
2007 if (res != 0) /* check result */
2008 {
2009 handle->debug_print("hdc302x: soft reset failed.\n"); /* soft reset failed */
2010
2011 return 5; /* return error */
2012 }
2013 handle->delay_ms(5); /* delay 5 ms */
2014 handle->auto_mode = 0; /* init 0 */
2015 handle->low_power_mode = 0; /* init 0 */
2016 handle->mode = 0; /* init 0 */
2017 handle->inited = 1; /* flag finish initialization */
2018
2019 return 0; /* success return 0 */
2020}
2021
2034{
2035 uint8_t res;
2036
2037 if (handle == NULL) /* check handle */
2038 {
2039 return 2; /* return error */
2040 }
2041 if (handle->inited != 1) /* check handle initialization */
2042 {
2043 return 3; /* return error */
2044 }
2045
2046 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_SOFT_RESET, NULL, 0); /* soft reset */
2047 if (res != 0) /* check result */
2048 {
2049 handle->debug_print("hdc302x: soft reset failed.\n"); /* soft reset failed */
2050
2051 return 4; /* return error */
2052 }
2053 if (handle->iic_deinit() != 0) /* iic deinit */
2054 {
2055 handle->debug_print("hdc302x: iic deinit failed.\n"); /* iic deinit failed */
2056
2057 return 1; /* return error */
2058 }
2059 handle->inited = 0; /* flag close */
2060
2061 return 0; /* success return 0 */
2062}
2063
2075{
2076 if (handle == NULL) /* check handle */
2077 {
2078 return 2; /* return error */
2079 }
2080
2081 handle->iic_addr = (uint8_t)addr; /* set address */
2082
2083 return 0; /* success return 0 */
2084}
2085
2097{
2098 if (handle == NULL) /* check handle */
2099 {
2100 return 2; /* return error */
2101 }
2102
2103 *addr = (hdc302x_address_t)(handle->iic_addr); /* get address */
2104
2105 return 0; /* success return 0 */
2106}
2107
2120{
2121 uint8_t res;
2122 uint8_t buf[3];
2123 uint16_t prev;
2124
2125 if (handle == NULL) /* check handle */
2126 {
2127 return 2; /* return error */
2128 }
2129 if (handle->inited != 1) /* check handle initialization */
2130 {
2131 return 3; /* return error */
2132 }
2133
2134 res = a_hdc302x_iic_read(handle, HDC302X_COMMAND_READ_STATUS, buf, 3); /* get status */
2135 if (res != 0) /* check result */
2136 {
2137 handle->debug_print("hdc302x: get status failed.\n"); /* get status failed */
2138
2139 return 1; /* return error */
2140 }
2141 if (a_hdc302x_crc(buf, 2) != buf[2]) /* check crc */
2142 {
2143 handle->debug_print("hdc302x: crc check error.\n"); /* crc check error */
2144
2145 return 4; /* return error */
2146 }
2147 prev = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set status */
2148 res = a_hdc302x_iic_write(handle, HDC302X_COMMAND_CLEAR_STATUS, NULL, 0); /* clear status */
2149 if (res != 0) /* check result */
2150 {
2151 handle->debug_print("hdc302x: clear status failed.\n"); /* clear status failed */
2152
2153 return 1; /* return error */
2154 }
2155
2156 if (prev != 0) /* check status */
2157 {
2158 if ((prev & HDC302X_STATUS_OVERALL_ALERT) != 0) /* check overall alert */
2159 {
2160 if (handle->receive_callback != NULL) /* not null */
2161 {
2162 handle->receive_callback(HDC302X_STATUS_OVERALL_ALERT); /* run the callback */
2163 }
2164 }
2165 if ((prev & HDC302X_STATUS_HEATER) != 0) /* check heater */
2166 {
2167 if (handle->receive_callback != NULL) /* not null */
2168 {
2169 handle->receive_callback(HDC302X_STATUS_HEATER); /* run the callback */
2170 }
2171 }
2172 if ((prev & HDC302X_STATUS_RH_TRACKING_ALERT) != 0) /* check rh tracking alert */
2173 {
2174 if (handle->receive_callback != NULL) /* not null */
2175 {
2176 handle->receive_callback(HDC302X_STATUS_RH_TRACKING_ALERT); /* run the callback */
2177 }
2178 }
2179 if ((prev & HDC302X_STATUS_T_TRACKING_ALERT) != 0) /* check t tracking alert */
2180 {
2181 if (handle->receive_callback != NULL) /* not null */
2182 {
2183 handle->receive_callback(HDC302X_STATUS_T_TRACKING_ALERT); /* run the callback */
2184 }
2185 }
2186 if ((prev & HDC302X_STATUS_RH_HIGH_TRACKING_ALERT) != 0) /* check rh high tracking alert */
2187 {
2188 if (handle->receive_callback != NULL) /* not null */
2189 {
2190 handle->receive_callback(HDC302X_STATUS_RH_HIGH_TRACKING_ALERT); /* run the callback */
2191 }
2192 }
2193 if ((prev & HDC302X_STATUS_RH_LOW_TRACKING_ALERT) != 0) /* check rh low tracking alert */
2194 {
2195 if (handle->receive_callback != NULL) /* not null */
2196 {
2197 handle->receive_callback(HDC302X_STATUS_RH_LOW_TRACKING_ALERT); /* run the callback */
2198 }
2199 }
2200 if ((prev & HDC302X_STATUS_T_HIGH_TRACKING_ALERT) != 0) /* check t high tracking alert */
2201 {
2202 if (handle->receive_callback != NULL) /* not null */
2203 {
2204 handle->receive_callback(HDC302X_STATUS_T_HIGH_TRACKING_ALERT); /* run the callback */
2205 }
2206 }
2207 if ((prev & HDC302X_STATUS_T_LOW_TRACKING_ALERT) != 0) /* check t low tracking alert */
2208 {
2209 if (handle->receive_callback != NULL) /* not null */
2210 {
2211 handle->receive_callback(HDC302X_STATUS_T_LOW_TRACKING_ALERT); /* run the callback */
2212 }
2213 }
2214 if ((prev & HDC302X_STATUS_DEVICE_RESET_DETECTED) != 0) /* check device reset detected */
2215 {
2216 if (handle->receive_callback != NULL) /* not null */
2217 {
2218 handle->receive_callback(HDC302X_STATUS_DEVICE_RESET_DETECTED); /* run the callback */
2219 }
2220 }
2221 if ((prev & HDC302X_STATUS_CHECKSUM_VERY) != 0) /* check checksum very */
2222 {
2223 if (handle->receive_callback != NULL) /* not null */
2224 {
2225 handle->receive_callback(HDC302X_STATUS_CHECKSUM_VERY); /* run the callback */
2226 }
2227 }
2228 }
2229
2230 return 0; /* success return 0 */
2231}
2232
2246 float humidity_percentage, uint16_t *reg)
2247{
2248 uint16_t temperature;
2249 uint16_t humidity;
2250
2251 if (handle == NULL) /* check handle */
2252 {
2253 return 2; /* return error */
2254 }
2255 if (handle->inited != 1) /* check handle initialization */
2256 {
2257 return 3; /* return error */
2258 }
2259
2260 humidity = (uint16_t)(humidity_percentage / 100.0f * 65535.0f); /* convert humidity */
2261 temperature = (uint16_t)((temperature_deg + 45.0f) / 175.0f * 65535.0f); /* convert temperature */
2262 *reg = (humidity >> 9) << 9 | (temperature >> 7); /* convert real data to register data */
2263
2264 return 0; /* success return 0 */
2265}
2266
2280 float *temperature_deg, float *humidity_percentage)
2281{
2282 uint16_t temperature;
2283 uint16_t humidity;
2284
2285 if (handle == NULL) /* check handle */
2286 {
2287 return 2; /* return error */
2288 }
2289 if (handle->inited != 1) /* check handle initialization */
2290 {
2291 return 3; /* return error */
2292 }
2293
2294 humidity = reg >> 9; /* convert humidity */
2295 humidity = humidity << 9; /* convert humidity */
2296 temperature = reg << 7; /* convert temperature */
2297 *temperature_deg = (float)(temperature) / 65535.0f * 175.0f - 45.0f; /* convert temperature */
2298 *humidity_percentage = (float)(humidity) / 65535.0f * 100.0f; /* convert humidity */
2299
2300 return 0; /* success return 0 */
2301}
2302
2317uint8_t hdc302x_offset_convert_to_register(hdc302x_handle_t *handle, uint8_t temperature_symbol, float temperature_deg,
2318 uint8_t humidity_symbol, float humidity_percentage, uint16_t *reg)
2319{
2320 uint16_t temperature;
2321 uint16_t humidity;
2322 uint8_t temperature_reg8;
2323 uint8_t humidity_reg8;
2324
2325 if (handle == NULL) /* check handle */
2326 {
2327 return 2; /* return error */
2328 }
2329 if (handle->inited != 1) /* check handle initialization */
2330 {
2331 return 3; /* return error */
2332 }
2333
2334 humidity = (uint16_t)(humidity_percentage / 100.0f * 65535.0f); /* convert humidity */
2335 temperature = (uint16_t)((temperature_deg + 45.0f) / 175.0f * 65535.0f); /* convert temperature */
2336 temperature_reg8 = (temperature >> 6) & 0x7F; /* convert temperature */
2337 if (temperature_symbol != 0) /* positive */
2338 {
2339 temperature_reg8 |= 1 << 7; /* set sign */
2340 }
2341 humidity_reg8 = (humidity >> 7) & 0x7F; /* convert humidity */
2342 if (humidity_symbol != 0) /* positive */
2343 {
2344 humidity_reg8 |= 1 << 7; /* set sign */
2345 }
2346 *reg = ((uint16_t)humidity_reg8) << 8 | temperature_reg8; /* set reg */
2347
2348 return 0; /* success return 0 */
2349}
2350
2366 uint8_t *temperature_symbol, float *temperature_deg,
2367 uint8_t *humidity_symbol, float *humidity_percentage)
2368{
2369 uint8_t temperature_reg8;
2370 uint8_t humidity_reg8;
2371 uint16_t temperature;
2372 uint16_t humidity;
2373
2374 if (handle == NULL) /* check handle */
2375 {
2376 return 2; /* return error */
2377 }
2378 if (handle->inited != 1) /* check handle initialization */
2379 {
2380 return 3; /* return error */
2381 }
2382
2383 temperature_reg8 = reg & 0xFF; /* set temperature */
2384 if ((temperature_reg8 >> 7) != 0) /* check sign */
2385 {
2386 *temperature_symbol = 1; /* set 1 */
2387 }
2388 else
2389 {
2390 *temperature_symbol = 0; /* set 0 */
2391 }
2392 temperature_reg8 &= ~(1 << 7); /* clear symbol */
2393 humidity_reg8 = (reg >> 8) & 0xFF; /* set humidity */
2394 if ((humidity_reg8 >> 7) != 0) /* check sign */
2395 {
2396 *humidity_symbol = 1; /* set 1 */
2397 }
2398 else
2399 {
2400 *humidity_symbol = 0; /* set 0 */
2401 }
2402 humidity_reg8 &= ~(1 << 7); /* clear symbol */
2403 temperature = temperature_reg8 << 6; /* convert temperature */
2404 temperature |= 1 << 14; /* set temperature */
2405 humidity = humidity_reg8 << 7; /* convert humidity */
2406 *temperature_deg = (float)(temperature) / 65535.0f * 175.0f - 45.0f; /* convert temperature */
2407 *humidity_percentage = (float)(humidity) / 65535.0f * 100.0f; /* convert humidity */
2408
2409 return 0; /* success return 0 */
2410}
2411
2425uint8_t hdc302x_set_reg(hdc302x_handle_t *handle, uint16_t command, uint8_t *buf, uint16_t len)
2426{
2427 if (handle == NULL) /* check handle */
2428 {
2429 return 2; /* return error */
2430 }
2431 if (handle->inited != 1) /* check handle initialization */
2432 {
2433 return 3; /* return error */
2434 }
2435
2436 if (a_hdc302x_iic_write(handle, command, buf, len) != 0) /* write data */
2437 {
2438 return 1; /* return error */
2439 }
2440
2441 return 0; /* success return 0 */
2442}
2443
2457uint8_t hdc302x_get_reg(hdc302x_handle_t *handle, uint16_t command, uint8_t *buf, uint16_t len)
2458{
2459 if (handle == NULL) /* check handle */
2460 {
2461 return 2; /* return error */
2462 }
2463 if (handle->inited != 1) /* check handle initialization */
2464 {
2465 return 3; /* return error */
2466 }
2467
2468 if (a_hdc302x_iic_read(handle, command, buf, len) != 0) /* read data */
2469 {
2470 return 1; /* return error */
2471 }
2472
2473 return 0; /* success return 0 */
2474}
2475
2485{
2486 if (info == NULL) /* check handle */
2487 {
2488 return 2; /* return error */
2489 }
2490
2491 memset(info, 0, sizeof(hdc302x_info_t)); /* initialize hdc302x info structure */
2492 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
2493 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
2494 strncpy(info->interface, "IIC", 8); /* copy interface name */
2495 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
2496 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
2497 info->max_current_ma = MAX_CURRENT; /* set maximum current */
2498 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
2499 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
2500 info->driver_version = DRIVER_VERSION; /* set driver version */
2501
2502 return 0; /* success return 0 */
2503}
#define HDC302X_COMMAND_SOFT_RESET
#define HDC302X_COMMAND_AUTO_MEASUREMENT_1_SECOND_LPM2
#define HDC302X_COMMAND_READ_SET_HIGH_ALERT
#define HDC302X_COMMAND_AUTO_MEASUREMENT_10_SECOND_LPM3
#define HDC302X_COMMAND_PROGRAM_ALERT_THRESHOLD
#define HDC302X_COMMAND_HEATER_CONFIG
#define HDC302X_COMMAND_READ_NIST_ID_BYTE1_BYTE0
#define HDC302X_COMMAND_SINGLE_MEASUREMENT_LPM3
#define HDC302X_COMMAND_AUTO_MEASUREMENT_READ_MIN_RH
#define MAX_CURRENT
#define HDC302X_COMMAND_SINGLE_MEASUREMENT_LPM1
#define HDC302X_COMMAND_HEATER_ENABLE
#define HDC302X_COMMAND_READ_NIST_ID_BYTE5_BYTE4
#define HDC302X_COMMAND_WRITE_SET_HIGH_ALERT
#define HDC302X_COMMAND_AUTO_MEASUREMENT_1_SECOND_LPM0
#define HDC302X_COMMAND_READ_NIST_ID_BYTE3_BYTE2
#define HDC302X_COMMAND_READ_STATUS
#define HDC302X_COMMAND_AUTO_MEASUREMENT_READ_MIN_T
#define SUPPLY_VOLTAGE_MAX
#define HDC302X_COMMAND_AUTO_MEASUREMENT_2_SECOND_LPM2
#define HDC302X_COMMAND_AUTO_MEASUREMENT_1_SECOND_LPM3
#define HDC302X_COMMAND_AUTO_MEASUREMENT_0P5_SECOND_LPM2
#define HDC302X_COMMAND_AUTO_MEASUREMENT_READ_MAX_RH
#define HDC302X_COMMAND_AUTO_MEASUREMENT_0P5_SECOND_LPM0
#define HDC302X_COMMAND_PROGRAM_READ_EEPROM_CONFIG
#define TEMPERATURE_MAX
#define HDC302X_COMMAND_CLEAR_STATUS
#define HDC302X_COMMAND_READ_CLEAR_HIGH_ALERT
#define HDC302X_COMMAND_AUTO_MEASUREMENT_READ_RH
#define HDC302X_COMMAND_SINGLE_MEASUREMENT_LPM2
#define HDC302X_COMMAND_AUTO_MEASUREMENT_10_SECOND_LPM0
#define HDC302X_COMMAND_EXIT
#define HDC302X_COMMAND_AUTO_MEASUREMENT_2_SECOND_LPM3
#define HDC302X_COMMAND_SINGLE_MEASUREMENT_LPM0
chip command definition
#define HDC302X_COMMAND_AUTO_MEASUREMENT_0P5_SECOND_LPM1
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define HDC302X_COMMAND_READ_SET_LOW_ALERT
#define SUPPLY_VOLTAGE_MIN
#define HDC302X_COMMAND_AUTO_MEASUREMENT_10_SECOND_LPM1
#define HDC302X_COMMAND_AUTO_MEASUREMENT_1_SECOND_LPM1
#define HDC302X_COMMAND_WRITE_CLEAR_LOW_ALERT
#define HDC302X_COMMAND_AUTO_MEASUREMENT_4_SECOND_LPM2
#define HDC302X_COMMAND_AUTO_MEASUREMENT_2_SECOND_LPM1
#define HDC302X_COMMAND_AUTO_MEASUREMENT_4_SECOND_LPM3
#define HDC302X_COMMAND_READ_CLEAR_LOW_ALERT
#define HDC302X_COMMAND_HEATER_DISABLE
#define HDC302X_COMMAND_AUTO_MEASUREMENT_4_SECOND_LPM0
#define HDC302X_COMMAND_AUTO_MEASUREMENT_2_SECOND_LPM0
#define HDC302X_COMMAND_AUTO_MEASUREMENT_10_SECOND_LPM2
#define HDC302X_COMMAND_PROGRAM_READ_OFFSET
#define HDC302X_COMMAND_AUTO_MEASUREMENT_READ_MAX_T
#define HDC302X_COMMAND_WRITE_SET_LOW_ALERT
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
#define HDC302X_COMMAND_AUTO_MEASUREMENT_0P5_SECOND_LPM3
#define HDC302X_COMMAND_WRITE_CLEAR_HIGH_ALERT
#define HDC302X_COMMAND_AUTO_MEASUREMENT_4_SECOND_LPM1
#define HDC302X_COMMAND_AUTO_MEASUREMENT_READ_T_RH
#define HDC302X_COMMAND_READ_ID
driver hdc302x header file
uint8_t hdc302x_alert_threshold_convert_to_data(hdc302x_handle_t *handle, uint16_t reg, float *temperature_deg, float *humidity_percentage)
convert the alert threshold to the real data
uint8_t hdc302x_get_addr(hdc302x_handle_t *handle, hdc302x_address_t *addr)
get the iic address
uint8_t hdc302x_continuous_read(hdc302x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
continuous read
uint8_t hdc302x_read_clear_high_alert(hdc302x_handle_t *handle, uint16_t *threshold)
read clear high alert
uint8_t hdc302x_read_set_low_alert(hdc302x_handle_t *handle, uint16_t *threshold)
read set low alert
uint8_t hdc302x_nvm_program_temperature_humidity_offset(hdc302x_handle_t *handle, uint16_t offset)
nvm program temperature humidity offset
uint8_t hdc302x_disable_heater(hdc302x_handle_t *handle)
disable heater
uint8_t hdc302x_set_heater_power(hdc302x_handle_t *handle, uint16_t power)
set heater power
uint8_t hdc302x_continuous_read_humidity(hdc302x_handle_t *handle, uint16_t *humidity_raw, float *humidity_s)
continuous read humidity
uint8_t hdc302x_nvm_read_temperature_humidity_offset(hdc302x_handle_t *handle, uint16_t *offset)
nvm read temperature humidity offset
uint8_t hdc302x_offset_convert_to_data(hdc302x_handle_t *handle, uint16_t reg, uint8_t *temperature_symbol, float *temperature_deg, uint8_t *humidity_symbol, float *humidity_percentage)
convert the offset to the real data
struct hdc302x_info_s hdc302x_info_t
hdc302x information structure definition
uint8_t hdc302x_enable_heater(hdc302x_handle_t *handle)
enable heater
uint8_t hdc302x_set_addr(hdc302x_handle_t *handle, hdc302x_address_t addr)
set the iic address
uint8_t hdc302x_deinit(hdc302x_handle_t *handle)
close the chip
hdc302x_address_t
hdc302x address enumeration definition
uint8_t hdc302x_irq_handler(hdc302x_handle_t *handle)
irq handler
uint8_t hdc302x_offset_convert_to_register(hdc302x_handle_t *handle, uint8_t temperature_symbol, float temperature_deg, uint8_t humidity_symbol, float humidity_percentage, uint16_t *reg)
convert the offset to the register raw data
uint8_t hdc302x_single_read(hdc302x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
single read
uint8_t hdc302x_set_low_power_mode(hdc302x_handle_t *handle, hdc302x_low_power_mode_t mode)
set low power mode
uint8_t hdc302x_get_nist_id(hdc302x_handle_t *handle, uint8_t id[6])
get nist id
uint8_t hdc302x_read_temperature_min(hdc302x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s)
read temperature min
hdc302x_auto_mode_t
hdc302x auto mode enumeration definition
uint8_t hdc302x_set_auto_mode(hdc302x_handle_t *handle, hdc302x_auto_mode_t mode)
set auto mode
uint8_t hdc302x_alert_threshold_convert_to_register(hdc302x_handle_t *handle, float temperature_deg, float humidity_percentage, uint16_t *reg)
convert the alert threshold to the register raw data
uint8_t hdc302x_get_low_power_mode(hdc302x_handle_t *handle, hdc302x_low_power_mode_t *mode)
get low power mode
uint8_t hdc302x_read_humidity_min(hdc302x_handle_t *handle, uint16_t *humidity_raw, float *humidity_s)
read humidity min
uint8_t hdc302x_read_set_high_alert(hdc302x_handle_t *handle, uint16_t *threshold)
read set high alert
uint8_t hdc302x_nvm_read_config(hdc302x_handle_t *handle, uint16_t *config)
nvm read config
uint8_t hdc302x_init(hdc302x_handle_t *handle)
initialize the chip
uint8_t hdc302x_write_clear_low_alert(hdc302x_handle_t *handle, uint16_t threshold)
write clear low alert
uint8_t hdc302x_get_auto_mode(hdc302x_handle_t *handle, hdc302x_auto_mode_t *mode)
get auto mode
hdc302x_low_power_mode_t
hdc302x low power mode enumeration definition
uint8_t hdc302x_clear_status(hdc302x_handle_t *handle)
clear status
uint8_t hdc302x_write_set_low_alert(hdc302x_handle_t *handle, uint16_t threshold)
write set low alert
uint8_t hdc302x_read_temperature_max(hdc302x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s)
read temperature max
uint8_t hdc302x_stop_continuous_read(hdc302x_handle_t *handle)
stop continuous read
struct hdc302x_handle_s hdc302x_handle_t
hdc302x handle structure definition
uint8_t hdc302x_read_clear_low_alert(hdc302x_handle_t *handle, uint16_t *threshold)
read clear low alert
uint8_t hdc302x_soft_reset(hdc302x_handle_t *handle)
soft reset
uint8_t hdc302x_nvm_program_alert_threshold(hdc302x_handle_t *handle)
nvm program alert threshold
uint8_t hdc302x_get_status(hdc302x_handle_t *handle, uint16_t *status)
get status
uint8_t hdc302x_read_humidity_max(hdc302x_handle_t *handle, uint16_t *humidity_raw, float *humidity_s)
read humidity max
uint8_t hdc302x_get_heater_power(hdc302x_handle_t *handle, uint16_t *power)
get heater power
uint8_t hdc302x_info(hdc302x_info_t *info)
get chip's information
uint8_t hdc302x_start_continuous_read(hdc302x_handle_t *handle)
start continuous read
uint8_t hdc302x_write_clear_high_alert(hdc302x_handle_t *handle, uint16_t threshold)
write clear high alert
uint8_t hdc302x_nvm_program_config(hdc302x_handle_t *handle, uint16_t config)
nvm program config
uint8_t hdc302x_write_set_high_alert(hdc302x_handle_t *handle, uint16_t threshold)
write set high alert
@ HDC302X_STATUS_OVERALL_ALERT
@ HDC302X_STATUS_T_HIGH_TRACKING_ALERT
@ HDC302X_STATUS_RH_LOW_TRACKING_ALERT
@ HDC302X_STATUS_T_LOW_TRACKING_ALERT
@ HDC302X_STATUS_HEATER
@ HDC302X_STATUS_CHECKSUM_VERY
@ HDC302X_STATUS_RH_HIGH_TRACKING_ALERT
@ HDC302X_STATUS_DEVICE_RESET_DETECTED
@ HDC302X_STATUS_T_TRACKING_ALERT
@ HDC302X_STATUS_RH_TRACKING_ALERT
@ HDC302X_AUTO_MODE_2_HZ
@ HDC302X_AUTO_MODE_10_HZ
@ HDC302X_AUTO_MODE_0P5_HZ
@ HDC302X_AUTO_MODE_1_HZ
@ HDC302X_AUTO_MODE_4_HZ
@ HDC302X_LOW_POWER_MODE_3
@ HDC302X_LOW_POWER_MODE_2
@ HDC302X_LOW_POWER_MODE_0
@ HDC302X_LOW_POWER_MODE_1
uint8_t hdc302x_get_reg(hdc302x_handle_t *handle, uint16_t command, uint8_t *buf, uint16_t len)
get the chip register
uint8_t hdc302x_set_reg(hdc302x_handle_t *handle, uint16_t command, uint8_t *buf, uint16_t len)
set the chip register
void(* delay_ms)(uint32_t ms)
uint8_t(* iic_read_address16)(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
void(* receive_callback)(uint16_t type)
uint8_t(* iic_init)(void)
uint8_t(* iic_write_address16)(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
uint32_t driver_version
char manufacturer_name[32]