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 125.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 1; /* 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 prev &= ~(1 << 6); /* set normally off */
208 res = handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
209 if (res != 0) /* check result */
210 {
211 handle->debug_print("max31865: write failed.\n"); /* write failed */
212
213 return 4; /* return error */
214 }
215 if (handle->spi_deinit() != 0) /* spi deinit */
216 {
217 handle->debug_print("max31865: spi deinit failed.\n"); /* spi deinit failed */
218
219 return 1; /* return error */
220 }
221 handle->inited = 0; /* flag close */
222
223 return 0; /* success return 0 */
224}
225
238{
239 uint8_t res, prev;
240
241 if (handle == NULL) /* check handle */
242 {
243 return 2; /* return error */
244 }
245 if (handle->inited != 1) /* check handle initialization */
246 {
247 return 3; /* return error */
248 }
249
250 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
251 if (res != 0) /* check result */
252 {
253 handle->debug_print("max31865: read failed.\n"); /* read failed */
254
255 return 1; /* return error */
256 }
257 prev &= ~(1 << 0); /* clear filter bit */
258 prev |= filter << 0; /* set filter */
259
260 return handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
261}
262
275{
276 uint8_t res, prev;
277
278 if (handle == NULL) /* check handle */
279 {
280 return 2; /* return error */
281 }
282 if (handle->inited != 1) /* check handle initialization */
283 {
284 return 3; /* return error */
285 }
286
287 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
288 if (res != 0) /* check result */
289 {
290 handle->debug_print("max31865: read failed.\n"); /* read failed */
291
292 return 1; /* return error */
293 }
294 prev &= (1 << 0); /* get raw */
295 *filter = (max31865_filter_select_t)(prev >> 0); /* get filter select */
296
297 return 0; /* success return 0 */
298}
299
312{
313 uint8_t res, prev;
314
315 if (handle == NULL) /* check handle */
316 {
317 return 2; /* return error */
318 }
319 if (handle->inited != 1) /* check handle initialization */
320 {
321 return 3; /* return error */
322 }
323
324 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
325 if (res != 0) /* check result */
326 {
327 handle->debug_print("max31865: read failed.\n"); /* read failed */
328
329 return 1; /* return error */
330 }
331 prev &= ~(1 << 4); /* clear wire bit */
332 prev |= wire << 4; /* set wire */
333
334 return handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
335}
336
349{
350 uint8_t res, prev;
351
352 if (handle == NULL) /* check handle */
353 {
354 return 2; /* return error */
355 }
356 if (handle->inited != 1) /* check handle initialization */
357 {
358 return 3; /* return error */
359 }
360
361 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
362 if (res != 0) /* check result */
363 {
364 handle->debug_print("max31865: read failed.\n"); /* read failed */
365
366 return 1; /* return error */
367 }
368 prev &= 1 << 4; /* get wire bit */
369 *wire = (max31865_wire_t)(prev >> 4); /* get wire */
370
371 return 0; /* success return 0 */
372}
373
385{
386 if (handle == NULL) /* check handle */
387 {
388 return 2; /* return error */
389 }
390 if (handle->inited != 1) /* check handle initialization */
391 {
392 return 3; /* return error */
393 }
394
395 handle->ref_resistor = value; /* set reference resistor */
396
397 return 0; /* success return 0 */
398}
399
411{
412 if (handle == NULL) /* check handle */
413 {
414 return 2; /* return error */
415 }
416 if (handle->inited != 1) /* check handle initialization */
417 {
418 return 3; /* return error */
419 }
420
421 *value = (float)(handle->ref_resistor); /* get reference resistor */
422
423 return 0; /* success return 0 */
424}
425
437{
438 if (handle == NULL) /* check handle */
439 {
440 return 2; /* return error */
441 }
442 if (handle->inited != 1) /* check handle initialization */
443 {
444 return 3; /* return error */
445 }
446
447 handle->resistor = (uint8_t)resistor; /* set resistor */
448
449 return 0; /* success return 0 */
450}
451
463{
464 if (handle == NULL) /* check handle */
465 {
466 return 2; /* return error */
467 }
468 if (handle->inited != 1) /* check handle initialization */
469 {
470 return 3; /* return error */
471 }
472
473 *resistor = (max31865_resistor_t)(handle->resistor); /* get resistor */
474
475 return 0; /* success return 0 */
476}
477
490{
491 uint8_t res, prev;
492
493 if (handle == NULL) /* check handle */
494 {
495 return 2; /* return error */
496 }
497 if (handle->inited != 1) /* check handle initialization */
498 {
499 return 3; /* return error */
500 }
501
502 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
503 if (res != 0) /* check result */
504 {
505 handle->debug_print("max31865: read failed.\n"); /* read failed */
506
507 return 1; /* return error */
508 }
509 prev &= ~(1 << 7); /* clear bias bit */
510 prev |= enable << 7; /* set bias enable */
511
512 return handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
513}
514
527{
528 uint8_t res, prev;
529
530 if (handle == NULL) /* check handle */
531 {
532 return 2; /* return error */
533 }
534 if (handle->inited != 1) /* check handle initialization */
535 {
536 return 3; /* return error */
537 }
538
539 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
540 if (res != 0) /* check result */
541 {
542 handle->debug_print("max31865: read failed.\n"); /* read failed */
543
544 return 1; /* return error */
545 }
546 prev &= 1 << 7; /* get vbias bit */
547 *enable = (max31865_bool_t)(prev >> 7); /* get vbias */
548
549 return 0; /* success return 0 */
550}
551
563{
564 uint8_t res, prev;
565
566 if (handle == NULL) /* check handle */
567 {
568 return 2; /* return error */
569 }
570 if (handle->inited != 1) /* check handle initialization */
571 {
572 return 3; /* return error */
573 }
574
575 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
576 if (res != 0) /* check result */
577 {
578 handle->debug_print("max31865: read failed.\n"); /* read failed */
579
580 return 1; /* return error */
581 }
582 prev &= ~(1 << 1); /* clear bit */
583 prev |= 1 << 1; /* set clear */
584
585 return handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
586}
587
599uint8_t max31865_get_fault_status(max31865_handle_t *handle, uint8_t *status)
600{
601 if (handle == NULL) /* check handle */
602 {
603 return 2; /* return error */
604 }
605 if (handle->inited != 1) /* check handle initialization */
606 {
607 return 3; /* return error */
608 }
609
610 return handle->spi_read(MAX31865_REG_FAULT_STATUS, status, 1); /* read status */
611}
612
624uint8_t max31865_set_high_fault_threshold(max31865_handle_t *handle, uint16_t threshold)
625{
626 uint8_t buf[2];
627
628 if (handle == NULL) /* check handle */
629 {
630 return 2; /* return error */
631 }
632 if (handle->inited != 1) /* check handle initialization */
633 {
634 return 3; /* return error */
635 }
636
637 threshold = threshold << 1; /* left shift 1 */
638 buf[0] = (uint8_t)((threshold >> 8) & 0xFF); /* set msb */
639 buf[1] = (uint8_t)(threshold & 0xFF); /* set lsb */
640
641 return handle->spi_write(MAX31865_REG_HIGH_FAULT_MSB | WRITE_ADDRESS_MASK, (uint8_t *)buf, 2); /* write fault threshold */
642}
643
655uint8_t max31865_get_high_fault_threshold(max31865_handle_t *handle, uint16_t *threshold)
656{
657 uint8_t res;
658 uint8_t buf[2];
659
660 if (handle == NULL) /* check handle */
661 {
662 return 2; /* return error */
663 }
664 if (handle->inited != 1) /* check handle initialization */
665 {
666 return 3; /* return error */
667 }
668
669 res = handle->spi_read(MAX31865_REG_HIGH_FAULT_MSB, (uint8_t *)buf, 2); /* get fault msb */
670 if (res != 0) /* check result */
671 {
672 handle->debug_print("max31865: read failed.\n"); /* read failed */
673
674 return 1; /* return error */
675 }
676 *threshold = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* get raw */
677 *threshold = (*threshold) >> 1; /* get data */
678
679 return 0; /* success return 0 */
680}
681
693uint8_t max31865_set_low_fault_threshold(max31865_handle_t *handle, uint16_t threshold)
694{
695 uint8_t buf[2];
696
697 if (handle == NULL) /* check handle */
698 {
699 return 2; /* return error */
700 }
701 if (handle->inited != 1) /* check handle initialization */
702 {
703 return 3; /* return error */
704 }
705
706 threshold = threshold << 1; /* left shift 1 */
707 buf[0] = (uint8_t)((threshold >> 8) & 0xFF); /* set msb */
708 buf[1] = (uint8_t)(threshold & 0xFF); /* set lsb */
709
710 return handle->spi_write(MAX31865_REG_LOW_FAULT_MSB | WRITE_ADDRESS_MASK, (uint8_t *)buf, 2); /* write config */
711}
712
724uint8_t max31865_get_low_fault_threshold(max31865_handle_t *handle, uint16_t *threshold)
725{
726 uint8_t res;
727 uint8_t buf[2];
728
729 if (handle == NULL) /* check handle */
730 {
731 return 2; /* return error */
732 }
733 if (handle->inited != 1) /* check handle initialization */
734 {
735 return 3; /* return error */
736 }
737
738 res = handle->spi_read(MAX31865_REG_LOW_FAULT_MSB, (uint8_t *)buf, 2); /* write low fault msb */
739 if (res != 0) /* check result */
740 {
741 handle->debug_print("max31865: read failed.\n"); /* read failed */
742
743 return 1; /* return error */
744 }
745 *threshold = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* get raw */
746 *threshold = (*threshold) >> 1; /* get data */
747
748 return 0; /* success return 0 */
749}
750
763{
764 uint8_t res, prev;
765
766 if (handle == NULL) /* check handle */
767 {
768 return 2; /* return error */
769 }
770 if (handle->inited != 1) /* check handle initialization */
771 {
772 return 3; /* return error */
773 }
774
775 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
776 if (res != 0) /* check result */
777 {
778 handle->debug_print("max31865: read failed.\n"); /* read failed */
779
780 return 1; /* return error */
781 }
782 prev &= ~(3 << 2); /* clear control */
783 prev |= control << 2; /* set control */
784
785 return handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
786}
787
800{
801 uint8_t res, prev;
802
803 if (handle == NULL) /* check handle */
804 {
805 return 2; /* return error */
806 }
807 if (handle->inited != 1) /* check handle initialization */
808 {
809 return 3; /* return error */
810 }
811
812 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
813 if (res != 0) /* check result */
814 {
815 handle->debug_print("max31865: read failed.\n"); /* read failed */
816
817 return 1; /* return error */
818 }
819 prev &= 3 << 2; /* get control bits */
820 *status = (max31865_fault_detection_cycle_control_status_t)(prev >> 2); /* get control */
821
822 return 0; /* success return 0 */
823}
824
838uint8_t max31865_single_read(max31865_handle_t *handle, uint16_t *raw, float *temp)
839{
840 uint8_t res, prev;
841 uint8_t buf[2];
842 float resistor;
843 uint16_t times;
844
845 if (handle == NULL) /* check handle */
846 {
847 return 2; /* return error */
848 }
849 if (handle->inited != 1) /* check handle initialization */
850 {
851 return 3; /* return error */
852 }
853
854 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
855 if (res != 0) /* check result */
856 {
857 handle->debug_print("max31865: read failed.\n"); /* read failed */
858
859 return 1; /* return error */
860 }
861 prev |= 1 << 7; /* enable vbias */
862 res = handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
863 if (res != 0) /* check result */
864 {
865 handle->debug_print("max31865: write failed.\n"); /* write failed */
866
867 return 1; /* return error */
868 }
869 handle->delay_ms(15); /* enable vbias */
870
871 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
872 if (res != 0) /* check result */
873 {
874 handle->debug_print("max31865: read failed.\n"); /* read failed */
875
876 return 1; /* return error */
877 }
878 prev |= 1 << 5; /* set shot */
879 prev &= ~(1 << 6); /* set normally off */
880 res = handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
881 if (res != 0) /* check result */
882 {
883 handle->debug_print("max31865: write failed.\n"); /* write failed */
884
885 return 1; /* return error */
886 }
887 times = 50; /* set retry times */
888 while (((prev & (1 << 5)) != 0) && (times != 0)) /* check retry times */
889 {
890 handle->delay_ms(66); /* delay 66 ms */
891 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
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 times--; /* retry times-- */
899 if (times == 0) /* if retry times == 0 */
900 {
901 handle->debug_print("max31865: read timeout.\n"); /* read timeout */
902
903 return 1; /* return error */
904 }
905 }
906 memset(buf, 0, sizeof(uint8_t) * 2); /* clear the buffer */
907 res = handle->spi_read(MAX31865_REG_RTD_MSB, (uint8_t *)buf, 2); /* read rtd msb */
908 if (res != 0) /* check result */
909 {
910 handle->debug_print("max31865: read failed.\n"); /* read failed */
911
912 return 1; /* return error */
913 }
914 *raw = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* get raw data */
915 if (((*raw) & 0x01) != 0)
916 {
917 handle->debug_print("max31865: find rtd fault.\n"); /* find rtd fault */
918
919 return 4; /* return error */
920 }
921 else
922 {
923 (*raw) = (*raw) >> 1; /* get raw data */
924 }
925 if (handle->resistor == MAX31865_RESISTOR_100PT) /* if 100PT */
926 {
927 resistor = 100.0f; /* set resistor type 100 */
928 }
929 else
930 {
931 resistor = 1000.0f; /* set resistor type 1000 */
932 }
933 *temp = a_max31865_temperature_conversion((float)(*raw), resistor, handle->ref_resistor); /* calculate temperature */
934
935 return 0; /* success return 0 */
936}
937
949{
950 uint8_t res, prev;
951
952 if (handle == NULL) /* check handle */
953 {
954 return 2; /* return error */
955 }
956 if (handle->inited != 1) /* check handle initialization */
957 {
958 return 3; /* return error */
959 }
960
961 handle->delay_ms(10); /* delay 10 ms */
962 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
963 if (res != 0) /* check result */
964 {
965 handle->debug_print("max31865: read failed.\n"); /* read failed */
966
967 return 1; /* return error */
968 }
969 prev |= 1 << 7; /* enable vbias */
970 prev |= 1 << 6; /* set auto mode */
971 prev &= ~(1 << 5); /* disable shot */
972
973 return handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
974}
975
987{
988 uint8_t res, prev;
989
990 if (handle == NULL) /* check handle */
991 {
992 return 2; /* return error */
993 }
994 if (handle->inited != 1) /* check handle initialization */
995 {
996 return 3; /* return error */
997 }
998
999 res = handle->spi_read(MAX31865_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
1000 if (res != 0) /* check result */
1001 {
1002 handle->debug_print("max31865: read failed.\n"); /* read failed */
1003
1004 return 1; /* return error */
1005 }
1006 prev &= ~(1 << 7); /* disable vbias */
1007 prev &= ~(1 << 6); /* disable auto mode */
1008 prev &= ~(1 << 5); /* disable shot */
1009
1010 return handle->spi_write(MAX31865_REG_CONFIG | WRITE_ADDRESS_MASK, (uint8_t *)&prev, 1); /* write config */
1011}
1012
1026uint8_t max31865_continuous_read(max31865_handle_t *handle, uint16_t *raw, float *temp)
1027{
1028 uint8_t res;
1029 uint8_t buf[2];
1030 float resistor;
1031
1032 if (handle == NULL) /* check handle */
1033 {
1034 return 2; /* return error */
1035 }
1036 if (handle->inited != 1) /* check handle initialization */
1037 {
1038 return 3; /* return error */
1039 }
1040
1041 memset(buf, 0, sizeof(uint8_t) * 2); /* clear the buffer */
1042 res = handle->spi_read(MAX31865_REG_RTD_MSB, (uint8_t *)buf, 2); /* read rtd msb */
1043 if (res != 0) /* check result */
1044 {
1045 handle->debug_print("max31865: read failed.\n"); /* read failed */
1046
1047 return 1; /* return error */
1048 }
1049 *raw = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* get raw data */
1050 if (((*raw) & 0x01) != 0) /* check error */
1051 {
1052 handle->debug_print("max31865: find rtd fault.\n"); /* find rtd fault */
1053
1054 return 4; /* return error */
1055 }
1056 else
1057 {
1058 (*raw) = (*raw) >> 1; /* get raw data */
1059 }
1060 if (handle->resistor == MAX31865_RESISTOR_100PT) /* choose resistor type */
1061 {
1062 resistor = 100.0f; /* set resistor type 100 */
1063 }
1064 else
1065 {
1066 resistor = 1000.0f; /* set resistor type 1000 */
1067 }
1068 *temp = a_max31865_temperature_conversion((float)(*raw), resistor, handle->ref_resistor); /* calculate */
1069
1070 return 0; /* success return 0 */
1071}
1072
1085uint8_t max31865_set_reg(max31865_handle_t *handle, uint8_t reg, uint8_t value)
1086{
1087 if (handle == NULL) /* check handle */
1088 {
1089 return 2; /* return error */
1090 }
1091 if (handle->inited != 1) /* check handle initialization */
1092 {
1093 return 3; /* return error */
1094 }
1095
1096 return handle->spi_write(reg | WRITE_ADDRESS_MASK, (uint8_t *)&value, 1); /* write to reg */
1097}
1098
1111uint8_t max31865_get_reg(max31865_handle_t *handle, uint8_t reg, uint8_t *value)
1112{
1113 if (handle == NULL) /* check handle */
1114 {
1115 return 2; /* return error */
1116 }
1117 if (handle->inited != 1) /* check handle initialization */
1118 {
1119 return 3; /* return error */
1120 }
1121
1122 return handle->spi_read(reg, (uint8_t *)value, 1); /* read from reg */
1123}
1124
1134{
1135 if (info == NULL) /* check handle */
1136 {
1137 return 2; /* return error */
1138 }
1139
1140 memset(info, 0, sizeof(max31865_info_t)); /* initialize max31865 info structure */
1141 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1142 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1143 strncpy(info->interface, "SPI", 8); /* copy interface name */
1144 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1145 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1146 info->max_current_ma = MAX_CURRENT; /* set maximum current */
1147 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1148 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1149 info->driver_version = DRIVER_VERSION; /* set driver version */
1150
1151 return 0; /* success return 0 */
1152}
#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]