LibDriver MAX31865
Loading...
Searching...
No Matches
driver_max31865.c
Go to the documentation of this file.
1
37
38#include "driver_max31865.h"
39
43#define CHIP_NAME "Maxim Integrated MAX31865"
44#define MANUFACTURER_NAME "Maxim Integrated"
45#define SUPPLY_VOLTAGE_MIN 3.0f
46#define SUPPLY_VOLTAGE_MAX 3.6f
47#define MAX_CURRENT 5.75f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 85.0f
50#define DRIVER_VERSION 2000
51
55#define MAX31865_REG_CONFIG 0x00
56#define MAX31865_REG_RTD_MSB 0x01
57#define MAX31865_REG_RTD_LSB 0x02
58#define MAX31865_REG_HIGH_FAULT_MSB 0x03
59#define MAX31865_REG_HIGH_FAULT_LSB 0x04
60#define MAX31865_REG_LOW_FAULT_MSB 0x05
61#define MAX31865_REG_LOW_FAULT_LSB 0x06
62#define MAX31865_REG_FAULT_STATUS 0x07
63
67#define WRITE_ADDRESS_MASK 0x80
68#define RTD_A 3.9083e-3f
69#define RTD_B -5.775e-7f
70
79static float a_max31865_temperature_conversion(float rt, float rtd_nominal, float ref_resistor)
80{
81 float z1, z2, z3, z4, temp;
82 float rpoly;
83
84 rt /= 32768; /* div 32768 */
85 rt *= ref_resistor; /* ref_resistor */
86 z1 = -RTD_A; /* -RTD A */
87 z2 = RTD_A * RTD_A - (4 * RTD_B); /* get z2 */
88 z3 = (4 * RTD_B) / rtd_nominal; /* get z3 */
89 z4 = 2 * RTD_B; /* get z4 */
90 temp = z2 + (z3 * rt); /* calculate temp */
91 temp = (sqrtf(temp) + z1) / z4; /* sqrt */
92 if (temp >= 0) /* check temp */
93 {
94 return temp; /* return temp */
95 }
96 rt /= rtd_nominal; /* nominal */
97 rt *= 100; /* normalize to 100 ohm */
98 rpoly = rt; /* use normalized value for polynomial */
99 temp = -242.02f; /* -242.02 */
100 temp += 2.2228f * rpoly; /* add offset */
101 rpoly *= rt; /* square */
102 temp += 2.5859e-3f * rpoly; /* add offset */
103 rpoly *= rt; /* ^3 */
104 temp -= 4.8260e-6f * rpoly; /* add offset */
105 rpoly *= rt; /* ^4 */
106 temp -= 2.8183e-8f * rpoly; /* add offset */
107 rpoly *= rt; /* ^5 */
108 temp += 1.5243e-10f * rpoly; /* add offset */
109
110 return temp; /* return error */
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("max31865: spi_init is null.\n"); /* spi_init is null */
136
137 return 3; /* return error */
138 }
139 if (handle->spi_deinit == NULL) /* check spi_init */
140 {
141 handle->debug_print("max31865: 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("max31865: 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("max31865: 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("max31865: delay_ms is null.\n"); /* delay_ms is null */
160
161 return 3; /* return error */
162 }
163
164 if (handle->spi_init() != 0) /* spi init */
165 {
166 handle->debug_print("max31865: spi init failed.\n"); /* spi init failed */
167
168 return 3; /* return error */
169 }
170 handle->inited = 1; /* flag initialization */
171
172 return 0; /* success return 0 */
173}
174
187{
188 uint8_t res, prev;
189
190 if (handle == NULL) /* check handle */
191 {
192 return 2; /* return error */
193 }
194 if (handle->inited != 1) /* check handle initialization */
195 {
196 return 3; /* return error */
197 }
198
199 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
200 if (res != 0) /* check result */
201 {
202 handle->debug_print("max31865: read failed.\n"); /* read failed */
203
204 return 4; /* return error */
205 }
206 prev &= ~(1 << 7); /* clear flag */
207 res = handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
208 if (res != 0) /* check result */
209 {
210 handle->debug_print("max31865: write failed.\n"); /* write failed */
211
212 return 4; /* return error */
213 }
214 if (handle->spi_deinit() != 0) /* spi deinit */
215 {
216 handle->debug_print("max31865: spi deinit failed.\n"); /* spi deinit failed */
217
218 return 1; /* return error */
219 }
220 handle->inited = 0; /* flag close */
221
222 return 0; /* success return 0 */
223}
224
237{
238 uint8_t res, prev;
239
240 if (handle == NULL) /* check handle */
241 {
242 return 2; /* return error */
243 }
244 if (handle->inited != 1) /* check handle initialization */
245 {
246 return 3; /* return error */
247 }
248
249 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
250 if (res != 0) /* check result */
251 {
252 handle->debug_print("max31865: read failed.\n"); /* read failed */
253
254 return 1; /* return error */
255 }
256 prev &= ~(1 << 0); /* clear filter bit */
257 prev |= filter << 0; /* set filter */
258
259 return handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
260}
261
274{
275 uint8_t res, prev;
276
277 if (handle == NULL) /* check handle */
278 {
279 return 2; /* return error */
280 }
281 if (handle->inited != 1) /* check handle initialization */
282 {
283 return 3; /* return error */
284 }
285
286 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
287 if (res != 0) /* check result */
288 {
289 handle->debug_print("max31865: read failed.\n"); /* read failed */
290
291 return 1; /* return error */
292 }
293 prev &= (1 << 0); /* get raw */
294 *filter = (max31865_filter_select_t)(prev >> 0); /* get filter select */
295
296 return 0; /* success return 0 */
297}
298
311{
312 uint8_t res, prev;
313
314 if (handle == NULL) /* check handle */
315 {
316 return 2; /* return error */
317 }
318 if (handle->inited != 1) /* check handle initialization */
319 {
320 return 3; /* return error */
321 }
322
323 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
324 if (res != 0) /* check result */
325 {
326 handle->debug_print("max31865: read failed.\n"); /* read failed */
327
328 return 1; /* return error */
329 }
330 prev &= ~(1 << 4); /* clear wire bit */
331 prev |= wire << 4; /* set wire */
332
333 return handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
334}
335
348{
349 uint8_t res, prev;
350
351 if (handle == NULL) /* check handle */
352 {
353 return 2; /* return error */
354 }
355 if (handle->inited != 1) /* check handle initialization */
356 {
357 return 3; /* return error */
358 }
359
360 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
361 if (res != 0) /* check result */
362 {
363 handle->debug_print("max31865: read failed.\n"); /* read failed */
364
365 return 1; /* return error */
366 }
367 prev &= 1 << 4; /* get wire bit */
368 *wire = (max31865_wire_t)(prev >> 4); /* get wire */
369
370 return 0; /* success return 0 */
371}
372
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 handle->ref_resistor = value; /* set reference resistor */
395
396 return 0; /* success return 0 */
397}
398
410{
411 if (handle == NULL) /* check handle */
412 {
413 return 2; /* return error */
414 }
415 if (handle->inited != 1) /* check handle initialization */
416 {
417 return 3; /* return error */
418 }
419
420 *value = (float)(handle->ref_resistor); /* get reference resistor */
421
422 return 0; /* success return 0 */
423}
424
436{
437 if (handle == NULL) /* check handle */
438 {
439 return 2; /* return error */
440 }
441 if (handle->inited != 1) /* check handle initialization */
442 {
443 return 3; /* return error */
444 }
445
446 handle->resistor = (uint8_t)resistor; /* set resistor */
447
448 return 0; /* success return 0 */
449}
450
462{
463 if (handle == NULL) /* check handle */
464 {
465 return 2; /* return error */
466 }
467 if (handle->inited != 1) /* check handle initialization */
468 {
469 return 3; /* return error */
470 }
471
472 *resistor = (max31865_resistor_t)(handle->resistor); /* get resistor */
473
474 return 0; /* success return 0 */
475}
476
489{
490 uint8_t res, prev;
491
492 if (handle == NULL) /* check handle */
493 {
494 return 2; /* return error */
495 }
496 if (handle->inited != 1) /* check handle initialization */
497 {
498 return 3; /* return error */
499 }
500
501 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
502 if (res != 0) /* check result */
503 {
504 handle->debug_print("max31865: read failed.\n"); /* read failed */
505
506 return 1; /* return error */
507 }
508 prev &= ~(1 << 7); /* clear bias bit */
509 prev |= enable << 7; /* set bias enable */
510
511 return handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
512}
513
526{
527 uint8_t res, prev;
528
529 if (handle == NULL) /* check handle */
530 {
531 return 2; /* return error */
532 }
533 if (handle->inited != 1) /* check handle initialization */
534 {
535 return 3; /* return error */
536 }
537
538 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
539 if (res != 0) /* check result */
540 {
541 handle->debug_print("max31865: read failed.\n"); /* read failed */
542
543 return 1; /* return error */
544 }
545 prev &= 1 << 7; /* get vbias bit */
546 *enable = (max31865_bool_t)(prev >> 7); /* get vbias */
547
548 return 0; /* success return 0 */
549}
550
562{
563 uint8_t res, prev;
564
565 if (handle == NULL) /* check handle */
566 {
567 return 2; /* return error */
568 }
569 if (handle->inited != 1) /* check handle initialization */
570 {
571 return 3; /* return error */
572 }
573
574 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
575 if (res != 0) /* check result */
576 {
577 handle->debug_print("max31865: read failed.\n"); /* read failed */
578
579 return 1; /* return error */
580 }
581 prev &= ~(1 << 1); /* clear bit */
582 prev |= 1 << 1; /* set clear */
583
584 return handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
585}
586
598uint8_t max31865_get_fault_status(max31865_handle_t *handle, uint8_t *status)
599{
600 if (handle == NULL) /* check handle */
601 {
602 return 2; /* return error */
603 }
604 if (handle->inited != 1) /* check handle initialization */
605 {
606 return 3; /* return error */
607 }
608
609 return handle->spi_read(MAX31865_REG_FAULT_STATUS, status, 1); /* read status */
610}
611
623uint8_t max31865_set_high_fault_threshold(max31865_handle_t *handle, uint16_t threshold)
624{
625 uint8_t buf[2];
626
627 if (handle == NULL) /* check handle */
628 {
629 return 2; /* return error */
630 }
631 if (handle->inited != 1) /* check handle initialization */
632 {
633 return 3; /* return error */
634 }
635
636 threshold = threshold << 1; /* left shift 1 */
637 buf[0] = (uint8_t)((threshold >> 8) & 0xFF); /* set msb */
638 buf[1] = (uint8_t)(threshold & 0xFF); /* set lsb */
639
640 return handle->spi_write(MAX31865_REG_HIGH_FAULT_MSB | WRITE_ADDRESS_MASK, (uint8_t *)buf, 2); /* write fault threshold */
641}
642
654uint8_t max31865_get_high_fault_threshold(max31865_handle_t *handle, uint16_t *threshold)
655{
656 uint8_t res;
657 uint8_t buf[2];
658
659 if (handle == NULL) /* check handle */
660 {
661 return 2; /* return error */
662 }
663 if (handle->inited != 1) /* check handle initialization */
664 {
665 return 3; /* return error */
666 }
667
668 res = handle->spi_read(MAX31865_REG_HIGH_FAULT_MSB, (uint8_t *)buf, 2); /* get fault msb */
669 if (res != 0) /* check result */
670 {
671 handle->debug_print("max31865: read failed.\n"); /* read failed */
672
673 return 1; /* return error */
674 }
675 *threshold = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* get raw */
676 *threshold = (*threshold) >> 1; /* get data */
677
678 return 0; /* success return 0 */
679}
680
692uint8_t max31865_set_low_fault_threshold(max31865_handle_t *handle, uint16_t threshold)
693{
694 uint8_t buf[2];
695
696 if (handle == NULL) /* check handle */
697 {
698 return 2; /* return error */
699 }
700 if (handle->inited != 1) /* check handle initialization */
701 {
702 return 3; /* return error */
703 }
704
705 threshold = threshold << 1; /* left shift 1 */
706 buf[0] = (uint8_t)((threshold >> 8) & 0xFF); /* set msb */
707 buf[1] = (uint8_t)(threshold & 0xFF); /* set lsb */
708
709 return handle->spi_write(MAX31865_REG_LOW_FAULT_MSB | WRITE_ADDRESS_MASK, (uint8_t *)buf, 2); /* write config */
710}
711
723uint8_t max31865_get_low_fault_threshold(max31865_handle_t *handle, uint16_t *threshold)
724{
725 uint8_t res;
726 uint8_t buf[2];
727
728 if (handle == NULL) /* check handle */
729 {
730 return 2; /* return error */
731 }
732 if (handle->inited != 1) /* check handle initialization */
733 {
734 return 3; /* return error */
735 }
736
737 res = handle->spi_read(MAX31865_REG_LOW_FAULT_MSB, (uint8_t *)buf, 2); /* write low fault msb */
738 if (res != 0) /* check result */
739 {
740 handle->debug_print("max31865: read failed.\n"); /* read failed */
741
742 return 1; /* return error */
743 }
744 *threshold = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* get raw */
745 *threshold = (*threshold) >> 1; /* get data */
746
747 return 0; /* success return 0 */
748}
749
762{
763 uint8_t res, prev;
764
765 if (handle == NULL) /* check handle */
766 {
767 return 2; /* return error */
768 }
769 if (handle->inited != 1) /* check handle initialization */
770 {
771 return 3; /* return error */
772 }
773
774 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
775 if (res != 0) /* check result */
776 {
777 handle->debug_print("max31865: read failed.\n"); /* read failed */
778
779 return 1; /* return error */
780 }
781 prev &= ~(3 << 2); /* clear control */
782 prev |= control << 2; /* set control */
783
784 return handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
785}
786
799{
800 uint8_t res, prev;
801
802 if (handle == NULL) /* check handle */
803 {
804 return 2; /* return error */
805 }
806 if (handle->inited != 1) /* check handle initialization */
807 {
808 return 3; /* return error */
809 }
810
811 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
812 if (res != 0) /* check result */
813 {
814 handle->debug_print("max31865: read failed.\n"); /* read failed */
815
816 return 1; /* return error */
817 }
818 prev &= 3 << 2; /* get control bits */
819 *status = (max31865_fault_detection_cycle_control_status_t)(prev >> 2); /* get control */
820
821 return 0; /* success return 0 */
822}
823
837uint8_t max31865_single_read(max31865_handle_t *handle, uint16_t *raw, float *temp)
838{
839 uint8_t res, prev;
840 uint8_t buf[2];
841 float resistor;
842 uint16_t times;
843
844 if (handle == NULL) /* check handle */
845 {
846 return 2; /* return error */
847 }
848 if (handle->inited != 1) /* check handle initialization */
849 {
850 return 3; /* return error */
851 }
852
853 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
854 if (res != 0) /* check result */
855 {
856 handle->debug_print("max31865: read failed.\n"); /* read failed */
857
858 return 1; /* return error */
859 }
860 prev |= 1 << 1; /* set fault detection */
861 prev |= 1 << 7; /* enable vbias */
862 prev &= ~(1 << 6); /* set normally off */
863 prev |= 1 << 5; /* set shot */
864 res = handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
865 if (res != 0) /* check result */
866 {
867 handle->debug_print("max31865: write failed.\n"); /* write failed */
868
869 return 1; /* return error */
870 }
871 times = 5000; /* set retry times */
872 while (((prev & (1 << 5)) != 0) && (times != 0)) /* check retry times */
873 {
874 handle->delay_ms(63); /* delay 63 ms */
875 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
876 if (res != 0) /* check result */
877 {
878 handle->debug_print("max31865: read failed.\n"); /* read failed */
879
880 return 1; /* return error */
881 }
882 times--; /* retry times-- */
883 if (times == 0) /* if retry times == 0 */
884 {
885 handle->debug_print("max31865: read timeout.\n"); /* read timeout */
886
887 return 1; /* return error */
888 }
889 }
890 memset(buf, 0, sizeof(uint8_t) * 2); /* clear the buffer */
891 res = handle->spi_read(MAX31865_REG_RTD_MSB, (uint8_t *)buf, 2); /* read rtd msb */
892 if (res != 0) /* check result */
893 {
894 handle->debug_print("max31865: read failed.\n"); /* read failed */
895
896 return 1; /* return error */
897 }
898 *raw = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* get raw data */
899 if (((*raw) & 0x01) != 0)
900 {
901 handle->debug_print("max31865: find rtd fault.\n"); /* find rtd fault */
902
903 return 4; /* return error */
904 }
905 else
906 {
907 (*raw) = (*raw) >> 1; /* get raw data */
908 }
909 if (handle->resistor == MAX31865_RESISTOR_100PT) /* if 100PT */
910 {
911 resistor = 100.0f; /* set resistor type 100 */
912 }
913 else
914 {
915 resistor = 1000.0f; /* set resistor type 1000 */
916 }
917 *temp = a_max31865_temperature_conversion((float)(*raw), resistor, handle->ref_resistor); /* calculate temperature */
918
919 return 0; /* success return 0 */
920}
921
933{
934 uint8_t res, prev;
935
936 if (handle == NULL) /* check handle */
937 {
938 return 2; /* return error */
939 }
940 if (handle->inited != 1) /* check handle initialization */
941 {
942 return 3; /* return error */
943 }
944
945 handle->delay_ms(10); /* delay 10 ms */
946 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
947 if (res != 0) /* check result */
948 {
949 handle->debug_print("max31865: read failed.\n"); /* read failed */
950
951 return 1; /* return error */
952 }
953 prev |= 1 << 1; /* set fault detection */
954 prev |= 1 << 7; /* enable vbias */
955 prev |= 1 << 6; /* set auto mode */
956 prev &= ~(1 << 5); /* disable shot */
957
958 return handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
959}
960
972{
973 uint8_t res, prev;
974
975 if (handle == NULL) /* check handle */
976 {
977 return 2; /* return error */
978 }
979 if (handle->inited != 1) /* check handle initialization */
980 {
981 return 3; /* return error */
982 }
983
984 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
985 if (res != 0) /* check result */
986 {
987 handle->debug_print("max31865: read failed.\n"); /* read failed */
988
989 return 1; /* return error */
990 }
991 prev |= 1 << 1; /* set fault detection */
992 prev &= ~(1 << 7); /* disable vbias */
993 prev &= ~(1 << 6); /* disable auto mode */
994 prev &= ~(1 << 5); /* disable shot */
995
996 return handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
997}
998
1012uint8_t max31865_continuous_read(max31865_handle_t *handle, uint16_t *raw, float *temp)
1013{
1014 uint8_t res;
1015 uint8_t buf[2];
1016 float resistor;
1017
1018 if (handle == NULL) /* check handle */
1019 {
1020 return 2; /* return error */
1021 }
1022 if (handle->inited != 1) /* check handle initialization */
1023 {
1024 return 3; /* return error */
1025 }
1026
1027 memset(buf, 0, sizeof(uint8_t) * 2); /* clear the buffer */
1028 res = handle->spi_read(MAX31865_REG_RTD_MSB, (uint8_t *)buf, 2); /* read rtd msb */
1029 if (res != 0) /* check result */
1030 {
1031 handle->debug_print("max31865: read failed.\n"); /* read failed */
1032
1033 return 1; /* return error */
1034 }
1035 *raw = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* get raw data */
1036 if (((*raw) & 0x01) != 0) /* check error */
1037 {
1038 handle->debug_print("max31865: find rtd fault.\n"); /* find rtd fault */
1039
1040 return 4; /* return error */
1041 }
1042 else
1043 {
1044 (*raw) = (*raw) >> 1; /* get raw data */
1045 }
1046 if (handle->resistor == MAX31865_RESISTOR_100PT) /* choose resistor type */
1047 {
1048 resistor = 100.0f; /* set resistor type 100 */
1049 }
1050 else
1051 {
1052 resistor = 1000.0f; /* set resistor type 1000 */
1053 }
1054 *temp = a_max31865_temperature_conversion((float)(*raw), resistor, handle->ref_resistor); /* calculate */
1055
1056 return 0; /* success return 0 */
1057}
1058
1071uint8_t max31865_set_reg(max31865_handle_t *handle, uint8_t reg, uint8_t value)
1072{
1073 if (handle == NULL) /* check handle */
1074 {
1075 return 2; /* return error */
1076 }
1077 if (handle->inited != 1) /* check handle initialization */
1078 {
1079 return 3; /* return error */
1080 }
1081
1082 return handle->spi_write(reg | WRITE_ADDRESS_MASK, (uint8_t *)&value, 1); /* write to reg */
1083}
1084
1097uint8_t max31865_get_reg(max31865_handle_t *handle, uint8_t reg, uint8_t *value)
1098{
1099 if (handle == NULL) /* check handle */
1100 {
1101 return 2; /* return error */
1102 }
1103 if (handle->inited != 1) /* check handle initialization */
1104 {
1105 return 3; /* return error */
1106 }
1107
1108 return handle->spi_read(reg, (uint8_t *)value, 1); /* read from reg */
1109}
1110
1120{
1121 if (info == NULL) /* check handle */
1122 {
1123 return 2; /* return error */
1124 }
1125
1126 memset(info, 0, sizeof(max31865_info_t)); /* initialize max31865 info structure */
1127 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1128 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1129 strncpy(info->interface, "SPI", 8); /* copy interface name */
1130 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1131 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1132 info->max_current_ma = MAX_CURRENT; /* set maximum current */
1133 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1134 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1135 info->driver_version = DRIVER_VERSION; /* set driver version */
1136
1137 return 0; /* success return 0 */
1138}
#define MAX31865_REG_FAULT_STATUS
#define RTD_B
#define MAX_CURRENT
#define RTD_A
#define SUPPLY_VOLTAGE_MAX
#define TEMPERATURE_MAX
#define WRITE_ADDRESS_MASK
calculate definition
#define MAX31865_REG_LOW_FAULT_MSB
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define MAX31865_REG_HIGH_FAULT_MSB
#define MAX31865_REG_CONFIG
chip register definition
#define MAX31865_REG_RTD_MSB
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
driver max31865 header file
uint8_t max31865_set_low_fault_threshold(max31865_handle_t *handle, uint16_t threshold)
set the low fault threshold
uint8_t max31865_get_wire(max31865_handle_t *handle, max31865_wire_t *wire)
get the pt resistor wire
max31865_bool_t
max31865 bool enumeration definition
uint8_t max31865_set_vbias(max31865_handle_t *handle, max31865_bool_t enable)
set the chip vbias
uint8_t max31865_set_wire(max31865_handle_t *handle, max31865_wire_t wire)
set the pt resistor wire
uint8_t max31865_get_reference_resistor(max31865_handle_t *handle, float *value)
get the reference resistor
struct max31865_info_s max31865_info_t
max31865 information structure definition
uint8_t max31865_continuous_read(max31865_handle_t *handle, uint16_t *raw, float *temp)
read data continuously
max31865_resistor_t
max31865 resistor type enumeration definition
uint8_t max31865_single_read(max31865_handle_t *handle, uint16_t *raw, float *temp)
read data once
uint8_t max31865_init(max31865_handle_t *handle)
initialize the chip
uint8_t max31865_set_resistor(max31865_handle_t *handle, max31865_resistor_t resistor)
set the pt resistor
max31865_fault_detection_cycle_control_t
max31865 fault detection cycle control enumeration definition
max31865_wire_t
max31865 wire type enumeration definition
uint8_t max31865_get_resistor(max31865_handle_t *handle, max31865_resistor_t *resistor)
get the pt resistor
uint8_t max31865_set_reference_resistor(max31865_handle_t *handle, float value)
set the reference resistor
uint8_t max31865_set_fault_detection_cycle_control(max31865_handle_t *handle, max31865_fault_detection_cycle_control_t control)
set the fault detection cycle control
uint8_t max31865_get_fault_status(max31865_handle_t *handle, uint8_t *status)
get the fault status
uint8_t max31865_set_filter_select(max31865_handle_t *handle, max31865_filter_select_t filter)
set the filter type
uint8_t max31865_get_filter_select(max31865_handle_t *handle, max31865_filter_select_t *filter)
get the filter type
max31865_fault_detection_cycle_control_status_t
max31865 fault detection cycle control status enumeration definition
uint8_t max31865_get_low_fault_threshold(max31865_handle_t *handle, uint16_t *threshold)
get the low fault threshold
uint8_t max31865_get_fault_detection_cycle_control(max31865_handle_t *handle, max31865_fault_detection_cycle_control_status_t *status)
get the fault detection cycle control
uint8_t max31865_clear_fault_status(max31865_handle_t *handle)
clear all fault status
uint8_t max31865_stop_continuous_read(max31865_handle_t *handle)
stop reading
uint8_t max31865_get_vbias(max31865_handle_t *handle, max31865_bool_t *enable)
get the chip vbias
struct max31865_handle_s max31865_handle_t
max31865 handle structure definition
uint8_t max31865_info(max31865_info_t *info)
get chip's information
uint8_t max31865_set_high_fault_threshold(max31865_handle_t *handle, uint16_t threshold)
set the high fault threshold
uint8_t max31865_get_high_fault_threshold(max31865_handle_t *handle, uint16_t *threshold)
get the high fault threshold
max31865_filter_select_t
max31865 filter select enumeration definition
uint8_t max31865_start_continuous_read(max31865_handle_t *handle)
start reading
uint8_t max31865_deinit(max31865_handle_t *handle)
close the chip
@ MAX31865_RESISTOR_100PT
uint8_t max31865_get_reg(max31865_handle_t *handle, uint8_t reg, uint8_t *value)
get the chip register
uint8_t max31865_set_reg(max31865_handle_t *handle, uint8_t reg, uint8_t value)
set 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)
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]