LibDriver MAX31865
Loading...
Searching...
No Matches
driver_max31865_read_test.c
Go to the documentation of this file.
1
37
39
40static max31865_handle_t gs_handle;
41
53uint8_t max31865_read_test(max31865_wire_t wire, max31865_resistor_t type, float ref_resistor, uint32_t times)
54{
55 uint8_t res;
56 uint32_t i;
57 max31865_info_t info;
58
59 /* link function */
67
68 /* get chip information */
69 res = max31865_info(&info);
70 if (res != 0)
71 {
72 max31865_interface_debug_print("max31865: get info failed.\n");
73
74 return 1;
75 }
76 else
77 {
78 /* print chip information */
79 max31865_interface_debug_print("max31865: chip is %s.\n", info.chip_name);
80 max31865_interface_debug_print("max31865: manufacturer is %s.\n", info.manufacturer_name);
81 max31865_interface_debug_print("max31865: interface is %s.\n", info.interface);
82 max31865_interface_debug_print("max31865: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
83 max31865_interface_debug_print("max31865: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
84 max31865_interface_debug_print("max31865: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
85 max31865_interface_debug_print("max31865: max current is %0.2fmA.\n", info.max_current_ma);
86 max31865_interface_debug_print("max31865: max temperature is %0.1fC.\n", info.temperature_max);
87 max31865_interface_debug_print("max31865: min temperature is %0.1fC.\n", info.temperature_min);
88 }
89
90 /* max31865 init */
91 res = max31865_init(&gs_handle);
92 if (res != 0)
93 {
94 max31865_interface_debug_print("max31865: init failed.\n");
95
96 return 1;
97 }
98
99 /* set filter select 50Hz */
101 if (res != 0)
102 {
103 max31865_interface_debug_print("max31865: set filter select failed.\n");
104 (void)max31865_deinit(&gs_handle);
105
106 return 1;
107 }
108
109 /* set wire */
110 res = max31865_set_wire(&gs_handle, wire);
111 if (res != 0)
112 {
113 max31865_interface_debug_print("max31865: set wire failed.\n");
114 (void)max31865_deinit(&gs_handle);
115
116 return 1;
117 }
118
119 /* set resistor type */
120 res = max31865_set_resistor(&gs_handle, type);
121 if (res != 0)
122 {
123 max31865_interface_debug_print("max31865: set resistor type failed.\n");
124 (void)max31865_deinit(&gs_handle);
125
126 return 1;
127 }
128
129 /* set reference resistor */
130 res = max31865_set_reference_resistor(&gs_handle, ref_resistor);
131 if (res != 0)
132 {
133 max31865_interface_debug_print("max31865: set reference resistor failed.\n");
134 (void)max31865_deinit(&gs_handle);
135
136 return 1;
137 }
138
139 /* set automatic delay */
141 if (res != 0)
142 {
143 max31865_interface_debug_print("max31865: set fault detection cycle control failed.\n");
144 (void)max31865_deinit(&gs_handle);
145
146 return 1;
147 }
148
149 /* set high fault threshold */
150 res = max31865_set_high_fault_threshold(&gs_handle, 0xFFFEU);
151 if (res != 0)
152 {
153 max31865_interface_debug_print("max31865: set high fault threshold failed.\n");
154 (void)max31865_deinit(&gs_handle);
155
156 return 1;
157 }
158
159 /* set low fault threshold */
160 res = max31865_set_low_fault_threshold(&gs_handle, 0x0000U);
161 if (res != 0)
162 {
163 max31865_interface_debug_print("max31865: set low fault threshold failed.\n");
164 (void)max31865_deinit(&gs_handle);
165
166 return 1;
167 }
168
169 /* start read test */
170 max31865_interface_debug_print("max31865: start read test.\n");
171
172 /* continuous read test test */
173 max31865_interface_debug_print("max31865: continuous read test test.\n");
174
175 /* start continuous */
176 res = max31865_start_continuous_read(&gs_handle);
177 if (res != 0)
178 {
179 max31865_interface_debug_print("max31865: start continuous read failed.\n");
180 (void)max31865_deinit(&gs_handle);
181
182 return 1;
183 }
184 for (i = 0; i < times; i++)
185 {
186 uint16_t raw;
187 float temp;
188
189 /* delay 2000 ms */
191
192 /* read data */
193 res = max31865_continuous_read(&gs_handle, (uint16_t *)&raw, (float *)&temp);
194 if (res != 0)
195 {
196 max31865_interface_debug_print("max31865: read failed.\n");
197 (void)max31865_deinit(&gs_handle);
198
199 return 1;
200 }
201 max31865_interface_debug_print("max31865: continuous read %0.2fC.\n", temp);
202 }
203
204 /* stop continuous read */
205 res = max31865_stop_continuous_read(&gs_handle);
206 if (res != 0)
207 {
208 max31865_interface_debug_print("max31865: stop continuous read failed.\n");
209 (void)max31865_deinit(&gs_handle);
210
211 return 1;
212 }
213
214 /* single read test */
215 max31865_interface_debug_print("max31865: single read test.\n");
216 for (i = 0; i < times; i++)
217 {
218 uint16_t raw;
219 float temp;
220
221 /* delay 2000 ms */
223
224 /* single read */
225 res = max31865_single_read(&gs_handle, (uint16_t *)&raw, (float *)&temp);
226 if (res != 0)
227 {
228 max31865_interface_debug_print("max31865: read failed.\n");
229 (void)max31865_deinit(&gs_handle);
230
231 return 1;
232 }
233 max31865_interface_debug_print("max31865: single read %0.2fC.\n", temp);
234 }
235
236 /* finish read test */
237 max31865_interface_debug_print("max31865: finish read test.\n");
238 (void)max31865_deinit(&gs_handle);
239
240 return 0;
241}
driver max31865 read test header file
uint8_t max31865_set_low_fault_threshold(max31865_handle_t *handle, uint16_t threshold)
set the low fault threshold
uint8_t max31865_set_wire(max31865_handle_t *handle, max31865_wire_t wire)
set the pt resistor wire
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_wire_t
max31865 wire type enumeration definition
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_set_filter_select(max31865_handle_t *handle, max31865_filter_select_t filter)
set the filter type
uint8_t max31865_stop_continuous_read(max31865_handle_t *handle)
stop reading
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_start_continuous_read(max31865_handle_t *handle)
start reading
uint8_t max31865_deinit(max31865_handle_t *handle)
close the chip
@ MAX31865_FAULT_DETECTION_CYCLE_CONTROL_AUTOMATIC_DELAY
@ MAX31865_FILTER_SELECT_50HZ
uint8_t max31865_interface_spi_init(void)
interface spi bus init
void max31865_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t max31865_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t max31865_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t max31865_interface_spi_deinit(void)
interface spi bus deinit
void max31865_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t max31865_read_test(max31865_wire_t wire, max31865_resistor_t type, float ref_resistor, uint32_t times)
read test
char manufacturer_name[32]