LibDriver MAX31856
Loading...
Searching...
No Matches
driver_max31856_read_test.c
Go to the documentation of this file.
1
36
38
39static max31856_handle_t gs_handle;
40
51{
52 uint8_t res;
53 int8_t offset;
54 uint32_t i;
55 max31856_info_t info;
56
57 /* link interface function */
66
67 /* max31856 info */
68 res = max31856_info(&info);
69 if (res != 0)
70 {
71 max31856_interface_debug_print("max31856: get info failed.\n");
72
73 return 1;
74 }
75 else
76 {
77 /* print chip information */
78 max31856_interface_debug_print("max31856: chip is %s.\n", info.chip_name);
79 max31856_interface_debug_print("max31856: manufacturer is %s.\n", info.manufacturer_name);
80 max31856_interface_debug_print("max31856: interface is %s.\n", info.interface);
81 max31856_interface_debug_print("max31856: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
82 max31856_interface_debug_print("max31856: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
83 max31856_interface_debug_print("max31856: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
84 max31856_interface_debug_print("max31856: max current is %0.2fmA.\n", info.max_current_ma);
85 max31856_interface_debug_print("max31856: max temperature is %0.1fC.\n", info.temperature_max);
86 max31856_interface_debug_print("max31856: min temperature is %0.1fC.\n", info.temperature_min);
87 }
88
89 /* start read test */
90 max31856_interface_debug_print("max31856: start read test.\n");
91
92 /* max31856 init */
93 res = max31856_init(&gs_handle);
94 if (res != 0)
95 {
96 max31856_interface_debug_print("max31856: init failed.\n");
97
98 return 1;
99 }
100
101 /* set thermocouple type */
102 res = max31856_set_thermocouple_type(&gs_handle, type);
103 if (res != 0)
104 {
105 max31856_interface_debug_print("max31856: set thermocouple type failed.\n");
106 (void)max31856_deinit(&gs_handle);
107
108 return 1;
109 }
110
111 /* set open circuit detection mode3 */
113 if (res != 0)
114 {
115 max31856_interface_debug_print("max31856: set open circuit detection failed.\n");
116 (void)max31856_deinit(&gs_handle);
117
118 return 1;
119 }
120
121 /* enable cold junction sensor */
123 if (res != 0)
124 {
125 max31856_interface_debug_print("max31856: set cold junction sensor failed.\n");
126 (void)max31856_deinit(&gs_handle);
127
128 return 1;
129 }
130
131 /* set fault interrupt mode */
133 if (res != 0)
134 {
135 max31856_interface_debug_print("max31856: set fault mode failed.\n");
136 (void)max31856_deinit(&gs_handle);
137
138 return 1;
139 }
140
141 /* set noise rejection filter 50hz */
143 if (res != 0)
144 {
145 max31856_interface_debug_print("max31856: set noise rejection filter failed.\n");
146 (void)max31856_deinit(&gs_handle);
147
148 return 1;
149 }
150
151 /* set sample average 16 */
153 if (res != 0)
154 {
155 max31856_interface_debug_print("max31856: set sample average failed.\n");
156 (void)max31856_deinit(&gs_handle);
157
158 return 1;
159 }
160
161 /* enable cold junction high fault threshold mask */
163 if (res != 0)
164 {
165 max31856_interface_debug_print("max31856: set fault mask failed.\n");
166 (void)max31856_deinit(&gs_handle);
167
168 return 1;
169 }
170
171 /* enable cold junction low fault threshold mask */
173 if (res != 0)
174 {
175 max31856_interface_debug_print("max31856: set fault mask failed.\n");
176 (void)max31856_deinit(&gs_handle);
177
178 return 1;
179 }
180
181 /* enable thermocouple temperature high fault threshold mask */
183 if (res != 0)
184 {
185 max31856_interface_debug_print("max31856: set fault mask failed.\n");
186 (void)max31856_deinit(&gs_handle);
187
188 return 1;
189 }
190
191 /* enable thermocouple temperature low fault threshold mask */
193 if (res != 0)
194 {
195 max31856_interface_debug_print("max31856: set fault mask failed.\n");
196 (void)max31856_deinit(&gs_handle);
197
198 return 1;
199 }
200
201 /* enable over voltage or undervoltage input fault mask */
203 if (res != 0)
204 {
205 max31856_interface_debug_print("max31856: set fault mask failed.\n");
206 (void)max31856_deinit(&gs_handle);
207
208 return 1;
209 }
210
211 /* enable thermocouple open circuit fault mask */
213 if (res != 0)
214 {
215 max31856_interface_debug_print("max31856: set fault mask failed.\n");
216 (void)max31856_deinit(&gs_handle);
217
218 return 1;
219 }
220
221 /* 0.0 offset */
223 if (res != 0)
224 {
225 max31856_interface_debug_print("max31856: cold junction temperature offset convert to register failed.\n");
226 (void)max31856_deinit(&gs_handle);
227
228 return 1;
229 }
230
231 /* set cold junction temperature offset */
232 res = max31856_set_cold_junction_temperature_offset(&gs_handle, offset);
233 if (res != 0)
234 {
235 max31856_interface_debug_print("max31856: set cold junction temperature offset failed.\n");
236 (void)max31856_deinit(&gs_handle);
237
238 return 1;
239 }
240
241 /* clear fault */
242 res = max31856_clear_fault(&gs_handle);
243 if (res != 0)
244 {
245 max31856_interface_debug_print("max31856: clear fault failed.\n");
246 (void)max31856_deinit(&gs_handle);
247
248 return 1;
249 }
250
251 /* cold junction temperature read test */
252 max31856_interface_debug_print("max31856: cold junction temperature read test.\n");
253
254 for (i = 0; i < times; i++)
255 {
256 int16_t raw;
257 double deg;
258
259 /* delay 1000ms */
261
262 /* read temperature */
263 res = max31856_read_cold_junction_temperature(&gs_handle, &raw, &deg);
264 if (res != 0)
265 {
266 max31856_interface_debug_print("max31856: read cold junction temperature failed.\n");
267 (void)max31856_deinit(&gs_handle);
268
269 return 1;
270 }
271
272 /* output */
273 max31856_interface_debug_print("max31856: cold junction temperature is %0.03fC.\n", deg);
274 }
275
276 /* single read test */
277 max31856_interface_debug_print("max31856: single read test.\n");
278
279 for (i = 0; i < times; i++)
280 {
281 int32_t raw;
282 double deg;
283
284 /* delay 1000ms */
286
287 /* single read */
288 res = max31856_single_read(&gs_handle, &raw, &deg);
289 if (res != 0)
290 {
291 max31856_interface_debug_print("max31856: single read failed.\n");
292 (void)max31856_deinit(&gs_handle);
293
294 return 1;
295 }
296
297 /* output */
298 max31856_interface_debug_print("max31856: temperature is %0.03fC.\n", deg);
299 }
300
301 /* continuous read test */
302 max31856_interface_debug_print("max31856: continuous read test.\n");
303
304 /* start continuous read */
305 res = max31856_start_continuous_read(&gs_handle);
306 if (res != 0)
307 {
308 max31856_interface_debug_print("max31856: start continuous read failed.\n");
309 (void)max31856_deinit(&gs_handle);
310
311 return 1;
312 }
313
314 for (i = 0; i < times; i++)
315 {
316 int32_t raw;
317 double deg;
318
319 /* delay 1000ms */
321
322 /* continuous read */
323 res = max31856_continuous_read(&gs_handle, &raw, &deg);
324 if (res != 0)
325 {
326 max31856_interface_debug_print("max31856: continuous read failed.\n");
327 (void)max31856_deinit(&gs_handle);
328
329 return 1;
330 }
331
332 /* output */
333 max31856_interface_debug_print("max31856: temperature is %0.03fC.\n", deg);
334 }
335
336 /* stop continuous read */
337 res = max31856_stop_continuous_read(&gs_handle);
338 if (res != 0)
339 {
340 max31856_interface_debug_print("max31856: stop continuous read failed.\n");
341 (void)max31856_deinit(&gs_handle);
342
343 return 1;
344 }
345
346 /* finish read test */
347 max31856_interface_debug_print("max31856: finish read test.\n");
348 (void)max31856_deinit(&gs_handle);
349
350 return 0;
351}
driver max31856 read test 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_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
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_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_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_continuous_read(max31856_handle_t *handle, int32_t *raw, double *deg)
read data from the chip continuously
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_init(max31856_handle_t *handle)
initialize the chip
struct max31856_handle_s max31856_handle_t
max31856 handle structure definition
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_set_fault_mode(max31856_handle_t *handle, max31856_fault_mode_t mode)
set fault mode
uint8_t max31856_set_cold_junction_temperature_offset(max31856_handle_t *handle, int8_t offset)
set cold junction temperature offset
@ MAX31856_BOOL_TRUE
@ MAX31856_OPEN_CIRCUIT_DETECTION_MODE3
@ MAX31856_SAMPLE_AVERAGE_16
@ MAX31856_NOISE_REJECTION_FILTER_50HZ
@ MAX31856_FAULT_MODE_INTERRUPT
@ MAX31856_FAULT_MASK_OPEN
@ MAX31856_FAULT_MASK_TCLOW
@ MAX31856_FAULT_MASK_CJHIGH
@ MAX31856_FAULT_MASK_TCHIGH
@ MAX31856_FAULT_MASK_OVUV
@ MAX31856_FAULT_MASK_CJLOW
uint8_t max31856_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
void max31856_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t max31856_interface_spi_init(void)
interface spi bus init
void max31856_interface_debug_print(const char *const fmt,...)
interface print format data
void max31856_interface_receive_callback(uint8_t type)
interface receive callback
uint8_t max31856_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t max31856_interface_spi_deinit(void)
interface spi bus deinit
uint8_t max31856_read_test(max31856_thermocouple_type_t type, uint32_t times)
read test
char manufacturer_name[32]