LibDriver MAX31856
Loading...
Searching...
No Matches
driver_max31856.c
Go to the documentation of this file.
1
36
37#include "driver_max31856.h"
38
42#define CHIP_NAME "Maxim Integrated MAX31856"
43#define MANUFACTURER_NAME "Maxim Integrated"
44#define SUPPLY_VOLTAGE_MIN 3.0f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 2.0f
47#define TEMPERATURE_MIN -55.0f
48#define TEMPERATURE_MAX 125.0f
49#define DRIVER_VERSION 1000
50
54#define MAX31856_REG_CR0 0x00
55#define MAX31856_REG_CR1 0x01
56#define MAX31856_REG_MASK 0x02
57#define MAX31856_REG_CJHF 0x03
58#define MAX31856_REG_CJLF 0x04
59#define MAX31856_REG_LTHFTH 0x05
60#define MAX31856_REG_LTHFTL 0x06
61#define MAX31856_REG_LTLFTH 0x07
62#define MAX31856_REG_LTLFTL 0x08
63#define MAX31856_REG_CJTO 0x09
64#define MAX31856_REG_CJTH 0x0A
65#define MAX31856_REG_CJTL 0x0B
66#define MAX31856_REG_LTCBH 0x0C
67#define MAX31856_REG_LTCBM 0x0D
68#define MAX31856_REG_LTCBL 0x0E
69#define MAX31856_REG_SR 0x0F
70
82static uint8_t a_max31856_read(max31856_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
83{
84 if (handle->spi_read(reg, buf, len) != 0) /* read data */
85 {
86 return 1; /* return error */
87 }
88
89 return 0; /* success return 0 */
90}
91
103static uint8_t a_max31856_write(max31856_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
104{
105 if (handle->spi_write(0x80 | reg, buf, len) != 0) /* write data */
106 {
107 return 1; /* return error */
108 }
109
110 return 0; /* success return 0 */
111}
112
124{
125 if (handle == NULL) /* check handle */
126 {
127 return 2; /* return error */
128 }
129 if (handle->debug_print == NULL) /* check debug_print */
130 {
131 return 3; /* return error */
132 }
133 if (handle->spi_init == NULL) /* check spi_init */
134 {
135 handle->debug_print("max31856: spi_init is null.\n"); /* spi_init is null */
136
137 return 3; /* return error */
138 }
139 if (handle->spi_deinit == NULL) /* check spi_deinit */
140 {
141 handle->debug_print("max31856: spi_deinit is null.\n"); /* spi_deinit is null */
142
143 return 3; /* return error */
144 }
145 if (handle->spi_read == NULL) /* check spi_read */
146 {
147 handle->debug_print("max31856: spi_read is null.\n"); /* spi_read is null */
148
149 return 3; /* return error */
150 }
151 if (handle->spi_write == NULL) /* check spi_write */
152 {
153 handle->debug_print("max31856: spi_write is null.\n"); /* spi_write is null */
154
155 return 3; /* return error */
156 }
157 if (handle->delay_ms == NULL) /* check delay_ms */
158 {
159 handle->debug_print("max31856: delay_ms is null.\n"); /* delay_ms is null */
160
161 return 3; /* return error */
162 }
163 if (handle->receive_callback == NULL) /* check receive_callback */
164 {
165 handle->debug_print("max31856: receive_callback is null.\n"); /* receive_callback is null */
166
167 return 3; /* return error */
168 }
169
170 if (handle->spi_init() != 0) /* spi init */
171 {
172 handle->debug_print("max31856: spi init failed.\n"); /* spi init failed */
173
174 return 1; /* return error */
175 }
176
177 handle->inited = 1; /* flag finish initialization */
178
179 return 0; /* success return 0 */
180}
181
194{
195 uint8_t res;
196 uint8_t prev;
197
198 if (handle == NULL) /* check handle */
199 {
200 return 2; /* return error */
201 }
202 if (handle->inited != 1) /* check handle initialization */
203 {
204 return 3; /* return error */
205 }
206
207 res = a_max31856_read(handle, MAX31856_REG_CR0, &prev, 1); /* read cr0 */
208 if (res != 0) /* check result */
209 {
210 handle->debug_print("max31856: read cr0 failed.\n"); /* read cr0 failed */
211
212 return 4; /* return error */
213 }
214 prev &= ~(1 << 7); /* clear settings */
215 res = a_max31856_write(handle, MAX31856_REG_CR0, &prev, 1); /* write cr0 */
216 if (res != 0) /* check result */
217 {
218 handle->debug_print("max31856: write cr0 failed.\n"); /* write cr0 failed */
219
220 return 4; /* return error */
221 }
222
223 res = handle->spi_deinit(); /* spi deinit */
224 if (res != 0) /* check result */
225 {
226 handle->debug_print("max31856: spi deinit failed.\n"); /* spi deinit failed */
227
228 return 1; /* return error */
229 }
230 handle->inited = 0; /* flag close */
231
232 return 0; /* success return 0 */
233}
234
252uint8_t max31856_single_read(max31856_handle_t *handle, int32_t *raw, double *deg)
253{
254 uint8_t res;
255 uint8_t prev;
256 uint8_t buf[3];
257 uint16_t timeout;
258 uint16_t i;
259 uint32_t temp_raw;
260
261 if (handle == NULL) /* check handle */
262 {
263 return 2; /* return error */
264 }
265 if (handle->inited != 1) /* check handle initialization */
266 {
267 return 3; /* return error */
268 }
269
270 res = a_max31856_read(handle, MAX31856_REG_CR0, &prev, 1); /* read cr0 */
271 if (res != 0) /* check result */
272 {
273 handle->debug_print("max31856: read cr0 failed.\n"); /* read cr0 failed */
274
275 return 1; /* return error */
276 }
277 prev &= ~(1 << 7); /* clear settings */
278 prev |= 1 << 6; /* set bool */
279 res = a_max31856_write(handle, MAX31856_REG_CR0, &prev, 1); /* write cr0 */
280 if (res != 0) /* check result */
281 {
282 handle->debug_print("max31856: write cr0 failed.\n"); /* write cr0 failed */
283
284 return 1; /* return error */
285 }
286
287 timeout = 200; /* 2s timeout */
288 for (i = 0; i < timeout; i++) /* loop */
289 {
290 res = a_max31856_read(handle, MAX31856_REG_CR0, &prev, 1); /* read cr0 */
291 if (res != 0) /* check result */
292 {
293 handle->debug_print("max31856: read cr0 failed.\n"); /* read cr0 failed */
294
295 return 1; /* return error */
296 }
297 if (((prev >> 6) & 0x01) == 0) /* check bit */
298 {
299 break; /* break */
300 }
301 handle->delay_ms(10); /* delay 10ms */
302 }
303 if (i >= timeout) /* check timeout */
304 {
305 handle->debug_print("max31856: read timeout.\n"); /* read timeout */
306
307 return 4; /* return error */
308 }
309
310 res = a_max31856_read(handle, MAX31856_REG_SR, &prev, 1); /* read fault status */
311 if (res != 0) /* check result */
312 {
313 handle->debug_print("max31856: read fault status failed.\n"); /* read fault status failed */
314
315 return 1; /* return error */
316 }
317 if (((prev >> 0) & 0x01) != 0) /* check open circuit fault */
318 {
319 handle->debug_print("max31856: open circuit fault.\n"); /* open circuit fault */
320
321 return 5; /* return error */
322 }
323 if (((prev >> 1) & 0x01) != 0) /* check overvoltage or undervoltage input fault */
324 {
325 handle->debug_print("max31856: overvoltage or undervoltage input fault.\n"); /* overvoltage or undervoltage input fault */
326
327 return 6; /* return error */
328 }
329 if (((prev >> 6) & 0x01) != 0) /* check thermocouple out of range */
330 {
331 handle->debug_print("max31856: thermocouple out of range.\n"); /* thermocouple out of range */
332
333 return 7; /* return error */
334 }
335 if (((prev >> 7) & 0x01) != 0) /* check cold junction out of range */
336 {
337 handle->debug_print("max31856: cold junction out of range.\n"); /* cold junction out of range */
338
339 return 8; /* return error */
340 }
341 res = a_max31856_read(handle, MAX31856_REG_LTCBH, buf, 3); /* read linearized tc temperature */
342 if (res != 0) /* check result */
343 {
344 handle->debug_print("max31856: read linearized tc temperature failed.\n"); /* read linearized tc temperature failed */
345
346 return 1; /* return error */
347 }
348 temp_raw = ((uint32_t)buf[0] << 16 | (uint32_t)buf[1] << 8 |
349 (uint32_t)buf[2] << 0); /* make the raw data */
350 temp_raw = temp_raw >> 5; /* right shift */
351 if ((temp_raw & 0x00040000U) != 0) /* check sign bit */
352 {
353 temp_raw |= 0xFFF80000U; /* set negative */
354 }
355 *raw = (int32_t)temp_raw; /* save the raw data */
356 *deg = (double)(*raw) * 0.0078125; /* convert temperature */
357
358 return 0; /* success return 0 */
359}
360
378uint8_t max31856_continuous_read(max31856_handle_t *handle, int32_t *raw, double *deg)
379{
380 uint8_t res;
381 uint8_t prev;
382 uint8_t buf[3];
383 uint32_t temp_raw;
384
385 if (handle == NULL) /* check handle */
386 {
387 return 2; /* return error */
388 }
389 if (handle->inited != 1) /* check handle initialization */
390 {
391 return 3; /* return error */
392 }
393
394 res = a_max31856_read(handle, MAX31856_REG_SR, &prev, 1); /* read fault status */
395 if (res != 0) /* check result */
396 {
397 handle->debug_print("max31856: read fault status failed.\n"); /* read fault status failed */
398
399 return 1; /* return error */
400 }
401 if (((prev >> 0) & 0x01) != 0) /* check open circuit fault */
402 {
403 handle->debug_print("max31856: open circuit fault.\n"); /* open circuit fault */
404
405 return 4; /* return error */
406 }
407 if (((prev >> 1) & 0x01) != 0) /* check overvoltage or undervoltage input fault */
408 {
409 handle->debug_print("max31856: overvoltage or undervoltage input fault.\n"); /* overvoltage or undervoltage input fault */
410
411 return 5; /* return error */
412 }
413 if (((prev >> 6) & 0x01) != 0) /* check thermocouple out of range */
414 {
415 handle->debug_print("max31856: thermocouple out of range.\n"); /* thermocouple out of range */
416
417 return 6; /* return error */
418 }
419 if (((prev >> 7) & 0x01) != 0) /* check cold junction out of range */
420 {
421 handle->debug_print("max31856: cold junction out of range.\n"); /* cold junction out of range */
422
423 return 7; /* return error */
424 }
425 res = a_max31856_read(handle, MAX31856_REG_LTCBH, buf, 3); /* read linearized tc temperature */
426 if (res != 0) /* check result */
427 {
428 handle->debug_print("max31856: read linearized tc temperature failed.\n"); /* read linearized tc temperature failed */
429
430 return 1; /* return error */
431 }
432 temp_raw = ((uint32_t)buf[0] << 16 | (uint32_t)buf[1] << 8 |
433 (uint32_t)buf[2] << 0); /* make the raw data */
434 temp_raw = temp_raw >> 5; /* right shift */
435 if ((temp_raw & 0x00040000U) != 0) /* check sign bit */
436 {
437 temp_raw |= 0xFFF80000U; /* set negative */
438 }
439 *raw = (int32_t)temp_raw; /* save the raw data */
440 *deg = (double)(*raw) * 0.0078125; /* convert temperature */
441
442 return 0; /* success return 0 */
443}
444
456{
457 uint8_t res;
458 uint8_t prev;
459
460 if (handle == NULL) /* check handle */
461 {
462 return 2; /* return error */
463 }
464 if (handle->inited != 1) /* check handle initialization */
465 {
466 return 3; /* return error */
467 }
468
469 res = a_max31856_read(handle, MAX31856_REG_CR0, &prev, 1); /* read cr0 */
470 if (res != 0) /* check result */
471 {
472 handle->debug_print("max31856: read cr0 failed.\n"); /* read cr0 failed */
473
474 return 1; /* return error */
475 }
476 prev &= ~(1 << 7); /* clear settings */
477 prev |= 1 << 7; /* set bool */
478 prev &= ~(1 << 6); /* clear settings */
479 res = a_max31856_write(handle, MAX31856_REG_CR0, &prev, 1); /* write cr0 */
480 if (res != 0) /* check result */
481 {
482 handle->debug_print("max31856: write cr0 failed.\n"); /* write cr0 failed */
483
484 return 1; /* return error */
485 }
486
487 return 0; /* success return 0 */
488}
489
501{
502 uint8_t res;
503 uint8_t prev;
504
505 if (handle == NULL) /* check handle */
506 {
507 return 2; /* return error */
508 }
509 if (handle->inited != 1) /* check handle initialization */
510 {
511 return 3; /* return error */
512 }
513
514 res = a_max31856_read(handle, MAX31856_REG_CR0, &prev, 1); /* read cr0 */
515 if (res != 0) /* check result */
516 {
517 handle->debug_print("max31856: read cr0 failed.\n"); /* read cr0 failed */
518
519 return 1; /* return error */
520 }
521 prev &= ~(1 << 7); /* clear settings */
522 prev &= ~(1 << 6); /* clear settings */
523 res = a_max31856_write(handle, MAX31856_REG_CR0, &prev, 1); /* write cr0 */
524 if (res != 0) /* check result */
525 {
526 handle->debug_print("max31856: write cr0 failed.\n"); /* write cr0 failed */
527
528 return 1; /* return error */
529 }
530
531 return 0; /* success return 0 */
532}
533
546uint8_t max31856_read_cold_junction_temperature(max31856_handle_t *handle, int16_t *raw, double *deg)
547{
548 uint8_t res;
549 uint8_t buf[2];
550 uint16_t temp_raw;
551
552 if (handle == NULL) /* check handle */
553 {
554 return 2; /* return error */
555 }
556 if (handle->inited != 1) /* check handle initialization */
557 {
558 return 3; /* return error */
559 }
560
561 res = a_max31856_read(handle, MAX31856_REG_CJTH, buf, 2); /* read cold junction temperature */
562 if (res != 0) /* check result */
563 {
564 handle->debug_print("max31856: read cold junction temperature failed.\n"); /* read cold junction temperature failed */
565
566 return 1; /* return error */
567 }
568 temp_raw = ((uint16_t)buf[0] << 8) | (uint16_t)buf[1]; /* set temperature */
569 temp_raw = temp_raw >> 2; /* right shift */
570 if ((temp_raw & 0x2000U) != 0) /* check sign bit */
571 {
572 temp_raw |= 0xC000U; /* set negative */
573 }
574 *raw = (int16_t)temp_raw; /* save the raw data */
575 *deg = (double)(*raw) * 0.015625; /* convert temperature */
576
577 return 0; /* success return 0 */
578}
579
592{
593 uint8_t res;
594 uint8_t prev;
595
596 if (handle == NULL) /* check handle */
597 {
598 return 2; /* return error */
599 }
600 if (handle->inited != 1) /* check handle initialization */
601 {
602 return 3; /* return error */
603 }
604
605 res = a_max31856_read(handle, MAX31856_REG_CR0, &prev, 1); /* read cr0 */
606 if (res != 0) /* check result */
607 {
608 handle->debug_print("max31856: read cr0 failed.\n"); /* read cr0 failed */
609
610 return 1; /* return error */
611 }
612 prev &= ~(3 << 4); /* clear settings */
613 prev |= detection << 4; /* set detection */
614 res = a_max31856_write(handle, MAX31856_REG_CR0, &prev, 1); /* write cr0 */
615 if (res != 0) /* check result */
616 {
617 handle->debug_print("max31856: write cr0 failed.\n"); /* write cr0 failed */
618
619 return 1; /* return error */
620 }
621
622 return 0; /* success return 0 */
623}
624
637{
638 uint8_t res;
639 uint8_t prev;
640
641 if (handle == NULL) /* check handle */
642 {
643 return 2; /* return error */
644 }
645 if (handle->inited != 1) /* check handle initialization */
646 {
647 return 3; /* return error */
648 }
649
650 res = a_max31856_read(handle, MAX31856_REG_CR0, &prev, 1); /* read cr0 */
651 if (res != 0) /* check result */
652 {
653 handle->debug_print("max31856: read cr0 failed.\n"); /* read cr0 failed */
654
655 return 1; /* return error */
656 }
657 *detection = (max31856_open_circuit_detection_t)((prev >> 4) & 0x03); /* set detection */
658
659 return 0; /* success return 0 */
660}
661
674{
675 uint8_t res;
676 uint8_t prev;
677
678 if (handle == NULL) /* check handle */
679 {
680 return 2; /* return error */
681 }
682 if (handle->inited != 1) /* check handle initialization */
683 {
684 return 3; /* return error */
685 }
686
687 res = a_max31856_read(handle, MAX31856_REG_CR0, &prev, 1); /* read cr0 */
688 if (res != 0) /* check result */
689 {
690 handle->debug_print("max31856: read cr0 failed.\n"); /* read cr0 failed */
691
692 return 1; /* return error */
693 }
694 prev &= ~(1 << 3); /* clear settings */
695 prev |= !enable << 3; /* set bool */
696 res = a_max31856_write(handle, MAX31856_REG_CR0, &prev, 1); /* write cr0 */
697 if (res != 0) /* check result */
698 {
699 handle->debug_print("max31856: write cr0 failed.\n"); /* write cr0 failed */
700
701 return 1; /* return error */
702 }
703
704 return 0; /* success return 0 */
705}
706
719{
720 uint8_t res;
721 uint8_t prev;
722
723 if (handle == NULL) /* check handle */
724 {
725 return 2; /* return error */
726 }
727 if (handle->inited != 1) /* check handle initialization */
728 {
729 return 3; /* return error */
730 }
731
732 res = a_max31856_read(handle, MAX31856_REG_CR0, &prev, 1); /* read cr0 */
733 if (res != 0) /* check result */
734 {
735 handle->debug_print("max31856: read cr0 failed.\n"); /* read cr0 failed */
736
737 return 1; /* return error */
738 }
739 *enable = (max31856_bool_t)(!((prev >> 3) & 0x01)); /* set bool */
740
741 return 0; /* success return 0 */
742}
743
756{
757 uint8_t res;
758 uint8_t prev;
759
760 if (handle == NULL) /* check handle */
761 {
762 return 2; /* return error */
763 }
764 if (handle->inited != 1) /* check handle initialization */
765 {
766 return 3; /* return error */
767 }
768
769 res = a_max31856_read(handle, MAX31856_REG_CR0, &prev, 1); /* read cr0 */
770 if (res != 0) /* check result */
771 {
772 handle->debug_print("max31856: read cr0 failed.\n"); /* read cr0 failed */
773
774 return 1; /* return error */
775 }
776 prev &= ~(1 << 2); /* clear settings */
777 prev |= mode << 2; /* set mode */
778 res = a_max31856_write(handle, MAX31856_REG_CR0, &prev, 1); /* write cr0 */
779 if (res != 0) /* check result */
780 {
781 handle->debug_print("max31856: write cr0 failed.\n"); /* write cr0 failed */
782
783 return 1; /* return error */
784 }
785
786 return 0; /* success return 0 */
787}
788
801{
802 uint8_t res;
803 uint8_t prev;
804
805 if (handle == NULL) /* check handle */
806 {
807 return 2; /* return error */
808 }
809 if (handle->inited != 1) /* check handle initialization */
810 {
811 return 3; /* return error */
812 }
813
814 res = a_max31856_read(handle, MAX31856_REG_CR0, &prev, 1); /* read cr0 */
815 if (res != 0) /* check result */
816 {
817 handle->debug_print("max31856: read cr0 failed.\n"); /* read cr0 failed */
818
819 return 1; /* return error */
820 }
821 *mode = (max31856_fault_mode_t)((prev >> 2) & 0x01); /* set mode */
822
823 return 0; /* success return 0 */
824}
825
837{
838 uint8_t res;
839 uint8_t prev;
840
841 if (handle == NULL) /* check handle */
842 {
843 return 2; /* return error */
844 }
845 if (handle->inited != 1) /* check handle initialization */
846 {
847 return 3; /* return error */
848 }
849
850 res = a_max31856_read(handle, MAX31856_REG_CR0, &prev, 1); /* read cr0 */
851 if (res != 0) /* check result */
852 {
853 handle->debug_print("max31856: read cr0 failed.\n"); /* read cr0 failed */
854
855 return 1; /* return error */
856 }
857 prev &= ~(1 << 1); /* clear settings */
858 prev |= 1 << 1; /* set bool */
859 res = a_max31856_write(handle, MAX31856_REG_CR0, &prev, 1); /* write cr0 */
860 if (res != 0) /* check result */
861 {
862 handle->debug_print("max31856: write cr0 failed.\n"); /* write cr0 failed */
863
864 return 1; /* return error */
865 }
866
867 return 0; /* success return 0 */
868}
869
882{
883 uint8_t res;
884 uint8_t prev;
885
886 if (handle == NULL) /* check handle */
887 {
888 return 2; /* return error */
889 }
890 if (handle->inited != 1) /* check handle initialization */
891 {
892 return 3; /* return error */
893 }
894
895 res = a_max31856_read(handle, MAX31856_REG_CR0, &prev, 1); /* read cr0 */
896 if (res != 0) /* check result */
897 {
898 handle->debug_print("max31856: read cr0 failed.\n"); /* read cr0 failed */
899
900 return 1; /* return error */
901 }
902 prev &= ~(1 << 0); /* clear settings */
903 prev |= filter << 0; /* set filter */
904 res = a_max31856_write(handle, MAX31856_REG_CR0, &prev, 1); /* write cr0 */
905 if (res != 0) /* check result */
906 {
907 handle->debug_print("max31856: write cr0 failed.\n"); /* write cr0 failed */
908
909 return 1; /* return error */
910 }
911
912 return 0; /* success return 0 */
913}
914
927{
928 uint8_t res;
929 uint8_t prev;
930
931 if (handle == NULL) /* check handle */
932 {
933 return 2; /* return error */
934 }
935 if (handle->inited != 1) /* check handle initialization */
936 {
937 return 3; /* return error */
938 }
939
940 res = a_max31856_read(handle, MAX31856_REG_CR0, &prev, 1); /* read cr0 */
941 if (res != 0) /* check result */
942 {
943 handle->debug_print("max31856: read cr0 failed.\n"); /* read cr0 failed */
944
945 return 1; /* return error */
946 }
947 *filter = (max31856_noise_rejection_filter_t)((prev >> 0) & 0x01); /* set noise rejection filter */
948
949 return 0; /* success return 0 */
950}
951
964{
965 uint8_t res;
966 uint8_t prev;
967
968 if (handle == NULL) /* check handle */
969 {
970 return 2; /* return error */
971 }
972 if (handle->inited != 1) /* check handle initialization */
973 {
974 return 3; /* return error */
975 }
976
977 res = a_max31856_read(handle, MAX31856_REG_CR1, &prev, 1); /* read cr1 */
978 if (res != 0) /* check result */
979 {
980 handle->debug_print("max31856: read cr1 failed.\n"); /* read cr1 failed */
981
982 return 1; /* return error */
983 }
984 prev &= ~(7 << 4); /* clear settings */
985 prev |= average << 4; /* set average */
986 res = a_max31856_write(handle, MAX31856_REG_CR1, &prev, 1); /* write cr1 */
987 if (res != 0) /* check result */
988 {
989 handle->debug_print("max31856: write cr1 failed.\n"); /* write cr1 failed */
990
991 return 1; /* return error */
992 }
993
994 return 0; /* success return 0 */
995}
996
1009{
1010 uint8_t res;
1011 uint8_t prev;
1012
1013 if (handle == NULL) /* check handle */
1014 {
1015 return 2; /* return error */
1016 }
1017 if (handle->inited != 1) /* check handle initialization */
1018 {
1019 return 3; /* return error */
1020 }
1021
1022 res = a_max31856_read(handle, MAX31856_REG_CR1, &prev, 1); /* read cr1 */
1023 if (res != 0) /* check result */
1024 {
1025 handle->debug_print("max31856: read cr1 failed.\n"); /* read cr1 failed */
1026
1027 return 1; /* return error */
1028 }
1029 *average = (max31856_sample_average_t)((prev >> 4) & 0x07); /* set average */
1030
1031 return 0; /* success return 0 */
1032}
1033
1046{
1047 uint8_t res;
1048 uint8_t prev;
1049
1050 if (handle == NULL) /* check handle */
1051 {
1052 return 2; /* return error */
1053 }
1054 if (handle->inited != 1) /* check handle initialization */
1055 {
1056 return 3; /* return error */
1057 }
1058
1059 res = a_max31856_read(handle, MAX31856_REG_CR1, &prev, 1); /* read cr1 */
1060 if (res != 0) /* check result */
1061 {
1062 handle->debug_print("max31856: read cr1 failed.\n"); /* read cr1 failed */
1063
1064 return 1; /* return error */
1065 }
1066 prev &= ~(0xF << 0); /* clear settings */
1067 prev |= type << 0; /* set type */
1068 res = a_max31856_write(handle, MAX31856_REG_CR1, &prev, 1); /* write cr1 */
1069 if (res != 0) /* check result */
1070 {
1071 handle->debug_print("max31856: write cr1 failed.\n"); /* write cr1 failed */
1072
1073 return 1; /* return error */
1074 }
1075
1076 return 0; /* success return 0 */
1077}
1078
1091{
1092 uint8_t res;
1093 uint8_t prev;
1094
1095 if (handle == NULL) /* check handle */
1096 {
1097 return 2; /* return error */
1098 }
1099 if (handle->inited != 1) /* check handle initialization */
1100 {
1101 return 3; /* return error */
1102 }
1103
1104 res = a_max31856_read(handle, MAX31856_REG_CR1, &prev, 1); /* read cr1 */
1105 if (res != 0) /* check result */
1106 {
1107 handle->debug_print("max31856: read cr1 failed.\n"); /* read cr1 failed */
1108
1109 return 1; /* return error */
1110 }
1111 *type = (max31856_thermocouple_type_t)((prev >> 0) & 0x0F); /* set thermocouple type */
1112
1113 return 0; /* success return 0 */
1114}
1115
1129{
1130 uint8_t res;
1131 uint8_t prev;
1132
1133 if (handle == NULL) /* check handle */
1134 {
1135 return 2; /* return error */
1136 }
1137 if (handle->inited != 1) /* check handle initialization */
1138 {
1139 return 3; /* return error */
1140 }
1141
1142 res = a_max31856_read(handle, MAX31856_REG_MASK, &prev, 1); /* read mask */
1143 if (res != 0) /* check result */
1144 {
1145 handle->debug_print("max31856: read mask failed.\n"); /* read mask failed */
1146
1147 return 1; /* return error */
1148 }
1149 prev &= ~(1 << mask); /* clear settings */
1150 prev |= enable << mask; /* set bool */
1151 res = a_max31856_write(handle, MAX31856_REG_MASK, &prev, 1); /* write mask */
1152 if (res != 0) /* check result */
1153 {
1154 handle->debug_print("max31856: write mask failed.\n"); /* write mask failed */
1155
1156 return 1; /* return error */
1157 }
1158
1159 return 0; /* success return 0 */
1160}
1161
1175{
1176 uint8_t res;
1177 uint8_t prev;
1178
1179 if (handle == NULL) /* check handle */
1180 {
1181 return 2; /* return error */
1182 }
1183 if (handle->inited != 1) /* check handle initialization */
1184 {
1185 return 3; /* return error */
1186 }
1187
1188 res = a_max31856_read(handle, MAX31856_REG_MASK, &prev, 1); /* read mask */
1189 if (res != 0) /* check result */
1190 {
1191 handle->debug_print("max31856: read mask failed.\n"); /* read mask failed */
1192
1193 return 1; /* return error */
1194 }
1195 *enable = (max31856_bool_t)((prev >> mask) & 0x01); /* set bool */
1196
1197 return 0; /* success return 0 */
1198}
1199
1212{
1213 uint8_t res;
1214 uint8_t prev;
1215
1216 if (handle == NULL) /* check handle */
1217 {
1218 return 2; /* return error */
1219 }
1220 if (handle->inited != 1) /* check handle initialization */
1221 {
1222 return 3; /* return error */
1223 }
1224
1225 prev = (uint8_t)(threshold); /* set threshold */
1226 res = a_max31856_write(handle, MAX31856_REG_CJHF, &prev, 1); /* write cold junction high fault threshold */
1227 if (res != 0) /* check result */
1228 {
1229 handle->debug_print("max31856: write cold junction high fault threshold failed.\n"); /* write cold junction high fault threshold failed */
1230
1231 return 1; /* return error */
1232 }
1233
1234 return 0; /* success return 0 */
1235}
1236
1249{
1250 uint8_t res;
1251 uint8_t prev;
1252
1253 if (handle == NULL) /* check handle */
1254 {
1255 return 2; /* return error */
1256 }
1257 if (handle->inited != 1) /* check handle initialization */
1258 {
1259 return 3; /* return error */
1260 }
1261
1262 res = a_max31856_read(handle, MAX31856_REG_CJHF, &prev, 1); /* read cold junction high fault threshold */
1263 if (res != 0) /* check result */
1264 {
1265 handle->debug_print("max31856: read cold junction high fault threshold failed.\n"); /* read cold junction high fault threshold failed */
1266
1267 return 1; /* return error */
1268 }
1269 *threshold = (int8_t)(prev); /* set threshold */
1270
1271 return 0; /* success return 0 */
1272}
1273
1286{
1287 uint8_t res;
1288 uint8_t prev;
1289
1290 if (handle == NULL) /* check handle */
1291 {
1292 return 2; /* return error */
1293 }
1294 if (handle->inited != 1) /* check handle initialization */
1295 {
1296 return 3; /* return error */
1297 }
1298
1299 prev = (uint8_t)(threshold); /* set threshold */
1300 res = a_max31856_write(handle, MAX31856_REG_CJLF, &prev, 1); /* write cold junction low fault threshold */
1301 if (res != 0) /* check result */
1302 {
1303 handle->debug_print("max31856: write cold junction low fault threshold failed.\n"); /* write cold junction low fault threshold failed */
1304
1305 return 1; /* return error */
1306 }
1307
1308 return 0; /* success return 0 */
1309}
1310
1323{
1324 uint8_t res;
1325 uint8_t prev;
1326
1327 if (handle == NULL) /* check handle */
1328 {
1329 return 2; /* return error */
1330 }
1331 if (handle->inited != 1) /* check handle initialization */
1332 {
1333 return 3; /* return error */
1334 }
1335
1336 res = a_max31856_read(handle, MAX31856_REG_CJLF, &prev, 1); /* read cold junction low fault threshold */
1337 if (res != 0) /* check result */
1338 {
1339 handle->debug_print("max31856: read cold junction low fault threshold failed.\n"); /* read cold junction low fault threshold failed */
1340
1341 return 1; /* return error */
1342 }
1343 *threshold = (int8_t)(prev); /* set threshold */
1344
1345 return 0; /* success return 0 */
1346}
1347
1360{
1361 uint8_t res;
1362 uint8_t buf[2];
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 buf[0] = (threshold >> 8) & 0xFF; /* set msb */
1374 buf[1] = (threshold >> 0) & 0xFF; /* set lsb */
1375 res = a_max31856_write(handle, MAX31856_REG_LTHFTH, buf, 2); /* write temperature high fault threshold */
1376 if (res != 0) /* check result */
1377 {
1378 handle->debug_print("max31856: write temperature high fault threshold failed.\n"); /* write temperature high fault threshold failed */
1379
1380 return 1; /* return error */
1381 }
1382
1383 return 0; /* success return 0 */
1384}
1385
1398{
1399 uint8_t res;
1400 uint8_t buf[2];
1401
1402 if (handle == NULL) /* check handle */
1403 {
1404 return 2; /* return error */
1405 }
1406 if (handle->inited != 1) /* check handle initialization */
1407 {
1408 return 3; /* return error */
1409 }
1410
1411 res = a_max31856_read(handle, MAX31856_REG_LTHFTH, buf, 2); /* read temperature high fault threshold */
1412 if (res != 0) /* check result */
1413 {
1414 handle->debug_print("max31856: read temperature high fault threshold failed.\n"); /* read temperature high fault threshold failed */
1415
1416 return 1; /* return error */
1417 }
1418 *threshold = (int16_t)((uint16_t)buf[0] << 8 | buf[1]); /* set threshold */
1419
1420 return 0; /* success return 0 */
1421}
1422
1435{
1436 uint8_t res;
1437 uint8_t buf[2];
1438
1439 if (handle == NULL) /* check handle */
1440 {
1441 return 2; /* return error */
1442 }
1443 if (handle->inited != 1) /* check handle initialization */
1444 {
1445 return 3; /* return error */
1446 }
1447
1448 buf[0] = (threshold >> 8) & 0xFF; /* set msb */
1449 buf[1] = (threshold >> 0) & 0xFF; /* set lsb */
1450 res = a_max31856_write(handle, MAX31856_REG_LTLFTH, buf, 2); /* write temperature low fault threshold */
1451 if (res != 0) /* check result */
1452 {
1453 handle->debug_print("max31856: write temperature low fault threshold failed.\n"); /* write temperature low fault threshold failed */
1454
1455 return 1; /* return error */
1456 }
1457
1458 return 0; /* success return 0 */
1459}
1460
1473{
1474 uint8_t res;
1475 uint8_t buf[2];
1476
1477 if (handle == NULL) /* check handle */
1478 {
1479 return 2; /* return error */
1480 }
1481 if (handle->inited != 1) /* check handle initialization */
1482 {
1483 return 3; /* return error */
1484 }
1485
1486 res = a_max31856_read(handle, MAX31856_REG_LTLFTH, buf, 2); /* read temperature low fault threshold */
1487 if (res != 0) /* check result */
1488 {
1489 handle->debug_print("max31856: read temperature low fault threshold failed.\n"); /* read temperature low fault threshold failed */
1490
1491 return 1; /* return error */
1492 }
1493 *threshold = (int16_t)((uint16_t)buf[0] << 8 | buf[1]); /* set threshold */
1494
1495 return 0; /* success return 0 */
1496}
1497
1510{
1511 uint8_t res;
1512 uint8_t prev;
1513
1514 if (handle == NULL) /* check handle */
1515 {
1516 return 2; /* return error */
1517 }
1518 if (handle->inited != 1) /* check handle initialization */
1519 {
1520 return 3; /* return error */
1521 }
1522
1523 prev = (uint8_t)(offset); /* set offset */
1524 res = a_max31856_write(handle, MAX31856_REG_CJTO, &prev, 1); /* write cold junction temperature offset */
1525 if (res != 0) /* check result */
1526 {
1527 handle->debug_print("max31856: write cold junction temperature offset failed.\n"); /* write cold junction temperature offset failed */
1528
1529 return 1; /* return error */
1530 }
1531
1532 return 0; /* success return 0 */
1533}
1534
1547{
1548 uint8_t res;
1549 uint8_t prev;
1550
1551 if (handle == NULL) /* check handle */
1552 {
1553 return 2; /* return error */
1554 }
1555 if (handle->inited != 1) /* check handle initialization */
1556 {
1557 return 3; /* return error */
1558 }
1559
1560 res = a_max31856_read(handle, MAX31856_REG_CJTO, &prev, 1); /* read cold junction temperature offset */
1561 if (res != 0) /* check result */
1562 {
1563 handle->debug_print("max31856: read cold junction temperature offset failed.\n"); /* read cold junction temperature offset failed */
1564
1565 return 1; /* return error */
1566 }
1567 *offset = (int8_t)(prev); /* set offset */
1568
1569 return 0; /* success return 0 */
1570}
1571
1584{
1585 uint8_t res;
1586 uint8_t buf[2];
1587
1588 if (handle == NULL) /* check handle */
1589 {
1590 return 2; /* return error */
1591 }
1592 if (handle->inited != 1) /* check handle initialization */
1593 {
1594 return 3; /* return error */
1595 }
1596
1597 buf[0] = (temperature >> 8) & 0xFF; /* set msb */
1598 buf[1] = (temperature >> 0) & 0xFF; /* set lsb */
1599 res = a_max31856_write(handle, MAX31856_REG_CJTH, buf, 2); /* write cold junction temperature */
1600 if (res != 0) /* check result */
1601 {
1602 handle->debug_print("max31856: write cold junction temperature failed.\n"); /* write cold junction temperature failed */
1603
1604 return 1; /* return error */
1605 }
1606
1607 return 0; /* success return 0 */
1608}
1609
1621uint8_t max31856_get_cold_junction_temperature(max31856_handle_t *handle, int16_t *temperature)
1622{
1623 uint8_t res;
1624 uint8_t buf[2];
1625
1626 if (handle == NULL) /* check handle */
1627 {
1628 return 2; /* return error */
1629 }
1630 if (handle->inited != 1) /* check handle initialization */
1631 {
1632 return 3; /* return error */
1633 }
1634
1635 res = a_max31856_read(handle, MAX31856_REG_CJTH, buf, 2); /* read cold junction temperature */
1636 if (res != 0) /* check result */
1637 {
1638 handle->debug_print("max31856: read cold junction temperature failed.\n"); /* read cold junction temperature failed */
1639
1640 return 1; /* return error */
1641 }
1642 *temperature = (int16_t)((uint16_t)buf[0] << 8 | buf[1]); /* set temperature */
1643
1644 return 0; /* success return 0 */
1645}
1646
1658uint8_t max31856_get_fault_status(max31856_handle_t *handle, uint8_t *status)
1659{
1660 uint8_t res;
1661 uint8_t prev;
1662
1663 if (handle == NULL) /* check handle */
1664 {
1665 return 2; /* return error */
1666 }
1667 if (handle->inited != 1) /* check handle initialization */
1668 {
1669 return 3; /* return error */
1670 }
1671
1672 res = a_max31856_read(handle, MAX31856_REG_SR, &prev, 1); /* read fault status */
1673 if (res != 0) /* check result */
1674 {
1675 handle->debug_print("max31856: read fault status failed.\n"); /* read fault status failed */
1676
1677 return 1; /* return error */
1678 }
1679 *status = prev; /* set status */
1680
1681 return 0; /* success return 0 */
1682}
1683
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
1706 *reg = (int8_t)(deg); /* convert real data to register data */
1707
1708 return 0; /* success return 0 */
1709}
1710
1723{
1724 if (handle == NULL) /* check handle */
1725 {
1726 return 2; /* return error */
1727 }
1728 if (handle->inited != 1) /* check handle initialization */
1729 {
1730 return 3; /* return error */
1731 }
1732
1733 *deg = (float)(reg); /* convert raw data to real data */
1734
1735 return 0; /* success return 0 */
1736}
1737
1750{
1751 if (handle == NULL) /* check handle */
1752 {
1753 return 2; /* return error */
1754 }
1755 if (handle->inited != 1) /* check handle initialization */
1756 {
1757 return 3; /* return error */
1758 }
1759
1760 *reg = (int16_t)(deg / 0.0625f); /* convert real data to register data */
1761
1762 return 0; /* success return 0 */
1763}
1764
1777{
1778 if (handle == NULL) /* check handle */
1779 {
1780 return 2; /* return error */
1781 }
1782 if (handle->inited != 1) /* check handle initialization */
1783 {
1784 return 3; /* return error */
1785 }
1786
1787 *deg = (float)(reg) * 0.0625f; /* convert raw data to real data */
1788
1789 return 0; /* success return 0 */
1790}
1791
1804{
1805 if (handle == NULL) /* check handle */
1806 {
1807 return 2; /* return error */
1808 }
1809 if (handle->inited != 1) /* check handle initialization */
1810 {
1811 return 3; /* return error */
1812 }
1813
1814 *reg = (int8_t)(deg / 0.0625f); /* convert real data to register data */
1815
1816 return 0; /* success return 0 */
1817}
1818
1831{
1832 if (handle == NULL) /* check handle */
1833 {
1834 return 2; /* return error */
1835 }
1836 if (handle->inited != 1) /* check handle initialization */
1837 {
1838 return 3; /* return error */
1839 }
1840
1841 *deg = (float)(reg) * 0.0625f; /* convert raw data to real data */
1842
1843 return 0; /* success return 0 */
1844}
1845
1858{
1859 if (handle == NULL) /* check handle */
1860 {
1861 return 2; /* return error */
1862 }
1863 if (handle->inited != 1) /* check handle initialization */
1864 {
1865 return 3; /* return error */
1866 }
1867
1868 *reg = (int16_t)(deg / 0.00390625f); /* convert real data to register data */
1869
1870 return 0; /* success return 0 */
1871}
1872
1885{
1886 if (handle == NULL) /* check handle */
1887 {
1888 return 2; /* return error */
1889 }
1890 if (handle->inited != 1) /* check handle initialization */
1891 {
1892 return 3; /* return error */
1893 }
1894
1895 *deg = (float)(reg) * 0.00390625f; /* convert raw data to real data */
1896
1897 return 0; /* success return 0 */
1898}
1899
1911{
1912 uint8_t res;
1913 uint8_t prev;
1914
1915 if (handle == NULL) /* check handle */
1916 {
1917 return 2; /* return error */
1918 }
1919 if (handle->inited != 1) /* check handle initialization */
1920 {
1921 return 3; /* return error */
1922 }
1923
1924 res = a_max31856_read(handle, MAX31856_REG_SR, &prev, 1); /* read fault status */
1925 if (res != 0) /* check result */
1926 {
1927 handle->debug_print("max31856: read fault status failed.\n"); /* read fault status failed */
1928
1929 return 1; /* return error */
1930 }
1931 if (((prev >> 7) & 0x01) != 0) /* check cold junction out of range */
1932 {
1933 if (handle->receive_callback != NULL) /* not null */
1934 {
1935 handle->receive_callback(MAX31856_FAULT_STATUS_CJRANGE); /* run the callback */
1936 }
1937 }
1938 if (((prev >> 6) & 0x01) != 0) /* check thermocouple out of range */
1939 {
1940 if (handle->receive_callback != NULL) /* not null */
1941 {
1942 handle->receive_callback(MAX31856_FAULT_STATUS_TCRANGE); /* run the callback */
1943 }
1944 }
1945 if (((prev >> 5) & 0x01) != 0) /* check cold junction high fault */
1946 {
1947 if (handle->receive_callback != NULL) /* not null */
1948 {
1949 handle->receive_callback(MAX31856_FAULT_STATUS_CJHIGH); /* run the callback */
1950 }
1951 }
1952 if (((prev >> 4) & 0x01) != 0) /* check cold junction low fault */
1953 {
1954 if (handle->receive_callback != NULL) /* not null */
1955 {
1956 handle->receive_callback(MAX31856_FAULT_STATUS_CJLOW); /* run the callback */
1957 }
1958 }
1959 if (((prev >> 3) & 0x01) != 0) /* check thermocouple temperature high fault */
1960 {
1961 if (handle->receive_callback != NULL) /* not null */
1962 {
1963 handle->receive_callback(MAX31856_FAULT_STATUS_TCHIGH); /* run the callback */
1964 }
1965 }
1966 if (((prev >> 2) & 0x01) != 0) /* check thermocouple temperature low fault */
1967 {
1968 if (handle->receive_callback != NULL) /* not null */
1969 {
1970 handle->receive_callback(MAX31856_FAULT_STATUS_TCLOW); /* run the callback */
1971 }
1972 }
1973 if (((prev >> 1) & 0x01) != 0) /* check overvoltage or undervoltage input fault */
1974 {
1975 if (handle->receive_callback != NULL) /* not null */
1976 {
1977 handle->receive_callback(MAX31856_FAULT_STATUS_OVUV); /* run the callback */
1978 }
1979 }
1980 if (((prev >> 0) & 0x01) != 0) /* check thermocouple open circuit fault */
1981 {
1982 if (handle->receive_callback != NULL) /* not null */
1983 {
1984 handle->receive_callback(MAX31856_FAULT_STATUS_OPEN); /* run the callback */
1985 }
1986 }
1987
1988 return 0; /* success return 0 */
1989}
1990
2004uint8_t max31856_set_reg(max31856_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
2005{
2006 uint8_t res;
2007
2008 if (handle == NULL) /* check handle */
2009 {
2010 return 2; /* return error */
2011 }
2012 if (handle->inited != 1) /* check handle initialization */
2013 {
2014 return 3; /* return error */
2015 }
2016
2017 res = a_max31856_write(handle, reg, buf, len); /* write data */
2018 if (res != 0) /* check result */
2019 {
2020 handle->debug_print("max31856: write data failed.\n"); /* write data failed */
2021
2022 return 1; /* return error */
2023 }
2024
2025 return 0; /* success return 0 */
2026}
2027
2041uint8_t max31856_get_reg(max31856_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
2042{
2043 uint8_t res;
2044
2045 if (handle == NULL) /* check handle */
2046 {
2047 return 2; /* return error */
2048 }
2049 if (handle->inited != 1) /* check handle initialization */
2050 {
2051 return 3; /* return error */
2052 }
2053
2054 res = a_max31856_read(handle, reg, buf, len); /* read data */
2055 if (res != 0) /* check result */
2056 {
2057 handle->debug_print("max31856: read data failed.\n"); /* read data failed */
2058
2059 return 1; /* return error */
2060 }
2061
2062 return 0; /* success return 0 */
2063}
2064
2074{
2075 if (info == NULL) /* check handle */
2076 {
2077 return 2; /* return error */
2078 }
2079
2080 memset(info, 0, sizeof(max31856_info_t)); /* initialize max31856 info structure */
2081 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
2082 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
2083 strncpy(info->interface, "SPI", 8); /* copy interface name */
2084 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
2085 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
2086 info->max_current_ma = MAX_CURRENT; /* set maximum current */
2087 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
2088 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
2089 info->driver_version = DRIVER_VERSION; /* set driver version */
2090
2091 return 0; /* success return 0 */
2092}
#define MAX_CURRENT
#define MAX31856_REG_CJLF
#define MAX31856_REG_CJTH
#define MAX31856_REG_LTHFTH
#define MAX31856_REG_CR1
#define MAX31856_REG_LTCBH
#define MAX31856_REG_CR0
chip register definition
#define SUPPLY_VOLTAGE_MAX
#define TEMPERATURE_MAX
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define MAX31856_REG_LTLFTH
#define MAX31856_REG_MASK
#define MAX31856_REG_CJHF
#define MAX31856_REG_SR
#define MAX31856_REG_CJTO
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
driver max31856 header file
uint8_t max31856_stop_continuous_read(max31856_handle_t *handle)
stop the chip reading
struct max31856_info_s max31856_info_t
max31856 information structure definition
uint8_t max31856_set_cold_junction_high_fault_threshold(max31856_handle_t *handle, int8_t threshold)
set cold junction high fault threshold
uint8_t max31856_get_fault_status(max31856_handle_t *handle, uint8_t *status)
get fault status
uint8_t max31856_set_cold_junction_sensor(max31856_handle_t *handle, max31856_bool_t enable)
enable or disable cold junction sensor
uint8_t max31856_set_thermocouple_type(max31856_handle_t *handle, max31856_thermocouple_type_t type)
set thermocouple type
max31856_bool_t
max31856 bool enumeration definition
uint8_t max31856_info(max31856_info_t *info)
get chip's information
uint8_t max31856_clear_fault(max31856_handle_t *handle)
clear fault
uint8_t max31856_get_cold_junction_sensor(max31856_handle_t *handle, max31856_bool_t *enable)
get cold junction sensor status
uint8_t max31856_get_fault_mode(max31856_handle_t *handle, max31856_fault_mode_t *mode)
get fault mode
uint8_t max31856_single_read(max31856_handle_t *handle, int32_t *raw, double *deg)
read data from the chip once
uint8_t max31856_start_continuous_read(max31856_handle_t *handle)
start the chip reading
uint8_t max31856_cold_junction_temperature_convert_to_data(max31856_handle_t *handle, int16_t reg, float *deg)
convert the register raw data to the cold junction temperature
uint8_t max31856_set_fault_mask(max31856_handle_t *handle, max31856_fault_mask_t mask, max31856_bool_t enable)
set fault mask
uint8_t max31856_set_open_circuit_detection(max31856_handle_t *handle, max31856_open_circuit_detection_t detection)
set open circuit detection
uint8_t max31856_get_temperature_low_fault_threshold(max31856_handle_t *handle, int16_t *threshold)
get temperature low fault threshold
max31856_open_circuit_detection_t
max31856 open circuit detection enumeration definition
uint8_t max31856_get_temperature_high_fault_threshold(max31856_handle_t *handle, int16_t *threshold)
get temperature high fault threshold
uint8_t max31856_get_thermocouple_type(max31856_handle_t *handle, max31856_thermocouple_type_t *type)
get thermocouple type
max31856_sample_average_t
max31856 sample average enumeration definition
uint8_t max31856_get_cold_junction_high_fault_threshold(max31856_handle_t *handle, int8_t *threshold)
get cold junction high fault threshold
uint8_t max31856_set_temperature_low_fault_threshold(max31856_handle_t *handle, int16_t threshold)
set temperature low fault threshold
uint8_t max31856_get_sample_average(max31856_handle_t *handle, max31856_sample_average_t *average)
get sample average
uint8_t max31856_get_cold_junction_temperature(max31856_handle_t *handle, int16_t *temperature)
get cold junction temperature
uint8_t max31856_get_cold_junction_low_fault_threshold(max31856_handle_t *handle, int8_t *threshold)
get cold junction low fault threshold
max31856_noise_rejection_filter_t
max31856 noise rejection filter enumeration definition
uint8_t max31856_continuous_read(max31856_handle_t *handle, int32_t *raw, double *deg)
read data from the chip continuously
uint8_t max31856_get_fault_mask(max31856_handle_t *handle, max31856_fault_mask_t mask, max31856_bool_t *enable)
get fault mask
uint8_t max31856_temperature_fault_threshold_convert_to_register(max31856_handle_t *handle, float deg, int16_t *reg)
convert the temperature fault threshold to the register raw data
max31856_fault_mode_t
max31856 fault mode enumeration definition
uint8_t max31856_read_cold_junction_temperature(max31856_handle_t *handle, int16_t *raw, double *deg)
read cold junction temperature
uint8_t max31856_deinit(max31856_handle_t *handle)
close the chip
uint8_t max31856_set_noise_rejection_filter(max31856_handle_t *handle, max31856_noise_rejection_filter_t filter)
set noise rejection filter
max31856_thermocouple_type_t
max31856 thermocouple type enumeration definition
uint8_t max31856_get_open_circuit_detection(max31856_handle_t *handle, max31856_open_circuit_detection_t *detection)
get open circuit detection
uint8_t max31856_init(max31856_handle_t *handle)
initialize the chip
uint8_t max31856_set_cold_junction_low_fault_threshold(max31856_handle_t *handle, int8_t threshold)
set cold junction low fault threshold
uint8_t max31856_set_cold_junction_temperature(max31856_handle_t *handle, int16_t temperature)
set cold junction temperature
uint8_t max31856_temperature_fault_threshold_convert_to_data(max31856_handle_t *handle, int16_t reg, float *deg)
convert the register raw data to the temperature fault threshold
struct max31856_handle_s max31856_handle_t
max31856 handle structure definition
uint8_t max31856_get_cold_junction_temperature_offset(max31856_handle_t *handle, int8_t *offset)
get cold junction temperature offset
uint8_t max31856_cold_junction_temperature_convert_to_register(max31856_handle_t *handle, float deg, int16_t *reg)
convert the cold junction temperature to the register raw data
uint8_t max31856_cold_junction_fault_threshold_convert_to_register(max31856_handle_t *handle, float deg, int8_t *reg)
convert the cold junction fault threshold to the register raw data
uint8_t max31856_set_sample_average(max31856_handle_t *handle, max31856_sample_average_t average)
set sample average
uint8_t max31856_cold_junction_temperature_offset_convert_to_register(max31856_handle_t *handle, float deg, int8_t *reg)
convert the cold junction temperature offset to the register raw data
uint8_t max31856_cold_junction_fault_threshold_convert_to_data(max31856_handle_t *handle, int8_t reg, float *deg)
convert the register raw data to the cold junction fault threshold
uint8_t max31856_cold_junction_temperature_offset_convert_to_data(max31856_handle_t *handle, int8_t reg, float *deg)
convert the register raw data to the cold junction temperature offset
uint8_t max31856_set_fault_mode(max31856_handle_t *handle, max31856_fault_mode_t mode)
set fault mode
uint8_t max31856_irq_handler(max31856_handle_t *handle)
irq handler
uint8_t max31856_set_cold_junction_temperature_offset(max31856_handle_t *handle, int8_t offset)
set cold junction temperature offset
uint8_t max31856_set_temperature_high_fault_threshold(max31856_handle_t *handle, int16_t threshold)
set temperature high fault threshold
uint8_t max31856_get_noise_rejection_filter(max31856_handle_t *handle, max31856_noise_rejection_filter_t *filter)
get noise rejection filter
max31856_fault_mask_t
max31856 fault mask enumeration definition
@ MAX31856_FAULT_STATUS_TCHIGH
@ MAX31856_FAULT_STATUS_CJHIGH
@ MAX31856_FAULT_STATUS_TCLOW
@ MAX31856_FAULT_STATUS_OVUV
@ MAX31856_FAULT_STATUS_TCRANGE
@ MAX31856_FAULT_STATUS_OPEN
@ MAX31856_FAULT_STATUS_CJLOW
@ MAX31856_FAULT_STATUS_CJRANGE
uint8_t max31856_set_reg(max31856_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t max31856_get_reg(max31856_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* receive_callback)(uint8_t type)
uint8_t(* spi_write)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
uint8_t(* spi_deinit)(void)
char manufacturer_name[32]