42#define CHIP_NAME "Maxim Integrated MAX31856"
43#define MANUFACTURER_NAME "Maxim Integrated"
44#define SUPPLY_VOLTAGE_MIN 3.0f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 2.0f
47#define TEMPERATURE_MIN -55.0f
48#define TEMPERATURE_MAX 125.0f
49#define DRIVER_VERSION 1000
54#define MAX31856_REG_CR0 0x00
55#define MAX31856_REG_CR1 0x01
56#define MAX31856_REG_MASK 0x02
57#define MAX31856_REG_CJHF 0x03
58#define MAX31856_REG_CJLF 0x04
59#define MAX31856_REG_LTHFTH 0x05
60#define MAX31856_REG_LTHFTL 0x06
61#define MAX31856_REG_LTLFTH 0x07
62#define MAX31856_REG_LTLFTL 0x08
63#define MAX31856_REG_CJTO 0x09
64#define MAX31856_REG_CJTH 0x0A
65#define MAX31856_REG_CJTL 0x0B
66#define MAX31856_REG_LTCBH 0x0C
67#define MAX31856_REG_LTCBM 0x0D
68#define MAX31856_REG_LTCBL 0x0E
69#define MAX31856_REG_SR 0x0F
82static uint8_t a_max31856_read(
max31856_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
84 if (handle->
spi_read(reg, buf, len) != 0)
103static uint8_t a_max31856_write(
max31856_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
105 if (handle->
spi_write(0x80 | reg, buf, len) != 0)
135 handle->
debug_print(
"max31856: spi_init is null.\n");
141 handle->
debug_print(
"max31856: spi_deinit is null.\n");
147 handle->
debug_print(
"max31856: spi_read is null.\n");
153 handle->
debug_print(
"max31856: spi_write is null.\n");
159 handle->
debug_print(
"max31856: delay_ms is null.\n");
165 handle->
debug_print(
"max31856: receive_callback is null.\n");
172 handle->
debug_print(
"max31856: spi init failed.\n");
210 handle->
debug_print(
"max31856: read cr0 failed.\n");
218 handle->
debug_print(
"max31856: write cr0 failed.\n");
226 handle->
debug_print(
"max31856: spi deinit failed.\n");
273 handle->
debug_print(
"max31856: read cr0 failed.\n");
282 handle->
debug_print(
"max31856: write cr0 failed.\n");
288 for (i = 0; i < timeout; i++)
293 handle->
debug_print(
"max31856: read cr0 failed.\n");
297 if (((prev >> 6) & 0x01) == 0)
313 handle->
debug_print(
"max31856: read fault status failed.\n");
317 if (((prev >> 0) & 0x01) != 0)
319 handle->
debug_print(
"max31856: open circuit fault.\n");
323 if (((prev >> 1) & 0x01) != 0)
325 handle->
debug_print(
"max31856: overvoltage or undervoltage input fault.\n");
329 if (((prev >> 6) & 0x01) != 0)
331 handle->
debug_print(
"max31856: thermocouple out of range.\n");
335 if (((prev >> 7) & 0x01) != 0)
337 handle->
debug_print(
"max31856: cold junction out of range.\n");
344 handle->
debug_print(
"max31856: read linearized tc temperature failed.\n");
348 temp_raw = ((uint32_t)buf[0] << 16 | (uint32_t)buf[1] << 8 |
349 (uint32_t)buf[2] << 0);
350 temp_raw = temp_raw >> 5;
351 if ((temp_raw & 0x00040000U) != 0)
353 temp_raw |= 0xFFF80000U;
355 *raw = (int32_t)temp_raw;
356 *deg = (double)(*raw) * 0.0078125;
397 handle->
debug_print(
"max31856: read fault status failed.\n");
401 if (((prev >> 0) & 0x01) != 0)
403 handle->
debug_print(
"max31856: open circuit fault.\n");
407 if (((prev >> 1) & 0x01) != 0)
409 handle->
debug_print(
"max31856: overvoltage or undervoltage input fault.\n");
413 if (((prev >> 6) & 0x01) != 0)
415 handle->
debug_print(
"max31856: thermocouple out of range.\n");
419 if (((prev >> 7) & 0x01) != 0)
421 handle->
debug_print(
"max31856: cold junction out of range.\n");
428 handle->
debug_print(
"max31856: read linearized tc temperature failed.\n");
432 temp_raw = ((uint32_t)buf[0] << 16 | (uint32_t)buf[1] << 8 |
433 (uint32_t)buf[2] << 0);
434 temp_raw = temp_raw >> 5;
435 if ((temp_raw & 0x00040000U) != 0)
437 temp_raw |= 0xFFF80000U;
439 *raw = (int32_t)temp_raw;
440 *deg = (double)(*raw) * 0.0078125;
472 handle->
debug_print(
"max31856: read cr0 failed.\n");
482 handle->
debug_print(
"max31856: write cr0 failed.\n");
517 handle->
debug_print(
"max31856: read cr0 failed.\n");
526 handle->
debug_print(
"max31856: write cr0 failed.\n");
564 handle->
debug_print(
"max31856: read cold junction temperature failed.\n");
568 temp_raw = ((uint16_t)buf[0] << 8) | (uint16_t)buf[1];
569 temp_raw = temp_raw >> 2;
570 if ((temp_raw & 0x2000U) != 0)
574 *raw = (int16_t)temp_raw;
575 *deg = (double)(*raw) * 0.015625;
608 handle->
debug_print(
"max31856: read cr0 failed.\n");
613 prev |= detection << 4;
617 handle->
debug_print(
"max31856: write cr0 failed.\n");
653 handle->
debug_print(
"max31856: read cr0 failed.\n");
690 handle->
debug_print(
"max31856: read cr0 failed.\n");
695 prev |= !enable << 3;
699 handle->
debug_print(
"max31856: write cr0 failed.\n");
735 handle->
debug_print(
"max31856: read cr0 failed.\n");
772 handle->
debug_print(
"max31856: read cr0 failed.\n");
781 handle->
debug_print(
"max31856: write cr0 failed.\n");
817 handle->
debug_print(
"max31856: read cr0 failed.\n");
853 handle->
debug_print(
"max31856: read cr0 failed.\n");
862 handle->
debug_print(
"max31856: write cr0 failed.\n");
898 handle->
debug_print(
"max31856: read cr0 failed.\n");
907 handle->
debug_print(
"max31856: write cr0 failed.\n");
943 handle->
debug_print(
"max31856: read cr0 failed.\n");
980 handle->
debug_print(
"max31856: read cr1 failed.\n");
985 prev |= average << 4;
989 handle->
debug_print(
"max31856: write cr1 failed.\n");
1025 handle->
debug_print(
"max31856: read cr1 failed.\n");
1062 handle->
debug_print(
"max31856: read cr1 failed.\n");
1066 prev &= ~(0xF << 0);
1071 handle->
debug_print(
"max31856: write cr1 failed.\n");
1107 handle->
debug_print(
"max31856: read cr1 failed.\n");
1145 handle->
debug_print(
"max31856: read mask failed.\n");
1149 prev &= ~(1 << mask);
1150 prev |= enable << mask;
1154 handle->
debug_print(
"max31856: write mask failed.\n");
1191 handle->
debug_print(
"max31856: read mask failed.\n");
1225 prev = (uint8_t)(threshold);
1229 handle->
debug_print(
"max31856: write cold junction high fault threshold failed.\n");
1265 handle->
debug_print(
"max31856: read cold junction high fault threshold failed.\n");
1269 *threshold = (int8_t)(prev);
1299 prev = (uint8_t)(threshold);
1303 handle->
debug_print(
"max31856: write cold junction low fault threshold failed.\n");
1339 handle->
debug_print(
"max31856: read cold junction low fault threshold failed.\n");
1343 *threshold = (int8_t)(prev);
1373 buf[0] = (threshold >> 8) & 0xFF;
1374 buf[1] = (threshold >> 0) & 0xFF;
1378 handle->
debug_print(
"max31856: write temperature high fault threshold failed.\n");
1414 handle->
debug_print(
"max31856: read temperature high fault threshold failed.\n");
1418 *threshold = (int16_t)((uint16_t)buf[0] << 8 | buf[1]);
1448 buf[0] = (threshold >> 8) & 0xFF;
1449 buf[1] = (threshold >> 0) & 0xFF;
1453 handle->
debug_print(
"max31856: write temperature low fault threshold failed.\n");
1489 handle->
debug_print(
"max31856: read temperature low fault threshold failed.\n");
1493 *threshold = (int16_t)((uint16_t)buf[0] << 8 | buf[1]);
1523 prev = (uint8_t)(offset);
1527 handle->
debug_print(
"max31856: write cold junction temperature offset failed.\n");
1563 handle->
debug_print(
"max31856: read cold junction temperature offset failed.\n");
1567 *offset = (int8_t)(prev);
1597 buf[0] = (temperature >> 8) & 0xFF;
1598 buf[1] = (temperature >> 0) & 0xFF;
1602 handle->
debug_print(
"max31856: write cold junction temperature failed.\n");
1638 handle->
debug_print(
"max31856: read cold junction temperature failed.\n");
1642 *temperature = (int16_t)((uint16_t)buf[0] << 8 | buf[1]);
1675 handle->
debug_print(
"max31856: read fault status failed.\n");
1706 *reg = (int8_t)(deg);
1733 *deg = (float)(reg);
1760 *reg = (int16_t)(deg / 0.0625f);
1787 *deg = (float)(reg) * 0.0625f;
1814 *reg = (int8_t)(deg / 0.0625f);
1841 *deg = (float)(reg) * 0.0625f;
1868 *reg = (int16_t)(deg / 0.00390625f);
1895 *deg = (float)(reg) * 0.00390625f;
1927 handle->
debug_print(
"max31856: read fault status failed.\n");
1931 if (((prev >> 7) & 0x01) != 0)
1938 if (((prev >> 6) & 0x01) != 0)
1945 if (((prev >> 5) & 0x01) != 0)
1952 if (((prev >> 4) & 0x01) != 0)
1959 if (((prev >> 3) & 0x01) != 0)
1966 if (((prev >> 2) & 0x01) != 0)
1973 if (((prev >> 1) & 0x01) != 0)
1980 if (((prev >> 0) & 0x01) != 0)
2017 res = a_max31856_write(handle, reg, buf, len);
2020 handle->
debug_print(
"max31856: write data failed.\n");
2054 res = a_max31856_read(handle, reg, buf, len);
2057 handle->
debug_print(
"max31856: read data failed.\n");
#define MAX31856_REG_CJLF
#define MAX31856_REG_CJTH
#define MAX31856_REG_LTHFTH
#define MAX31856_REG_LTCBH
#define MAX31856_REG_CR0
chip register definition
#define SUPPLY_VOLTAGE_MAX
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define MAX31856_REG_LTLFTH
#define MAX31856_REG_MASK
#define MAX31856_REG_CJHF
#define MAX31856_REG_CJTO
#define CHIP_NAME
chip information definition
driver max31856 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_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
max31856_bool_t
max31856 bool enumeration definition
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_get_cold_junction_sensor(max31856_handle_t *handle, max31856_bool_t *enable)
get cold junction sensor status
uint8_t max31856_get_fault_mode(max31856_handle_t *handle, max31856_fault_mode_t *mode)
get fault mode
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_cold_junction_temperature_convert_to_data(max31856_handle_t *handle, int16_t reg, float *deg)
convert the register raw data to the cold junction temperature
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_get_temperature_low_fault_threshold(max31856_handle_t *handle, int16_t *threshold)
get temperature low fault threshold
max31856_open_circuit_detection_t
max31856 open circuit detection enumeration definition
uint8_t max31856_get_temperature_high_fault_threshold(max31856_handle_t *handle, int16_t *threshold)
get temperature high fault threshold
uint8_t max31856_get_thermocouple_type(max31856_handle_t *handle, max31856_thermocouple_type_t *type)
get thermocouple type
max31856_sample_average_t
max31856 sample average enumeration definition
uint8_t max31856_get_cold_junction_high_fault_threshold(max31856_handle_t *handle, int8_t *threshold)
get cold junction high fault threshold
uint8_t max31856_set_temperature_low_fault_threshold(max31856_handle_t *handle, int16_t threshold)
set temperature low fault threshold
uint8_t max31856_get_sample_average(max31856_handle_t *handle, max31856_sample_average_t *average)
get sample average
uint8_t max31856_get_cold_junction_temperature(max31856_handle_t *handle, int16_t *temperature)
get cold junction temperature
uint8_t max31856_get_cold_junction_low_fault_threshold(max31856_handle_t *handle, int8_t *threshold)
get cold junction low fault threshold
max31856_noise_rejection_filter_t
max31856 noise rejection filter enumeration definition
uint8_t max31856_continuous_read(max31856_handle_t *handle, int32_t *raw, double *deg)
read data from the chip continuously
uint8_t max31856_get_fault_mask(max31856_handle_t *handle, max31856_fault_mask_t mask, max31856_bool_t *enable)
get fault mask
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
max31856_fault_mode_t
max31856 fault mode enumeration definition
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_get_open_circuit_detection(max31856_handle_t *handle, max31856_open_circuit_detection_t *detection)
get open circuit detection
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
uint8_t max31856_set_cold_junction_temperature(max31856_handle_t *handle, int16_t temperature)
set cold junction temperature
uint8_t max31856_temperature_fault_threshold_convert_to_data(max31856_handle_t *handle, int16_t reg, float *deg)
convert the register raw data to the temperature fault threshold
struct max31856_handle_s max31856_handle_t
max31856 handle structure definition
uint8_t max31856_get_cold_junction_temperature_offset(max31856_handle_t *handle, int8_t *offset)
get cold junction temperature offset
uint8_t max31856_cold_junction_temperature_convert_to_register(max31856_handle_t *handle, float deg, int16_t *reg)
convert the cold junction temperature to the register raw data
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_cold_junction_fault_threshold_convert_to_data(max31856_handle_t *handle, int8_t reg, float *deg)
convert the register raw data to the cold junction fault threshold
uint8_t max31856_cold_junction_temperature_offset_convert_to_data(max31856_handle_t *handle, int8_t reg, float *deg)
convert the register raw data to the cold junction temperature offset
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
uint8_t max31856_get_noise_rejection_filter(max31856_handle_t *handle, max31856_noise_rejection_filter_t *filter)
get noise rejection filter
max31856_fault_mask_t
max31856 fault mask enumeration definition
@ MAX31856_FAULT_STATUS_TCHIGH
@ MAX31856_FAULT_STATUS_CJHIGH
@ MAX31856_FAULT_STATUS_TCLOW
@ MAX31856_FAULT_STATUS_OVUV
@ MAX31856_FAULT_STATUS_TCRANGE
@ MAX31856_FAULT_STATUS_OPEN
@ MAX31856_FAULT_STATUS_CJLOW
@ MAX31856_FAULT_STATUS_CJRANGE
uint8_t max31856_set_reg(max31856_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t max31856_get_reg(max31856_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* receive_callback)(uint8_t type)
uint8_t(* spi_write)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
uint8_t(* spi_deinit)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v