LibDriver MAX31865
Loading...
Searching...
No Matches
driver_max31865_register_test.c
Go to the documentation of this file.
1
37
39#include <math.h>
40#include <stdlib.h>
41
42static max31865_handle_t gs_handle;
43
52{
53 uint8_t res;
54 float resistor_in;
55 float resistor_out;
56 uint16_t threshold_in;
57 uint16_t threshold_out;
58 max31865_info_t info;
60 max31865_wire_t wire;
61 max31865_resistor_t resistor;
62 max31865_bool_t enable;
64
65 /* link function */
73
74 /* get chip information */
75 res = max31865_info(&info);
76 if (res != 0)
77 {
78 max31865_interface_debug_print("max31865: get info failed.\n");
79
80 return 1;
81 }
82 else
83 {
84 /* print chip information */
85 max31865_interface_debug_print("max31865: chip is %s.\n", info.chip_name);
86 max31865_interface_debug_print("max31865: manufacturer is %s.\n", info.manufacturer_name);
87 max31865_interface_debug_print("max31865: interface is %s.\n", info.interface);
88 max31865_interface_debug_print("max31865: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
89 max31865_interface_debug_print("max31865: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
90 max31865_interface_debug_print("max31865: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
91 max31865_interface_debug_print("max31865: max current is %0.2fmA.\n", info.max_current_ma);
92 max31865_interface_debug_print("max31865: max temperature is %0.1fC.\n", info.temperature_max);
93 max31865_interface_debug_print("max31865: min temperature is %0.1fC.\n", info.temperature_min);
94 }
95
96 /* max31865 init */
97 res = max31865_init(&gs_handle);
98 if (res != 0)
99 {
100 max31865_interface_debug_print("max31865: init failed.\n");
101
102 return 1;
103 }
104
105 /* start register test */
106 max31865_interface_debug_print("max31865: start register test.\n");
107
108 /* max31865_set_filter_select/max31865_get_filter_select test */
109 max31865_interface_debug_print("max31865: max31865_set_filter_select/max31865_get_filter_select test.\n");
110
111 /* set 60Hz */
113 if (res != 0)
114 {
115 max31865_interface_debug_print("max31865: set filter select failed.\n");
116 (void)max31865_deinit(&gs_handle);
117
118 return 1;
119 }
120 max31865_interface_debug_print("max31865: set filter select 60Hz.\n");
121 res = max31865_get_filter_select(&gs_handle, &filter);
122 if (res != 0)
123 {
124 max31865_interface_debug_print("max31865: get filter select failed.\n");
125 (void)max31865_deinit(&gs_handle);
126
127 return 1;
128 }
129 max31865_interface_debug_print("max31865: check filter select %s.\n", filter == MAX31865_FILTER_SELECT_60HZ ? "ok" : "error");
130
131 /* set 50Hz */
133 if (res != 0)
134 {
135 max31865_interface_debug_print("max31865: set filter select failed.\n");
136 (void)max31865_deinit(&gs_handle);
137
138 return 1;
139 }
140 max31865_interface_debug_print("max31865: set filter select 50Hz.\n");
141 res = max31865_get_filter_select(&gs_handle, &filter);
142 if (res != 0)
143 {
144 max31865_interface_debug_print("max31865: get filter select failed.\n");
145 (void)max31865_deinit(&gs_handle);
146
147 return 1;
148 }
149 max31865_interface_debug_print("max31865: check filter select %s.\n", filter == MAX31865_FILTER_SELECT_50HZ ? "ok" : "error");
150
151 /* max31865_set_wire/max31865_get_wire test */
152 max31865_interface_debug_print("max31865: max31865_set_wire/max31865_get_wire test.\n");
153
154 /* set wire 2 */
155 res = max31865_set_wire(&gs_handle, MAX31865_WIRE_2);
156 if (res != 0)
157 {
158 max31865_interface_debug_print("max31865: set wire failed.\n");
159 (void)max31865_deinit(&gs_handle);
160
161 return 1;
162 }
163 max31865_interface_debug_print("max31865: set 2 wire.\n");
164 res = max31865_get_wire(&gs_handle, &wire);
165 if (res != 0)
166 {
167 max31865_interface_debug_print("max31865: get wire failed.\n");
168 (void)max31865_deinit(&gs_handle);
169
170 return 1;
171 }
172 max31865_interface_debug_print("max31865: check wire %s.\n", wire == MAX31865_WIRE_2 ? "ok" : "error");
173
174 /* set wire 3 */
175 res = max31865_set_wire(&gs_handle, MAX31865_WIRE_3);
176 if (res != 0)
177 {
178 max31865_interface_debug_print("max31865: set wire failed.\n");
179 (void)max31865_deinit(&gs_handle);
180
181 return 1;
182 }
183 max31865_interface_debug_print("max31865: set 3 wire.\n");
184 res = max31865_get_wire(&gs_handle, &wire);
185 if (res != 0)
186 {
187 max31865_interface_debug_print("max31865: get wire failed.\n");
188 (void)max31865_deinit(&gs_handle);
189
190 return 1;
191 }
192 max31865_interface_debug_print("max31865: check wire %s.\n", wire == MAX31865_WIRE_3 ? "ok" : "error");
193
194 /* set wire 4 */
195 res = max31865_set_wire(&gs_handle, MAX31865_WIRE_4);
196 if (res != 0)
197 {
198 max31865_interface_debug_print("max31865: set wire failed.\n");
199 (void)max31865_deinit(&gs_handle);
200
201 return 1;
202 }
203 max31865_interface_debug_print("max31865: set 4 wire.\n");
204 res = max31865_get_wire(&gs_handle, &wire);
205 if (res != 0)
206 {
207 max31865_interface_debug_print("max31865: get wire failed.\n");
208 (void)max31865_deinit(&gs_handle);
209
210 return 1;
211 }
212 max31865_interface_debug_print("max31865: check wire %s.\n", wire == MAX31865_WIRE_4 ? "ok" : "error");
213
214 /* max31865_set_resistor/max31865_get_resistor test */
215 max31865_interface_debug_print("max31865: max31865_set_resistor/max31865_get_resistor test.\n");
216
217 /* set 100PT */
219 if (res != 0)
220 {
221 max31865_interface_debug_print("max31865: set resistor failed.\n");
222 (void)max31865_deinit(&gs_handle);
223
224 return 1;
225 }
226 max31865_interface_debug_print("max31865: set 100 pt resistor.\n");
227 res = max31865_get_resistor(&gs_handle, &resistor);
228 if (res != 0)
229 {
230 max31865_interface_debug_print("max31865: get resistor failed.\n");
231 (void)max31865_deinit(&gs_handle);
232
233 return 1;
234 }
235 max31865_interface_debug_print("max31865: check resistor %s.\n", resistor == MAX31865_RESISTOR_100PT ? "ok" : "error");
236
237 /* set 1000PT */
239 if (res != 0)
240 {
241 max31865_interface_debug_print("max31865: set resistor failed.\n");
242 (void)max31865_deinit(&gs_handle);
243
244 return 1;
245 }
246 max31865_interface_debug_print("max31865: set 1000 pt resistor.\n");
247 res = max31865_get_resistor(&gs_handle, &resistor);
248 if (res != 0)
249 {
250 max31865_interface_debug_print("max31865: get resistor failed.\n");
251 (void)max31865_deinit(&gs_handle);
252
253 return 1;
254 }
255 max31865_interface_debug_print("max31865: check resistor %s.\n", resistor == MAX31865_RESISTOR_1000PT ? "ok" : "error");
256
257 /* max31865_set_reference_resistor/max31865_get_reference_resistor test */
258 max31865_interface_debug_print("max31865: max31865_set_reference_resistor/max31865_get_reference_resistor test.\n");
259 resistor_in = (float)(rand()%65536)/100.0f;
260 res = max31865_set_reference_resistor(&gs_handle, resistor_in);
261 if (res != 0)
262 {
263 max31865_interface_debug_print("max31865: set reference resistor failed.\n");
264 (void)max31865_deinit(&gs_handle);
265
266 return 1;
267 }
268 max31865_interface_debug_print("max31865: set reference resistor %f.\n", resistor_in);
269 res = max31865_get_reference_resistor(&gs_handle, (float *)&resistor_out);
270 if (res != 0)
271 {
272 max31865_interface_debug_print("max31865: get reference resistor failed.\n");
273 (void)max31865_deinit(&gs_handle);
274
275 return 1;
276 }
277 max31865_interface_debug_print("max31865: check reference resistor %s.\n", fabsf(resistor_out - resistor_in) < 0.000001f ? "ok" : "error");
278
279 /* max31865_set_vbias/max31865_get_vbias test */
280 max31865_interface_debug_print("max31865: max31865_set_vbias/max31865_get_vbias test.\n");
281
282 /* enable */
283 res = max31865_set_vbias(&gs_handle, MAX31865_BOOL_TRUE);
284 if (res != 0)
285 {
286 max31865_interface_debug_print("max31865: set vbias failed.\n");
287 (void)max31865_deinit(&gs_handle);
288
289 return 1;
290 }
291 max31865_interface_debug_print("max31865: enable vbias.\n");
292 res = max31865_get_vbias(&gs_handle, &enable);
293 if (res != 0)
294 {
295 max31865_interface_debug_print("max31865: get vbias failed.\n");
296 (void)max31865_deinit(&gs_handle);
297
298 return 1;
299 }
300 max31865_interface_debug_print("max31865: check vbias %s.\n", enable == MAX31865_BOOL_TRUE ? "ok" : "error");
301
302 /* disable */
303 res = max31865_set_vbias(&gs_handle, MAX31865_BOOL_FALSE);
304 if (res != 0)
305 {
306 max31865_interface_debug_print("max31865: set vbias failed.\n");
307 (void)max31865_deinit(&gs_handle);
308
309 return 1;
310 }
311 max31865_interface_debug_print("max31865: disable vbias.\n");
312 res = max31865_get_vbias(&gs_handle, &enable);
313 if (res != 0)
314 {
315 max31865_interface_debug_print("max31865: get vbias failed.\n");
316 (void)max31865_deinit(&gs_handle);
317
318 return 1;
319 }
320 max31865_interface_debug_print("max31865: check vbias %s.\n", enable == MAX31865_BOOL_FALSE ? "ok" : "error");
321
322 /* max31865_set_fault_detection_cycle_control test */
323 max31865_interface_debug_print("max31865: max31865_set_fault_detection_cycle_control test.\n");
324
325 /* no action */
327 if (res != 0)
328 {
329 max31865_interface_debug_print("max31865: set fault detection cycle control failed.\n");
330 (void)max31865_deinit(&gs_handle);
331
332 return 1;
333 }
334 max31865_interface_debug_print("max31865: check fault detection cycle control %s.\n", res==0?"ok":"error");
335
336 /* automatic delay */
338 if (res != 0)
339 {
340 max31865_interface_debug_print("max31865: set fault detection cycle control failed.\n");
341 (void)max31865_deinit(&gs_handle);
342
343 return 1;
344 }
345 max31865_interface_debug_print("max31865: check fault detection cycle control %s.\n", res==0?"ok":"error");
346
347 /* manual delay cycle 1 */
349 if (res != 0)
350 {
351 max31865_interface_debug_print("max31865: set fault detection cycle control failed.\n");
352 (void)max31865_deinit(&gs_handle);
353
354 return 1;
355 }
356 max31865_interface_debug_print("max31865: check fault detection cycle control %s.\n", res==0?"ok":"error");
357
358 /* manual delay cycle 2 */
360 if (res != 0)
361 {
362 max31865_interface_debug_print("max31865: set fault detection cycle control failed.\n");
363 (void)max31865_deinit(&gs_handle);
364
365 return 1;
366 }
367 max31865_interface_debug_print("max31865: check fault detection cycle control %s.\n", res==0?"ok":"error");
368
369 /* max31865_get_fault_detection_cycle_control test */
370 max31865_interface_debug_print("max31865: max31865_get_fault_detection_cycle_control test.\n");
371 res = max31865_get_fault_detection_cycle_control(&gs_handle, &status);
372 if (res != 0)
373 {
374 max31865_interface_debug_print("max31865: get fault detection cycle control failed.\n");
375 (void)max31865_deinit(&gs_handle);
376
377 return 1;
378 }
379 max31865_interface_debug_print("max31865: check get fault detection cycle control %s 0x%02X.\n", res==0?"ok":"error", status);
380
381 /* max31865_clear_fault_status test */
382 max31865_interface_debug_print("max31865: max31865_clear_fault_status test.\n");
383 res = max31865_clear_fault_status(&gs_handle);
384 if (res != 0)
385 {
386 max31865_interface_debug_print("max31865: clear fault status failed.\n");
387 (void)max31865_deinit(&gs_handle);
388
389 return 1;
390 }
391 max31865_interface_debug_print("max31865: check clear fault status %s.\n", res == 0 ? "ok" : "error");
392
393 /* max31865_set_high_fault_threshold/max31865_get_high_fault_threshold test */
394 max31865_interface_debug_print("max31865: max31865_set_high_fault_threshold/max31865_get_high_fault_threshold test.\n");
395 threshold_in = rand() % 32768;
396 res = max31865_set_high_fault_threshold(&gs_handle, threshold_in);
397 if (res != 0)
398 {
399 max31865_interface_debug_print("max31865: set high fault threshold failed.\n");
400 (void)max31865_deinit(&gs_handle);
401
402 return 1;
403 }
404 max31865_interface_debug_print("max31865: set high fault threshold %d.\n", threshold_in);
405 res = max31865_get_high_fault_threshold(&gs_handle, (uint16_t *)&threshold_out);
406 if (res != 0)
407 {
408 max31865_interface_debug_print("max31865: get high fault threshold failed.\n");
409 (void)max31865_deinit(&gs_handle);
410
411 return 1;
412 }
413 max31865_interface_debug_print("max31865: check high fault threshold %s.\n", threshold_out == threshold_in ? "ok" : "error");
414
415 /* max31865_set_low_fault_threshold/max31865_get_low_fault_threshold test */
416 max31865_interface_debug_print("max31865: max31865_set_low_fault_threshold/max31865_get_low_fault_threshold test.\n");
417 threshold_in = rand() % 32768;
418 res = max31865_set_low_fault_threshold(&gs_handle, threshold_in);
419 if (res != 0)
420 {
421 max31865_interface_debug_print("max31865: set low fault threshold failed.\n");
422 (void)max31865_deinit(&gs_handle);
423
424 return 1;
425 }
426 max31865_interface_debug_print("max31865: set low fault threshold %d.\n", threshold_in);
427 res = max31865_get_low_fault_threshold(&gs_handle, (uint16_t *)&threshold_out);
428 if (res != 0)
429 {
430 max31865_interface_debug_print("max31865: get low fault threshold failed.\n");
431 (void)max31865_deinit(&gs_handle);
432
433 return 1;
434 }
435 max31865_interface_debug_print("max31865: check low fault threshold %s.\n", threshold_out == threshold_in ? "ok" : "error");
436
437 /* finish register test */
438 max31865_interface_debug_print("max31865: finish register test.\n");
439 (void)max31865_deinit(&gs_handle);
440
441 return 0;
442}
driver max31865 register 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_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
max31865_resistor_t
max31865 resistor type enumeration definition
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_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_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_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_deinit(max31865_handle_t *handle)
close the chip
@ MAX31865_BOOL_TRUE
@ MAX31865_BOOL_FALSE
@ MAX31865_RESISTOR_1000PT
@ MAX31865_RESISTOR_100PT
@ MAX31865_FAULT_DETECTION_CYCLE_CONTROL_MANUAL_DELAY_CYCLE_1
@ MAX31865_FAULT_DETECTION_CYCLE_CONTROL_NO_ACTION
@ MAX31865_FAULT_DETECTION_CYCLE_CONTROL_MANUAL_DELAY_CYCLE_2
@ MAX31865_FAULT_DETECTION_CYCLE_CONTROL_AUTOMATIC_DELAY
@ MAX31865_WIRE_4
@ MAX31865_WIRE_3
@ MAX31865_WIRE_2
@ MAX31865_FILTER_SELECT_60HZ
@ 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_register_test(void)
register test
char manufacturer_name[32]