LibDriver MAX31856
Loading...
Searching...
No Matches
driver_max31856_interrupt.c
Go to the documentation of this file.
1
36
38
39static max31856_handle_t gs_handle;
40
49{
50 if (max31856_irq_handler(&gs_handle) != 0)
51 {
52 return 1;
53 }
54
55 return 0;
56}
57
72 float cold_junction_low_fault_threshold_deg,
73 float cold_junction_high_fault_threshold_deg,
74 float temperature_low_fault_threshold_deg,
75 float temperature_high_fault_threshold_deg,
76 void (*callback)(uint8_t type))
77{
78 uint8_t res;
79 int8_t reg8;
80 int16_t reg16;
81 int8_t offset;
82
83 /* link interface function */
91 DRIVER_MAX31856_LINK_RECEIVE_CALLBACK(&gs_handle, callback);
92
93 /* max31856 init */
94 res = max31856_init(&gs_handle);
95 if (res != 0)
96 {
97 max31856_interface_debug_print("max31856: init failed.\n");
98
99 return 1;
100 }
101
102 /* set thermocouple type */
103 res = max31856_set_thermocouple_type(&gs_handle, type);
104 if (res != 0)
105 {
106 max31856_interface_debug_print("max31856: set thermocouple type failed.\n");
107 (void)max31856_deinit(&gs_handle);
108
109 return 1;
110 }
111
112 /* set default open circuit detection */
114 if (res != 0)
115 {
116 max31856_interface_debug_print("max31856: set open circuit detection failed.\n");
117 (void)max31856_deinit(&gs_handle);
118
119 return 1;
120 }
121
122 /* enable cold junction sensor */
124 if (res != 0)
125 {
126 max31856_interface_debug_print("max31856: set cold junction sensor failed.\n");
127 (void)max31856_deinit(&gs_handle);
128
129 return 1;
130 }
131
132 /* set default fault mode */
134 if (res != 0)
135 {
136 max31856_interface_debug_print("max31856: set fault mode failed.\n");
137 (void)max31856_deinit(&gs_handle);
138
139 return 1;
140 }
141
142 /* set default noise rejection filter */
144 if (res != 0)
145 {
146 max31856_interface_debug_print("max31856: set noise rejection filter failed.\n");
147 (void)max31856_deinit(&gs_handle);
148
149 return 1;
150 }
151
152 /* set default sample average */
154 if (res != 0)
155 {
156 max31856_interface_debug_print("max31856: set sample average failed.\n");
157 (void)max31856_deinit(&gs_handle);
158
159 return 1;
160 }
161
162 /* disable cold junction high fault threshold mask */
164 if (res != 0)
165 {
166 max31856_interface_debug_print("max31856: set fault mask failed.\n");
167 (void)max31856_deinit(&gs_handle);
168
169 return 1;
170 }
171
172 /* disable cold junction low fault threshold mask */
174 if (res != 0)
175 {
176 max31856_interface_debug_print("max31856: set fault mask failed.\n");
177 (void)max31856_deinit(&gs_handle);
178
179 return 1;
180 }
181
182 /* disable thermocouple temperature high fault threshold mask */
184 if (res != 0)
185 {
186 max31856_interface_debug_print("max31856: set fault mask failed.\n");
187 (void)max31856_deinit(&gs_handle);
188
189 return 1;
190 }
191
192 /* disable thermocouple temperature low fault threshold mask */
194 if (res != 0)
195 {
196 max31856_interface_debug_print("max31856: set fault mask failed.\n");
197 (void)max31856_deinit(&gs_handle);
198
199 return 1;
200 }
201
202 /* disable over voltage or undervoltage input fault mask */
204 if (res != 0)
205 {
206 max31856_interface_debug_print("max31856: set fault mask failed.\n");
207 (void)max31856_deinit(&gs_handle);
208
209 return 1;
210 }
211
212 /* disable thermocouple open circuit fault mask */
214 if (res != 0)
215 {
216 max31856_interface_debug_print("max31856: set fault mask failed.\n");
217 (void)max31856_deinit(&gs_handle);
218
219 return 1;
220 }
221
222 /* set default cold junction temperature offset */
224 if (res != 0)
225 {
226 max31856_interface_debug_print("max31856: cold junction temperature offset convert to register failed.\n");
227 (void)max31856_deinit(&gs_handle);
228
229 return 1;
230 }
231
232 /* set cold junction temperature offset */
233 res = max31856_set_cold_junction_temperature_offset(&gs_handle, offset);
234 if (res != 0)
235 {
236 max31856_interface_debug_print("max31856: set cold junction temperature offset failed.\n");
237 (void)max31856_deinit(&gs_handle);
238
239 return 1;
240 }
241
242 /* convert */
243 res = max31856_cold_junction_fault_threshold_convert_to_register(&gs_handle, cold_junction_low_fault_threshold_deg, &reg8);
244 if (res != 0)
245 {
246 max31856_interface_debug_print("max31856: cold junction fault threshold convert to register failed.\n");
247 (void)max31856_deinit(&gs_handle);
248
249 return 1;
250 }
251
252 /* set cold junction low fault threshold */
254 if (res != 0)
255 {
256 max31856_interface_debug_print("max31856: set cold junction low fault threshold failed.\n");
257 (void)max31856_deinit(&gs_handle);
258
259 return 1;
260 }
261
262 /* convert */
263 res = max31856_cold_junction_fault_threshold_convert_to_register(&gs_handle, cold_junction_high_fault_threshold_deg, &reg8);
264 if (res != 0)
265 {
266 max31856_interface_debug_print("max31856: cold junction fault threshold convert to register failed.\n");
267 (void)max31856_deinit(&gs_handle);
268
269 return 1;
270 }
271
272 /* set cold junction high fault threshold */
274 if (res != 0)
275 {
276 max31856_interface_debug_print("max31856: set cold junction high fault threshold failed.\n");
277 (void)max31856_deinit(&gs_handle);
278
279 return 1;
280 }
281
282 /* convert */
283 res = max31856_temperature_fault_threshold_convert_to_register(&gs_handle, temperature_low_fault_threshold_deg, &reg16);
284 if (res != 0)
285 {
286 max31856_interface_debug_print("max31856: temperature fault threshold convert to register failed.\n");
287 (void)max31856_deinit(&gs_handle);
288
289 return 1;
290 }
291
292 /* set temperature low fault threshold */
293 res = max31856_set_temperature_low_fault_threshold(&gs_handle, reg16);
294 if (res != 0)
295 {
296 max31856_interface_debug_print("max31856: set temperature low fault threshold failed.\n");
297 (void)max31856_deinit(&gs_handle);
298
299 return 1;
300 }
301
302 /* convert */
303 res = max31856_temperature_fault_threshold_convert_to_register(&gs_handle, temperature_high_fault_threshold_deg, &reg16);
304 if (res != 0)
305 {
306 max31856_interface_debug_print("max31856: temperature fault threshold convert to register failed.\n");
307 (void)max31856_deinit(&gs_handle);
308
309 return 1;
310 }
311
312 /* set temperature high fault threshold */
313 res = max31856_set_temperature_high_fault_threshold(&gs_handle, reg16);
314 if (res != 0)
315 {
316 max31856_interface_debug_print("max31856: set temperature high fault threshold failed.\n");
317 (void)max31856_deinit(&gs_handle);
318
319 return 1;
320 }
321
322 /* clear fault */
323 res = max31856_clear_fault(&gs_handle);
324 if (res != 0)
325 {
326 max31856_interface_debug_print("max31856: clear fault failed.\n");
327 (void)max31856_deinit(&gs_handle);
328
329 return 1;
330 }
331
332 /* start continuous read */
333 res = max31856_start_continuous_read(&gs_handle);
334 if (res != 0)
335 {
336 max31856_interface_debug_print("max31856: start continuous read failed.\n");
337 (void)max31856_deinit(&gs_handle);
338
339 return 1;
340 }
341
342 return 0;
343}
344
353{
354 /* stop continuous read */
355 if (max31856_stop_continuous_read(&gs_handle) != 0)
356 {
357 return 1;
358 }
359
360 /* close max31856 */
361 if (max31856_deinit(&gs_handle) != 0)
362 {
363 return 1;
364 }
365
366 return 0;
367}
368
378uint8_t max31856_interrupt_read(double *temp_deg, uint8_t *fault)
379{
380 uint8_t res;
381 int32_t raw;
382
383 /* continuous read */
384 res = max31856_continuous_read(&gs_handle, &raw, temp_deg);
385 if (res != 0)
386 {
387 return 1;
388 }
389
390 /* get fault status */
391 res = max31856_get_fault_status(&gs_handle, fault);
392 if (res != 0)
393 {
394 return 1;
395 }
396
397 return 0;
398}
399
409{
410 int16_t raw;
411
412 /* read cold junction temperature */
413 if (max31856_read_cold_junction_temperature(&gs_handle, &raw, temp_deg) != 0)
414 {
415 return 1;
416 }
417
418 return 0;
419}
driver max31856 interrupt include file
uint8_t max31856_stop_continuous_read(max31856_handle_t *handle)
stop the chip reading
uint8_t max31856_set_cold_junction_high_fault_threshold(max31856_handle_t *handle, int8_t threshold)
set cold junction high fault threshold
uint8_t max31856_get_fault_status(max31856_handle_t *handle, uint8_t *status)
get fault status
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_clear_fault(max31856_handle_t *handle)
clear fault
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_set_temperature_low_fault_threshold(max31856_handle_t *handle, int16_t threshold)
set temperature low fault threshold
uint8_t max31856_continuous_read(max31856_handle_t *handle, int32_t *raw, double *deg)
read data from the chip continuously
uint8_t max31856_temperature_fault_threshold_convert_to_register(max31856_handle_t *handle, float deg, int16_t *reg)
convert the temperature fault threshold to the register raw data
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
uint8_t max31856_set_cold_junction_low_fault_threshold(max31856_handle_t *handle, int8_t threshold)
set cold junction low fault threshold
struct max31856_handle_s max31856_handle_t
max31856 handle structure definition
uint8_t max31856_cold_junction_fault_threshold_convert_to_register(max31856_handle_t *handle, float deg, int8_t *reg)
convert the cold junction fault threshold to the register raw data
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_irq_handler(max31856_handle_t *handle)
irq handler
uint8_t max31856_set_cold_junction_temperature_offset(max31856_handle_t *handle, int8_t offset)
set cold junction temperature offset
uint8_t max31856_set_temperature_high_fault_threshold(max31856_handle_t *handle, int16_t threshold)
set temperature high fault threshold
@ MAX31856_BOOL_TRUE
@ MAX31856_BOOL_FALSE
@ 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_interrupt_init(max31856_thermocouple_type_t type, float cold_junction_low_fault_threshold_deg, float cold_junction_high_fault_threshold_deg, float temperature_low_fault_threshold_deg, float temperature_high_fault_threshold_deg, void(*callback)(uint8_t type))
interrupt example init
#define MAX31856_INTERRUPT_DEFAULT_NOISE_REJECTION_FILTER
#define MAX31856_INTERRUPT_DEFAULT_COLD_JUNCTION_TEMPERATURE_OFFSET
#define MAX31856_INTERRUPT_DEFAULT_FAULT_MODE
#define MAX31856_INTERRUPT_DEFAULT_OPEN_CIRCUIT_DETECTION
max31856 interrupt example default definition
uint8_t max31856_interrupt_deinit(void)
interrupt example deinit
uint8_t max31856_interrupt_irq_handler(void)
interrupt irq callback
uint8_t max31856_interrupt_read(double *temp_deg, uint8_t *fault)
interrupt example read the temperature
#define MAX31856_INTERRUPT_DEFAULT_SAMPLE_AVERAGE
uint8_t max31856_interrupt_read_cold_junction_temperature(double *temp_deg)
interrupt example read the cold junction temperature
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
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