LibDriver MAX31856
Loading...
Searching...
No Matches
driver_max31856_shot.c
Go to the documentation of this file.
1
36
38
39static max31856_handle_t gs_handle;
40
50{
51 uint8_t res;
52 int8_t offset;
53
54 /* link interface function */
63
64 /* max31856 init */
65 res = max31856_init(&gs_handle);
66 if (res != 0)
67 {
68 max31856_interface_debug_print("max31856: init failed.\n");
69
70 return 1;
71 }
72
73 /* set thermocouple type */
74 res = max31856_set_thermocouple_type(&gs_handle, type);
75 if (res != 0)
76 {
77 max31856_interface_debug_print("max31856: set thermocouple type failed.\n");
78 (void)max31856_deinit(&gs_handle);
79
80 return 1;
81 }
82
83 /* set default open circuit detection */
85 if (res != 0)
86 {
87 max31856_interface_debug_print("max31856: set open circuit detection failed.\n");
88 (void)max31856_deinit(&gs_handle);
89
90 return 1;
91 }
92
93 /* enable cold junction sensor */
95 if (res != 0)
96 {
97 max31856_interface_debug_print("max31856: set cold junction sensor failed.\n");
98 (void)max31856_deinit(&gs_handle);
99
100 return 1;
101 }
102
103 /* set default fault mode */
105 if (res != 0)
106 {
107 max31856_interface_debug_print("max31856: set fault mode failed.\n");
108 (void)max31856_deinit(&gs_handle);
109
110 return 1;
111 }
112
113 /* set default noise rejection filter */
115 if (res != 0)
116 {
117 max31856_interface_debug_print("max31856: set noise rejection filter failed.\n");
118 (void)max31856_deinit(&gs_handle);
119
120 return 1;
121 }
122
123 /* set default sample average */
125 if (res != 0)
126 {
127 max31856_interface_debug_print("max31856: set sample average failed.\n");
128 (void)max31856_deinit(&gs_handle);
129
130 return 1;
131 }
132
133 /* enable cold junction high fault threshold mask */
135 if (res != 0)
136 {
137 max31856_interface_debug_print("max31856: set fault mask failed.\n");
138 (void)max31856_deinit(&gs_handle);
139
140 return 1;
141 }
142
143 /* enable cold junction low fault threshold mask */
145 if (res != 0)
146 {
147 max31856_interface_debug_print("max31856: set fault mask failed.\n");
148 (void)max31856_deinit(&gs_handle);
149
150 return 1;
151 }
152
153 /* enable thermocouple temperature high fault threshold mask */
155 if (res != 0)
156 {
157 max31856_interface_debug_print("max31856: set fault mask failed.\n");
158 (void)max31856_deinit(&gs_handle);
159
160 return 1;
161 }
162
163 /* enable thermocouple temperature low fault threshold mask */
165 if (res != 0)
166 {
167 max31856_interface_debug_print("max31856: set fault mask failed.\n");
168 (void)max31856_deinit(&gs_handle);
169
170 return 1;
171 }
172
173 /* enable over voltage or undervoltage input fault mask */
175 if (res != 0)
176 {
177 max31856_interface_debug_print("max31856: set fault mask failed.\n");
178 (void)max31856_deinit(&gs_handle);
179
180 return 1;
181 }
182
183 /* enable thermocouple open circuit fault mask */
185 if (res != 0)
186 {
187 max31856_interface_debug_print("max31856: set fault mask failed.\n");
188 (void)max31856_deinit(&gs_handle);
189
190 return 1;
191 }
192
193 /* set default cold junction temperature offset */
195 if (res != 0)
196 {
197 max31856_interface_debug_print("max31856: cold junction temperature offset convert to register failed.\n");
198 (void)max31856_deinit(&gs_handle);
199
200 return 1;
201 }
202
203 /* set cold junction temperature offset */
204 res = max31856_set_cold_junction_temperature_offset(&gs_handle, offset);
205 if (res != 0)
206 {
207 max31856_interface_debug_print("max31856: set cold junction temperature offset failed.\n");
208 (void)max31856_deinit(&gs_handle);
209
210 return 1;
211 }
212
213 /* clear fault */
214 res = max31856_clear_fault(&gs_handle);
215 if (res != 0)
216 {
217 max31856_interface_debug_print("max31856: clear fault failed.\n");
218 (void)max31856_deinit(&gs_handle);
219
220 return 1;
221 }
222
223 return 0;
224}
225
234{
235 /* close max31856 */
236 if (max31856_deinit(&gs_handle) != 0)
237 {
238 return 1;
239 }
240
241 return 0;
242}
243
253uint8_t max31856_shot_read(double *temp_deg, uint8_t *fault)
254{
255 uint8_t res;
256 int32_t raw;
257
258 /* single read */
259 res = max31856_single_read(&gs_handle, &raw, temp_deg);
260 if (res != 0)
261 {
262 return 1;
263 }
264
265 /* get fault status */
266 res = max31856_get_fault_status(&gs_handle, fault);
267 if (res != 0)
268 {
269 return 1;
270 }
271
272 return 0;
273}
274
284{
285 int16_t raw;
286
287 /* read cold junction temperature */
288 if (max31856_read_cold_junction_temperature(&gs_handle, &raw, temp_deg) != 0)
289 {
290 return 1;
291 }
292
293 return 0;
294}
driver max31856 shot include file
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_single_read(max31856_handle_t *handle, int32_t *raw, double *deg)
read data from the chip once
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_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_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_shot_init(max31856_thermocouple_type_t type)
shot example init
uint8_t max31856_shot_deinit(void)
shot example deinit
uint8_t max31856_shot_read(double *temp_deg, uint8_t *fault)
shot example read the temperature
#define MAX31856_SHOT_DEFAULT_NOISE_REJECTION_FILTER
#define MAX31856_SHOT_DEFAULT_OPEN_CIRCUIT_DETECTION
max31856 shot example default definition
uint8_t max31856_shot_read_cold_junction_temperature(double *temp_deg)
shot example read the cold junction temperature
#define MAX31856_SHOT_DEFAULT_FAULT_MODE
#define MAX31856_SHOT_DEFAULT_SAMPLE_AVERAGE
#define MAX31856_SHOT_DEFAULT_COLD_JUNCTION_TEMPERATURE_OFFSET
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