Data Logger BLE Cellular Board
Loading...
Searching...
No Matches
HDC2080.c
Go to the documentation of this file.
1/**
2 * \file HDC2080.c
3 * \brief Description: This library facilitates communication with, and configuration of,
4 * the HDC2080 Temperature and Humidity Sensor. It makes extensive use of the
5 * Wire.H library, and should be useable with both Arduino and Energia.
6 *
7 * \note code is release AS-IS into the public domain, no guarantee or warranty is given.
8 *
9 * \author HDC2010.cpp originally created by: Brandon Fisher, August 1st 2017
10 */
11#include "jfet_files/HDC2080.h"
13#include <stdint.h>
14#include <stdio.h>
15#include <zephyr/drivers/i2c.h>
16
17/**
18 * \fn float readTemp(void)
19 *
20 * \brief Reads the temperature data from the HDC2080 sensor.
21 *
22 * \return Temperature in degrees Celsius.
23 */
24float readTemp(void) {
25 uint8_t byte[2];
26 int err;
27 uint16_t temp;
28 float f;
29
30 /* Read two bytes starting from the TEMP_LOW register */
31 err = readReg(TEMP_LOW, byte, 2);
32 /* Combine high and low bytes into a 16-bit value */
33 temp = (byte[1] << 8) | byte[0];
34 /* Convert raw digital value to Celsius using datasheet formula */
35 f = ((temp * 165.0f) / 65536.0f) - 40.0f;
36 return f;
37}
38
39/**
40 * \fn uint8_t readTempOffsetAdjust(void)
41 *
42 * \brief Reads the temperature offset adjustment value.
43 *
44 * \return The 8-bit offset value from the register.
45 */
46uint8_t readTempOffsetAdjust(void) {
47 uint8_t byte[2];
48
49 /* Read the offset register */
51 return byte[0];
52}
53
54/**
55 * \fn uint8_t setTempOffsetAdjust(uint8_t value)
56 *
57 * \brief Sets the temperature offset adjustment value.
58 *
59 * \param value The 8-bit offset value to write (see datasheet page 22).
60 *
61 * \return The value read back from the register after writing.
62 */
63uint8_t setTempOffsetAdjust(uint8_t value) {
64 uint8_t byte[2];
65
66 byte[0] = value;
67 /* Write the new offset to the sensor */
69 return readTempOffsetAdjust();
70}
71
72/**
73 * \fn float readHumidity(void)
74 *
75 * \brief Reads the relative humidity from the HDC2080 sensor.
76 *
77 * \return Relative humidity as a percentage (0.0 to 100.0).
78 */
79float readHumidity(void) {
80 uint8_t byte[2];
81 int err;
82 uint16_t humidity;
83 float f;
84
85 /* Read two bytes starting from the HUMID_LOW register */
86 err = readReg(HUMID_LOW, byte, 2);
87 /* Combine high and low bytes */
88 humidity = (byte[1] << 8) | byte[0];
89 /* Convert raw value to percentage relative humidity */
90 f = (humidity / 65536.0f) * 100.0f;
91 return f;
92}
93
94/**
95 * \fn uint8_t readHumidityOffsetAdjust(void)
96 *
97 * \brief Reads the humidity offset adjustment value from the sensor.
98 *
99 * \return The 8-bit offset value from the HUM_OFFSET_ADJUST register.
100 */
102 uint8_t byte[2];
103
104 /* Read the humidity offset register */
105 readReg(HUM_OFFSET_ADJUST, byte, 1);
106 return byte[0];
107}
108
109// Página 23 do datasheet
110/**
111 * \fn uint8_t setHumidityOffsetAdjust(uint8_t value)
112 *
113 * \brief Sets the humidity offset adjustment value.
114 *
115 * \param value The 8-bit offset value to write.
116 *
117 * \return The value read back from the register after writing.
118 */
119uint8_t setHumidityOffsetAdjust(uint8_t value) {
120 uint8_t byte[2];
121
122 byte[0] = value;
123 /* Write the new offset to the sensor */
124 writeReg(HUM_OFFSET_ADJUST, byte, 1);
126}
127
128/**
129 * \fn void enableHeater(void)
130 *
131 * \brief Enables the internal heating element of the HDC2080.
132 */
133void enableHeater(void) {
134 int err;
135 uint8_t configContents; // Stores current contents of config register
136
137 err = readReg(HDC_CONFIG, &configContents, 1);
138
139 // set bit 3 to 1 to enable heater
140 configContents = (configContents | 0x08);
141
142 writeReg(HDC_CONFIG, &configContents, 1);
143}
144
145/**
146 * \fn void disableHeater(void)
147 *
148 * \brief Disables the internal heating element of the HDC2080.
149 */
150void disableHeater(void) {
151 int err;
152 uint8_t configContents; // Stores current contents of config register
153
154 err = readReg(HDC_CONFIG, &configContents, 1);
155
156 // set bit 3 to 0 to disable heater (all other bits 1)
157 configContents = (configContents & 0xF7);
158 writeReg(HDC_CONFIG, &configContents, 1);
159}
160
161/**
162 * \fn uint8_t readReg(uint8_t reg, uint8_t *data, uint8_t count)
163 *
164 * \brief Reads a specified number of bytes from a sensor register over I2C.
165 *
166 * \param reg The register address to read from.
167 * \param data Pointer to the buffer where received data will be stored.
168 * \param count Number of bytes to read.
169 *
170 * \return Returns TRUE (1) upon completion.
171 */
172uint8_t readReg(uint8_t reg, uint8_t *data, uint8_t count) {
173 uint8_t dataOut[6];
174
175 dataOut[0] = reg;
176 // if (i2c_write(i2c_dev, dataOut, 1, HDC_ADDRESS))
177 i2c_write(i2c_dev, dataOut, 1, HDC_ADDRESS);
178 // {
179 // myPrintkE("Fail to write to I2C\n");
180 // return FALSE;
181 // }
182 // if (i2c_read(i2c_dev, data, count, HDC_ADDRESS))
183 i2c_read(i2c_dev, data, count, HDC_ADDRESS);
184 // {
185 // myPrintkE("Fail to read to I2C\n");
186 // return FALSE;
187 // }
188 // printf("HDC2080 read reg: 0x%02X count: %d\r\n",reg,count);
189 // for(int i=0; i<count; i++)
190 // printf("i:%d 0x%02X\r\n",i, data[i]);
191 return TRUE;
192}
193
194/**
195 * \fn uint8_t writeReg(uint8_t reg, uint8_t *data, uint8_t count)
196 *
197 * \brief Writes a specified number of bytes to a sensor register over I2C.
198 *
199 * \param reg The register address to write to.
200 *
201 * \param data Pointer to the buffer containing data to be written.
202 * \param count Number of bytes to write.
203 *
204 * \return Returns TRUE (1) upon completion.
205 */
206uint8_t writeReg(uint8_t reg, uint8_t *data, uint8_t count) {
207 uint8_t datas[10];
208 int i;
209 // printf("HDC2080 write reg: 0x%02X count: %d\r\n",reg,count);
210 // for(int i=0; i<count; i++)
211 // printf("i:%d 0x%02X\r\n",i, data[i]);
212
213 /* load array with register and data */
214 datas[0] = reg;
215 for (i = 0; i < count; i++)
216 datas[i + 1] = data[i];
217
218 /* write data to HDC2080 */
219 // if (i2c_write(i2c_dev, datas, count + 1, HDC_ADDRESS))
220 i2c_write(i2c_dev, datas, count + 1, HDC_ADDRESS);
221 // {
222 // myPrintkE("Fail to write to I2C\n");
223 // return FALSE;
224 // }
225 return TRUE;
226}
227
228/**
229 * \fn void setLowTemp(float temp)
230 *
231 * \brief Sets the low temperature threshold for the interrupt pin.
232 *
233 * \param temp Temperature threshold in degrees Celsius (-40 to 125).
234 */
235void setLowTemp(float temp) {
236 uint8_t temp_thresh_low;
237
238 // Verify user is not trying to set value outside bounds
239 if (temp < -40.0f) {
240 temp = -40.0f;
241 } else if (temp > 125.0f) {
242 temp = 125.0f;
243 }
244
245 // Calculate value to load into register
246 temp_thresh_low = (uint8_t)(256.0f * (temp + 40.0f) / 165.0f);
247
248 writeReg(TEMP_THR_L, &temp_thresh_low, 1);
249}
250
251/**
252 * \fn void setHighTemp(float temp)
253 *
254 * \brief Sets the high temperature threshold for the interrupt pin.
255 *
256 * \param temp Temperature threshold in degrees Celsius (-40 to 125).
257 */
258void setHighTemp(float temp) {
259 uint8_t temp_thresh_high;
260
261 // Verify user is not trying to set value outside bounds
262 if (temp < -40.0f) {
263 temp = -40.0f;
264 } else if (temp > 125.0f) {
265 temp = 125.0f;
266 }
267
268 // Calculate value to load into register
269 temp_thresh_high = (uint8_t)(256.0f * (temp + 40.0f) / 165.0f);
270
271 writeReg(TEMP_THR_H, &temp_thresh_high, 1);
272}
273
274/**
275 * \fn void setHighHumidity(float humid)
276 *
277 * \brief Sets the high humidity threshold for the interrupt pin.
278 *
279 * \param humid Humidity threshold in percentage (0 to 100).
280 */
281void setHighHumidity(float humid) {
282 uint8_t humid_thresh;
283
284 // Verify user is not trying to set value outside bounds
285 if (humid < 0.0f) {
286 humid = 0.0f;
287 } else if (humid > 100.0f) {
288 humid = 100.0f;
289 }
290
291 // Calculate value to load into register
292 humid_thresh = (uint8_t)(256.0f * humid / 100.0f);
293
294 writeReg(HUMID_THR_H, &humid_thresh, 1);
295}
296
297/**
298 * \fn void setLowHumidity(float humid)
299 *
300 * \brief Sets the low humidity threshold for the interrupt pin.
301 *
302 * \param humid Humidity threshold in percentage (0 to 100).
303 */
304void setLowHumidity(float humid) {
305 uint8_t humid_thresh;
306
307 // Verify user is not trying to set value outside bounds
308 if (humid < 0.0f) {
309 humid = 0.0f;
310 } else if (humid > 100.0f) {
311 humid = 100.0f;
312 }
313
314 // Calculate value to load into register
315 humid_thresh = (uint8_t)(256.0f * humid / 100.0f);
316
317 writeReg(HUMID_THR_L, &humid_thresh, 1);
318}
319
320/**
321 * \fn float readLowHumidityThreshold(void)
322 *
323 * \brief Reads the low humidity threshold currently set in the sensor.
324 *
325 * \return Humidity threshold as a percentage.
326 */
328 int err;
329 uint8_t regContents;
330
331 err = readReg(HUMID_THR_L, &regContents, 1);
332 float f = regContents;
333 f = f * 100.0f / 256.0f;
334 return f;
335}
336
337/**
338 * \fn float readHighHumidityThreshold(void)
339 *
340 * \brief Reads the high humidity threshold currently set in the sensor.
341 *
342 * \return Humidity threshold as a percentage.
343 */
345 int err;
346 uint8_t regContents;
347
348 err = readReg(HUMID_THR_H, &regContents, 1);
349 float f = regContents;
350 f = f * 100.0f / 256.0f;
351 return f;
352}
353
354/**
355 * \fn float readLowTempThreshold(void)
356 *
357 * \brief Reads the low temperature threshold currently set in the sensor.
358 *
359 * \return Temperature threshold in degrees Celsius.
360 */
362 int err;
363 uint8_t regContents;
364
365 err = readReg(TEMP_THR_L, &regContents, 1);
366 float f = regContents;
367 f = (f * 165.0f / 256.0f) - 40.0f;
368 return f;
369}
370
371/**
372 * \fn float readHighTempThreshold(void)
373 *
374 * \brief Reads the high temperature threshold currently set in the sensor.
375 *
376 * \return Temperature threshold in degrees Celsius.
377 */
379 int err;
380 uint8_t regContents;
381
382 err = readReg(TEMP_THR_H, &regContents, 1);
383 float f = regContents;
384 f = (f * 165.0f / 256.0f) - 40.0f;
385
386 return f;
387}
388
389/* Upper two bits of the MEASUREMENT_CONFIG register controls
390 the temperature resolution*/
391/**
392 * \fn void setTempRes(int resolution)
393 *
394 * \brief Sets the temperature measurement resolution.
395 *
396 * \param resolution 0 for 14-bit, 1 for 11-bit, 2 for 9-bit.
397 */
398void setTempRes(int resolution) {
399 int err;
400 uint8_t configContents;
401
402 /* Read current measurement configuration */
403 err = readReg(MEASUREMENT_CONFIG, &configContents, 1);
404
405 switch (resolution) {
406 case FOURTEEN_BIT:
407 configContents = (configContents & 0x3F);
408 break;
409
410 case ELEVEN_BIT:
411 configContents = (configContents & 0x7F);
412 configContents = (configContents | 0x40);
413 break;
414
415 case NINE_BIT:
416 configContents = (configContents & 0xBF);
417 configContents = (configContents | 0x80);
418 break;
419
420 default:
421 configContents = (configContents & 0x3F);
422 }
423
424 /* Write updated resolution bits back to sensor */
425 writeReg(MEASUREMENT_CONFIG, &configContents, 1);
426}
427
428/* Bits 5 and 6 of the MEASUREMENT_CONFIG register controls
429 the humidity resolution*/
430/**
431 * \fn void setHumidRes(int resolution)
432 *
433 * \brief Sets the humidity measurement resolution.
434 *
435 * \param resolution 0 for 14-bit, 1 for 11-bit, 2 for 9-bit.
436 */
437void setHumidRes(int resolution) {
438 int err;
439 uint8_t configContents;
440
441 err = readReg(MEASUREMENT_CONFIG, &configContents, 1);
442
443 switch (resolution) {
444 case FOURTEEN_BIT:
445 configContents = (configContents & 0xCF);
446 break;
447
448 case ELEVEN_BIT:
449 configContents = (configContents & 0xDF);
450 configContents = (configContents | 0x10);
451 break;
452
453 case NINE_BIT:
454 configContents = (configContents & 0xEF);
455 configContents = (configContents | 0x20);
456 break;
457
458 default:
459 configContents = (configContents & 0xCF);
460 }
461
462 /* Write updated resolution bits back to sensor */
463 writeReg(MEASUREMENT_CONFIG, &configContents, 1);
464}
465
466/* Bits 2 and 1 of the MEASUREMENT_CONFIG register controls
467 the measurement mode */
468/**
469 * \fn void setMeasurementMode(int mode)
470 *
471 * \brief Configures whether the sensor measures Temp, Humidity, or both.
472 *
473 * \param mode 0: Temp & Humid, 1: Temp only, 2: Humid only.
474 */
475void setMeasurementMode(int mode) {
476 int err;
477 uint8_t configContents;
478
479 err = readReg(MEASUREMENT_CONFIG, &configContents, 1);
480
481 switch (mode) {
482 case TEMP_AND_HUMID:
483 configContents = (configContents & 0xF9);
484 break;
485
486 case TEMP_ONLY:
487 configContents = (configContents & 0xFC);
488 configContents = (configContents | 0x02);
489 break;
490
491 case HUMID_ONLY:
492 configContents = (configContents & 0xFD);
493 configContents = (configContents | 0x04);
494 break;
495
496 default:
497 configContents = (configContents & 0xF9);
498 }
499
500 /* Apply the measurement mode to the configuration register */
501 writeReg(MEASUREMENT_CONFIG, &configContents, 1);
502}
503
504/* Bit 0 of the MEASUREMENT_CONFIG register can be used
505 to trigger measurements */
506/**
507 * \fn void triggerMeasurement(void)
508 *
509 * \brief Manually triggers a single measurement cycle.
510 */
512 int err;
513 uint8_t configContents;
514
515 err = readReg(MEASUREMENT_CONFIG, &configContents, 1);
516
517 /* Set the trigger bit */
518 configContents = (configContents | 0x01);
519 writeReg(MEASUREMENT_CONFIG, &configContents, 1);
520}
521
522/* Bit 7 of the CONFIG register can be used to trigger a
523 soft reset */
524/**
525 * \fn void reset(void)
526 *
527 * \brief Performs a software reset on the HDC2080.
528 */
529void reset(void) {
530 int err;
531 uint8_t configContents;
532
533 err = readReg(HDC_CONFIG, &configContents, 1);
534
535 /* Set the soft reset bit */
536 configContents = (configContents | 0x80);
537 writeReg(HDC_CONFIG, &configContents, 1);
538 /* Wait for the device to reboot */
539 k_sleep(K_MSEC(50));
540}
541
542/* Bit 2 of the CONFIG register can be used to enable/disable
543 the interrupt pin */
544/**
545 * \fn void enableInterrupt(void)
546 *
547 * \brief Enables the physical interrupt/DRDY pin.
548 */
549void enableInterrupt(void) {
550 int err;
551 uint8_t configContents;
552
553 err = readReg(HDC_CONFIG, &configContents, 1);
554
555 /* Set the interrupt enable bit */
556 configContents = (configContents | 0x04);
557 writeReg(HDC_CONFIG, &configContents, 1);
558}
559
560/* Bit 2 of the CONFIG register can be used to enable/disable
561 the interrupt pin */
562/**
563 * \fn void disableInterrupt(void)
564 *
565 * \brief Disables the physical interrupt/DRDY pin (sets to High-Z).
566 */
568 int err;
569 uint8_t configContents;
570
571 err = readReg(HDC_CONFIG, &configContents, 1);
572
573 /* Clear the interrupt enable bit */
574 configContents = (configContents & 0xFB);
575 writeReg(HDC_CONFIG, &configContents, 1);
576}
577
578/**
579 * \fn void setRate(int rate)
580 *
581 * \brief Sets the automatic measurement frequency.
582 *
583 * \param rate Constant representing the frequency (e.g., ONE_HZ, FIVE_SECONDS).
584 */
585void setRate(int rate) {
586 int err;
587 uint8_t configContents;
588
589 err = readReg(HDC_CONFIG, &configContents, 1);
590
591 switch (rate) {
592 case MANUAL:
593 configContents = (configContents & 0x8F);
594 break;
595
596 case TWO_MINS:
597 configContents = (configContents & 0x9F);
598 configContents = (configContents | 0x10);
599 break;
600
601 case ONE_MINS:
602 configContents = (configContents & 0xAF);
603 configContents = (configContents | 0x20);
604 break;
605
606 case TEN_SECONDS:
607 configContents = (configContents & 0xBF);
608 configContents = (configContents | 0x30);
609 break;
610
611 case FIVE_SECONDS:
612 configContents = (configContents & 0xCF);
613 configContents = (configContents | 0x40);
614 break;
615
616 case ONE_HZ:
617 configContents = (configContents & 0xDF);
618 configContents = (configContents | 0x50);
619 break;
620
621 case TWO_HZ:
622 configContents = (configContents & 0xEF);
623 configContents = (configContents | 0x60);
624 break;
625
626 case FIVE_HZ:
627 configContents = (configContents | 0x70);
628 break;
629
630 default:
631 configContents = (configContents & 0x8F);
632 }
633
634 writeReg(HDC_CONFIG, &configContents, 1);
635}
636
637/**
638 * \fn void setInterruptPolarity(int polarity)
639 *
640 * \brief Configures the electrical behavior of the INT pin when active.
641 *
642 * \param polarity 0 for ACTIVE_LOW, 1 for ACTIVE_HIGH.
643 */
644void setInterruptPolarity(int polarity) {
645 int err;
646 uint8_t configContents;
647
648 err = readReg(HDC_CONFIG, &configContents, 1);
649
650 switch (polarity) {
651 case ACTIVE_LOW:
652 configContents = (configContents & 0xFD);
653 break;
654
655 case ACTIVE_HIGH:
656 configContents = (configContents | 0x02);
657 break;
658
659 default:
660 configContents = (configContents & 0xFD);
661 }
662
663 writeReg(HDC_CONFIG, &configContents, 1);
664}
665
666/**
667 * \fn void setInterruptMode(int mode)
668 *
669 * \brief Sets the interrupt pin to either level-sensitive or comparator mode.
670 *
671 * \param mode 0 for LEVEL_MODE, 1 for COMPARATOR_MODE.
672 */
673void setInterruptMode(int mode) {
674 int err;
675 uint8_t configContents;
676
677 err = readReg(HDC_CONFIG, &configContents, 1);
678
679 switch (mode) {
680 case LEVEL_MODE:
681 configContents = (configContents & 0xFE);
682 break;
683
684 case COMPARATOR_MODE:
685 configContents = (configContents | 0x01);
686 break;
687
688 default:
689 configContents = (configContents & 0xFE);
690 }
691
692 writeReg(HDC_CONFIG, &configContents, 1);
693}
694
695/**
696 * \fn uint8_t readInterruptStatus(void)
697 *
698 * \brief Reads the interrupt status register.
699 *
700 * \return Bitmask of triggered interrupts (DRDY, TH, TL, HH, HL).
701 */
702uint8_t readInterruptStatus(void) {
703 int err;
704 uint8_t regContents;
705
706 err = readReg(INTERRUPT_DRDY, &regContents, 1);
707 return regContents;
708}
709
710/**
711 * \fn void clearMaxTemp(void)
712 *
713 * \brief Resets the Maximum Temperature peak-hold register to 0.
714 */
715void clearMaxTemp(void) {
716 uint8_t value = 0;
717
718 writeReg(TEMP_MAX, &value, 1);
719}
720
721/**
722 * \fn void clearMaxHumidity(void)
723 *
724 * \brief Resets the Maximum Humidity peak-hold register to 0.
725 */
727 uint8_t value = 0;
728
729 writeReg(HUMID_MAX, &value, 1);
730}
731
732/**
733 * \fn float readMaxTemp(void)
734 *
735 * \brief Reads the highest temperature recorded since the last clear.
736 *
737 * \return Maximum temperature in degrees Celsius.
738 */
739float readMaxTemp(void) {
740 int err;
741 uint8_t regContents;
742
743 err = readReg(TEMP_MAX, &regContents, 1);
744 float f = regContents;
745 f = (f * 165.0f / 256.0f) - 40.0f;
746
747 return f;
748}
749
750/**
751 * \fn float readMaxHumidity(void)
752 *
753 * \brief Reads the maximum humidity recorded since the last clear.
754 *
755 * \return Maximum relative humidity as a percentage.
756 */
757float readMaxHumidity(void) {
758 int err;
759 uint8_t regContents;
760
761 err = readReg(HUMID_MAX, &regContents, 1);
762 float f = regContents;
763 f = (f / 256.0f) * 100.0f;
764
765 return f;
766}
767
768/**
769 * \fn void enableThresholdInterrupt(void)
770 *
771 * \brief Enables the high/low temperature and humidity threshold interrupts.
772 */
774 int err;
775 uint8_t regContents;
776
777 err = readReg(INTERRUPT_CONFIG, &regContents, 1);
778
779 regContents = (regContents | 0x78);
780
781 writeReg(INTERRUPT_CONFIG, &regContents, 1);
782}
783
784/**
785 * \fn void disableThresholdInterrupt(void)
786 *
787 * \brief Disables the high/low temperature and humidity threshold interrupts.
788 */
790 int err;
791 uint8_t regContents;
792
793 err = readReg(INTERRUPT_CONFIG, &regContents, 1);
794
795 regContents = (regContents & 0x87);
796
797 writeReg(INTERRUPT_CONFIG, &regContents, 1);
798}
799
800/**
801 * \fn void enableDRDYInterrupt(void)
802 *
803 * \brief Enables the Data Ready (DRDY) interrupt.
804 */
806 int err;
807 uint8_t regContents;
808
809 err = readReg(INTERRUPT_CONFIG, &regContents, 1);
810
811 regContents = (regContents | 0x80);
812
813 writeReg(INTERRUPT_CONFIG, &regContents, 1);
814}
815
816/**
817 * \fn void disableDRDYInterrupt(void)
818 *
819 * \brief Disables the Data Ready (DRDY) interrupt.
820 */
822 int err;
823 uint8_t regContents;
824
825 err = readReg(INTERRUPT_CONFIG, &regContents, 1);
826
827 regContents = (regContents & 0x7F);
828
829 writeReg(INTERRUPT_CONFIG, &regContents, 1);
830}
831
832/**
833 * \fn int initHDC2080(void)
834 *
835 * \brief Initializes the HDC2080 sensor with default parameters.
836 *
837 * \return TRUE if the sensor is found and initialized, FALSE otherwise.
838 */
839int initHDC2080(void) {
840 unsigned char datas[6] = {0};
841
842 /* Verify Manufacturer and Device ID */
843 ret = readReg(MID_L, datas, 4);
844 manfID = (datas[1] << 8) | datas[0];
845 deviceID = (datas[3] << 8) | datas[2];
846 myPrintkI("HDC2080 Manf: 0x%04X Device: 0x%04X\r\n", manfID, deviceID);
847 if ((manfID != MAN_ID) || (deviceID != DEV_ID) || (ret == FALSE)) {
848 // sprintf(myStr, "HDC2080 Manf: %04X Device: %04X\r\n", manfID, deviceID);
849 // myPrintkW(myStr);
850 myPrintkW("HDC2080 Temp/Humidty Sensor not found\r\n");
851 return FALSE;
852 }
853
854 /* initialize HDC2080 */
855 /* interrupt status 0x04 */
856 readInterruptStatus(); /* read status to clear */
857
858 /* TEMP_MAX 0x05 */
859 clearMaxTemp();
860
861 /* HUMIDITY_MAX 0x06 */
863
864 /* Interrupt Enable 0x07 */
865 // disableThresholdInterrupt(); /* disable temp/humidity low/high threshold interrupts */
866 enableThresholdInterrupt(); /* enable temp/humidity low/high threshold interrupts */
867 // disableDRDYInterrupt();
869
870 /* TEMP_OFFSET adjust 0x08 */
872
873 /* HUMIDITY_OFFSET adjust 0x09 */
875
876 /* Temperature Threshold adjust Low 0x0A */
877 setLowTemp(10.0);
878
879 /* Temperature Threshold adjust High 0x0B */
880 setHighTemp(30.0);
881
882 /* Humidity Threshold adjust Low 0x0C */
883 setLowHumidity(10.0);
884
885 /* Humidity Threshold adjust High 0x0D */
886 setHighHumidity(80.0);
887
888 /* CONFIG 0x0E*/
889 setInterruptMode(LEVEL_MODE); /* set interrupt mode */
890 setInterruptPolarity(ACTIVE_LOW); /* set interrupt polarity */
891
892 /* If manual trigger is enabled, we don't need the hardware interrupt pin active */
893 // if (flashParameters.manualTrigger) {
894 // myPrintkW("Manual trigger Enabled. Waiting for datetime command from gateway.\r\n");
895 // disableInterrupt();
896 // } else {
897 /* Otherwise, enable the INT pin to signal data ready or threshold alarms */
898 myPrintkW("HDC2080 automatic trigger Enabled\r\n");
900 // }
901
902 disableHeater(); /* dusable heater */
903
904 if (flashParameters.manualTrigger) {
905 setRate(MANUAL); /* set auto conversion rate */
906 } else {
907 setRate(TEN_SECONDS); /* set auto conversion rate */
908 }
909
910 /* MEASUREMENT_CONFIG 0x0F*/
911 // setMeasurementMode(TEMP_ONLY); /* set measurement mode */
912 // setMeasurementMode(HUMID_ONLY); /* set measurement mode */
913 setMeasurementMode(TEMP_AND_HUMID); /* set measurement mode */
914 setHumidRes(FOURTEEN_BIT); /* set humidity resolution */
915 setTempRes(FOURTEEN_BIT); /* set temperature resolution */
916 triggerMeasurement(); /* start measurement */
917
918 /* HDC2080 found */
920 myPrintkI("HDC2080 Temp/Humidty Present\r\n");
921 return TRUE;
922}
uint8_t readTempOffsetAdjust(void)
Reads the temperature offset adjustment value.
Definition HDC2080.c:46
void setInterruptPolarity(int polarity)
Configures the electrical behavior of the INT pin when active.
Definition HDC2080.c:644
void clearMaxHumidity(void)
Resets the Maximum Humidity peak-hold register to 0.
Definition HDC2080.c:726
uint8_t readReg(uint8_t reg, uint8_t *data, uint8_t count)
Reads a specified number of bytes from a sensor register over I2C.
Definition HDC2080.c:172
void enableThresholdInterrupt(void)
Enables the high/low temperature and humidity threshold interrupts.
Definition HDC2080.c:773
float readMaxTemp(void)
Reads the highest temperature recorded since the last clear.
Definition HDC2080.c:739
void reset(void)
Performs a software reset on the HDC2080.
Definition HDC2080.c:529
void setRate(int rate)
Sets the automatic measurement frequency.
Definition HDC2080.c:585
void setLowHumidity(float humid)
Sets the low humidity threshold for the interrupt pin.
Definition HDC2080.c:304
void enableInterrupt(void)
Enables the physical interrupt/DRDY pin.
Definition HDC2080.c:549
void setMeasurementMode(int mode)
Configures whether the sensor measures Temp, Humidity, or both.
Definition HDC2080.c:475
void enableHeater(void)
Enables the internal heating element of the HDC2080.
Definition HDC2080.c:133
float readMaxHumidity(void)
Reads the maximum humidity recorded since the last clear.
Definition HDC2080.c:757
void setTempRes(int resolution)
Sets the temperature measurement resolution.
Definition HDC2080.c:398
float readLowTempThreshold(void)
Reads the low temperature threshold currently set in the sensor.
Definition HDC2080.c:361
void setHighHumidity(float humid)
Sets the high humidity threshold for the interrupt pin.
Definition HDC2080.c:281
void setHumidRes(int resolution)
Sets the humidity measurement resolution.
Definition HDC2080.c:437
float readHighTempThreshold(void)
Reads the high temperature threshold currently set in the sensor.
Definition HDC2080.c:378
uint8_t setTempOffsetAdjust(uint8_t value)
Sets the temperature offset adjustment value.
Definition HDC2080.c:63
void setLowTemp(float temp)
Sets the low temperature threshold for the interrupt pin.
Definition HDC2080.c:235
float readHumidity(void)
Reads the relative humidity from the HDC2080 sensor.
Definition HDC2080.c:79
void setHighTemp(float temp)
Sets the high temperature threshold for the interrupt pin.
Definition HDC2080.c:258
uint8_t readHumidityOffsetAdjust(void)
Reads the humidity offset adjustment value from the sensor.
Definition HDC2080.c:101
void disableThresholdInterrupt(void)
Disables the high/low temperature and humidity threshold interrupts.
Definition HDC2080.c:789
uint8_t setHumidityOffsetAdjust(uint8_t value)
Sets the humidity offset adjustment value.
Definition HDC2080.c:119
int initHDC2080(void)
Initializes the HDC2080 sensor with default parameters.
Definition HDC2080.c:839
void triggerMeasurement(void)
Manually triggers a single measurement cycle.
Definition HDC2080.c:511
void enableDRDYInterrupt(void)
Enables the Data Ready (DRDY) interrupt.
Definition HDC2080.c:805
void disableHeater(void)
Disables the internal heating element of the HDC2080.
Definition HDC2080.c:150
float readHighHumidityThreshold(void)
Reads the high humidity threshold currently set in the sensor.
Definition HDC2080.c:344
void disableDRDYInterrupt(void)
Disables the Data Ready (DRDY) interrupt.
Definition HDC2080.c:821
float readLowHumidityThreshold(void)
Reads the low humidity threshold currently set in the sensor.
Definition HDC2080.c:327
void clearMaxTemp(void)
Resets the Maximum Temperature peak-hold register to 0.
Definition HDC2080.c:715
uint8_t writeReg(uint8_t reg, uint8_t *data, uint8_t count)
Writes a specified number of bytes to a sensor register over I2C.
Definition HDC2080.c:206
void disableInterrupt(void)
Disables the physical interrupt/DRDY pin (sets to High-Z).
Definition HDC2080.c:567
float readTemp(void)
Reads the temperature data from the HDC2080 sensor.
Definition HDC2080.c:24
uint8_t readInterruptStatus(void)
Reads the interrupt status register.
Definition HDC2080.c:702
void setInterruptMode(int mode)
Sets the interrupt pin to either level-sensitive or comparator mode.
Definition HDC2080.c:673
#define NINE_BIT
Definition HDC2080.h:18
#define TEN_SECONDS
Definition HDC2080.h:33
#define TEMP_OFFSET_ADJUST
Definition HDC2080.h:61
#define TEMP_AND_HUMID
Definition HDC2080.h:21
#define ELEVEN_BIT
Definition HDC2080.h:17
#define MID_L
Definition HDC2080.h:69
#define FIVE_SECONDS
Definition HDC2080.h:34
#define HUMID_ONLY
Definition HDC2080.h:23
#define INTERRUPT_CONFIG
Definition HDC2080.h:60
#define HUM_OFFSET_ADJUST
Definition HDC2080.h:62
#define FOURTEEN_BIT
Definition HDC2080.h:16
#define HDC_ADDRESS
Definition HDC2080.h:38
#define ACTIVE_HIGH
Definition HDC2080.h:25
#define MANUAL
Definition HDC2080.h:30
#define TEMP_ONLY
Definition HDC2080.h:22
#define INTERRUPT_DRDY
Definition HDC2080.h:57
#define MEASUREMENT_CONFIG
Definition HDC2080.h:68
#define ONE_MINS
Definition HDC2080.h:32
#define HDC_CONFIG
Definition HDC2080.h:67
#define HUMID_THR_H
Definition HDC2080.h:66
#define TEMP_LOW
Definition HDC2080.h:53
#define TEMP_MAX
Definition HDC2080.h:58
#define ONE_HZ
Definition HDC2080.h:35
#define TEMP_THR_H
Definition HDC2080.h:64
#define TWO_HZ
Definition HDC2080.h:36
#define HUMID_MAX
Definition HDC2080.h:59
#define COMPARATOR_MODE
Definition HDC2080.h:27
#define MAN_ID
Definition HDC2080.h:40
#define LEVEL_MODE
Definition HDC2080.h:26
#define HUMID_THR_L
Definition HDC2080.h:65
#define DEV_ID
Definition HDC2080.h:41
#define ACTIVE_LOW
Definition HDC2080.h:24
#define TWO_MINS
Definition HDC2080.h:31
#define HUMID_LOW
Definition HDC2080.h:55
#define FIVE_HZ
Definition HDC2080.h:37
#define TEMP_THR_L
Definition HDC2080.h:63
flashParametersStruct flashParameters
working valuses of flash parameters in RAM
Definition globals.c:35
uint16_t manfID
Definition globals.c:23
uint32_t sensorTypePresentAll
Definition globals.c:30
int ret
Definition globals.c:41
uint16_t deviceID
Definition globals.c:24
common struct, enum, externs, prototypes
int myPrintkI(char *restrict fmt,...)
prints an information message to the UART
Definition main.c:2386
const struct device *const i2c_dev
get the device structure for the I2C device defined by I2C_DEV_NODE
Definition main.c:106
#define TRUE
Definition jfet_common.h:42
#define FALSE
Definition jfet_common.h:41
@ SENSORTYPEHDC2080
Definition jfet_common.h:69
int myPrintkW(char *restrict fmt,...)
prints a warning message to the UART
Definition main.c:2353