# MAX31856 **Repository Path**: libdriver/max31856 ## Basic Information - **Project Name**: MAX31856 - **Description**: 适用于通用MCU和Linux系统的MAX31856全功能驱动 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-25 - **Last Updated**: 2026-07-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: SPI, 热电偶 ## README [English](/README.md) | [ 简体中文](/README_zh-Hans.md) | [繁體中文](/README_zh-Hant.md) | [日本語](/README_ja.md) | [Deutsch](/README_de.md) | [한국어](/README_ko.md)
## LibDriver MAX31856 [![MISRA](https://img.shields.io/badge/misra-compliant-brightgreen.svg)](/misra/README.md) [![API](https://img.shields.io/badge/api-reference-blue.svg)](https://www.libdriver.com/docs/max31856/index.html) [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](/LICENSE) MAX31856执行冷端补偿,并将来自任何类型热电偶的信号数字化。输出数据以摄氏度为单位进行格式化。该转换器将温度解析为0.0078125°C,允许读数高达+1800°C,低至-210°C(取决于热电偶类型),并显示热电偶电压测量精度为±0.15%。热电偶输入端可防止高达±45V的过电压条件。查找表(LUT)存储了几种类型的热电偶(K、J、N、R、S、T、E和B)的线性校正数据。包括50Hz和60Hz的线路频率滤波,以及热电偶故障检测。SPI兼容接口允许选择热电偶类型以及设置转换和故障检测过程。 LibDriver MAX31856是LibDriver推出的MAX31856的全功能驱动,该驱动提供热电偶温度连续模式读取、热电偶温度单次模式读取等功能并且它符合MISRA标准。 ### 目录 - [说明](#说明) - [安装](#安装) - [使用](#使用) - [example basic](#example-basic) - [example shot](#example-shot) - [example interrupt](#example-interrupt) - [文档](#文档) - [贡献](#贡献) - [版权](#版权) - [联系我们](#联系我们) ### 说明 /src目录包含了LibDriver MAX31856的源文件。 /interface目录包含了LibDriver MAX31856与平台无关的SPI总线模板。 /test目录包含了LibDriver MAX31856驱动测试程序,该程序可以简单的测试芯片必要功能。 /example目录包含了LibDriver MAX31856编程范例。 /doc目录包含了LibDriver MAX31856离线文档。 /datasheet目录包含了MAX31856数据手册。 /project目录包含了常用Linux与单片机开发板的工程样例。所有工程均采用shell脚本作为调试方法,详细内容可参考每个工程里面的README.md。 /misra目录包含了LibDriver MISRA代码扫描结果。 ### 安装 参考/interface目录下与平台无关的SPI总线模板,完成指定平台的SPI总线驱动。 将/src目录,您使用平台的接口驱动和您开发的驱动加入工程,如果您想要使用默认的范例驱动,可以将/example目录加入您的工程。 ### 使用 您可以参考/example目录下的编程范例完成适合您的驱动,如果您想要使用默认的编程范例,以下是它们的使用方法。 #### example basic ```C #include "driver_max31856_basic.h" uint8_t res; uint32_t i; max31856_thermocouple_type_t thermocouple_type = MAX31856_THERMOCOUPLE_TYPE_K; /* init */ res = max31856_basic_init(thermocouple_type); if (res != 0) { return 1; } ... /* loop */ for (i = 0; i < 3; i++) { double temp_deg; uint8_t fault; /* read data */ res = max31856_basic_read(&temp_deg, &fault); if (res != 0) { (void)max31856_basic_deinit(); if (fault != 0) { if ((fault & MAX31856_FAULT_STATUS_CJRANGE) != 0) { max31856_interface_debug_print("max31856: cold junction out of range.\n"); } else if ((fault & MAX31856_FAULT_STATUS_TCRANGE) != 0) { max31856_interface_debug_print("max31856: thermocouple out of range.\n"); } else if ((fault & MAX31856_FAULT_STATUS_CJHIGH) != 0) { max31856_interface_debug_print("max31856: cold junction high fault.\n"); } else if ((fault & MAX31856_FAULT_STATUS_CJLOW) != 0) { max31856_interface_debug_print("max31856: cold junction low fault.\n"); } else if ((fault & MAX31856_FAULT_STATUS_TCHIGH) != 0) { max31856_interface_debug_print("max31856: thermocouple temperature high fault.\n"); } else if ((fault & MAX31856_FAULT_STATUS_TCLOW) != 0) { max31856_interface_debug_print("max31856: thermocouple temperature low fault.\n"); } else if ((fault & MAX31856_FAULT_STATUS_OVUV) != 0) { max31856_interface_debug_print("max31856: overvoltage or undervoltage input fault.\n"); } else if ((fault & MAX31856_FAULT_STATUS_OPEN) != 0) { max31856_interface_debug_print("max31856: thermocouple open circuit fault.\n"); } else { max31856_interface_debug_print("max31856: fault is unknown.\n"); } } return 1; } /* output */ max31856_interface_debug_print("%d/%d %0.3fC.\n", i + 1, 3, temp_deg); /* delay 1000ms */ max31856_interface_delay_ms(1000); ... } ... /* deinit */ (void)max31856_basic_deinit(); return 0; ``` #### example shot ```C #include "driver_max31856_shot.h" uint8_t res; uint32_t i; max31856_thermocouple_type_t thermocouple_type = MAX31856_THERMOCOUPLE_TYPE_K; /* init */ res = max31856_shot_init(thermocouple_type); if (res != 0) { return 1; } ... /* loop */ for (i = 0; i < 3; i++) { double temp_deg; uint8_t fault; /* read data */ res = max31856_shot_read(&temp_deg, &fault); if (res != 0) { (void)max31856_shot_deinit(); if (fault != 0) { if ((fault & MAX31856_FAULT_STATUS_CJRANGE) != 0) { max31856_interface_debug_print("max31856: cold junction out of range.\n"); } else if ((fault & MAX31856_FAULT_STATUS_TCRANGE) != 0) { max31856_interface_debug_print("max31856: thermocouple out of range.\n"); } else if ((fault & MAX31856_FAULT_STATUS_CJHIGH) != 0) { max31856_interface_debug_print("max31856: cold junction high fault.\n"); } else if ((fault & MAX31856_FAULT_STATUS_CJLOW) != 0) { max31856_interface_debug_print("max31856: cold junction low fault.\n"); } else if ((fault & MAX31856_FAULT_STATUS_TCHIGH) != 0) { max31856_interface_debug_print("max31856: thermocouple temperature high fault.\n"); } else if ((fault & MAX31856_FAULT_STATUS_TCLOW) != 0) { max31856_interface_debug_print("max31856: thermocouple temperature low fault.\n"); } else if ((fault & MAX31856_FAULT_STATUS_OVUV) != 0) { max31856_interface_debug_print("max31856: overvoltage or undervoltage input fault.\n"); } else if ((fault & MAX31856_FAULT_STATUS_OPEN) != 0) { max31856_interface_debug_print("max31856: thermocouple open circuit fault.\n"); } else { max31856_interface_debug_print("max31856: fault is unknown.\n"); } } return 1; } /* output */ max31856_interface_debug_print("%d/%d %0.3fC.\n", i + 1, 3, temp_deg); /* delay 1000ms */ max31856_interface_delay_ms(1000); ... } ... /* deinit */ (void)max31856_shot_deinit(); return 0; ``` #### example interrupt ```C #include "driver_max31856_interrupt.h" uint8_t res; uint32_t i; float cold_junction_low = 20.0f; float cold_junction_high = 30.0f; float temperature_low = 25.0f; float temperature_high = 30.0f; uint32_t timeout = 5000; max31856_thermocouple_type_t thermocouple_type = MAX31856_THERMOCOUPLE_TYPE_K; static uint8_t gs_flag = 0; uint8_t (*g_gpio_irq)(void) = NULL; /** * @brief interface receive callback * @param[in] type callback type * @note none */ static void a_callback(uint8_t type) { switch (type) { case MAX31856_FAULT_STATUS_CJRANGE : { max31856_interface_debug_print("max31856: irq cold junction out of range.\n"); gs_flag = 1; break; } case MAX31856_FAULT_STATUS_TCRANGE : { max31856_interface_debug_print("max31856: irq thermocouple out of range.\n"); gs_flag = 1; break; } case MAX31856_FAULT_STATUS_CJHIGH : { uint8_t res; double deg; max31856_interface_debug_print("max31856: irq cold junction high fault.\n"); gs_flag = 1; /* read cold junction temperature */ res = max31856_interrupt_read_cold_junction_temperature(°); if (res == 0) { /* output */ max31856_interface_debug_print("max31856: cold junction temperature is %0.03fC.\n", deg); } break; } case MAX31856_FAULT_STATUS_CJLOW : { uint8_t res; double deg; max31856_interface_debug_print("max31856: irq cold junction low fault.\n"); gs_flag = 1; /* read cold junction temperature */ res = max31856_interrupt_read_cold_junction_temperature(°); if (res == 0) { /* output */ max31856_interface_debug_print("max31856: cold junction temperature is %0.03fC.\n", deg); } break; } case MAX31856_FAULT_STATUS_TCHIGH : { uint8_t res; uint8_t fault; double deg; max31856_interface_debug_print("max31856: irq thermocouple temperature high fault.\n"); gs_flag = 1; /* continuous read */ res = max31856_interrupt_read(°, &fault); if (res == 0) { /* output */ max31856_interface_debug_print("max31856: temperature is %0.03fC.\n", deg); } break; } case MAX31856_FAULT_STATUS_TCLOW : { uint8_t res; uint8_t fault; double deg; max31856_interface_debug_print("max31856: irq thermocouple temperature low fault.\n"); gs_flag = 1; /* continuous read */ res = max31856_interrupt_read(°, &fault); if (res == 0) { /* output */ max31856_interface_debug_print("max31856: temperature is %0.03fC.\n", deg); } break; } case MAX31856_FAULT_STATUS_OVUV : { max31856_interface_debug_print("max31856: irq overvoltage or undervoltage input fault.\n"); gs_flag = 1; break; } case MAX31856_FAULT_STATUS_OPEN : { max31856_interface_debug_print("max31856: irq thermocouple open circuit fault.\n"); gs_flag = 1; break; } default : { max31856_interface_debug_print("max31856: unknown code.\n"); gs_flag = 1; break; } } } /* output */ max31856_interface_debug_print("max31856: cold junction low fault threshold %0.3fC.\n", cold_junction_low); max31856_interface_debug_print("max31856: cold junction high fault threshold %0.3fC.\n", cold_junction_high); max31856_interface_debug_print("max31856: temperature low fault threshold %0.3fC.\n", temperature_low); max31856_interface_debug_print("max31856: temperature high fault threshold %0.3fC.\n", temperature_high); ... /* interrupt init */ g_gpio_irq = max31856_interrupt_irq_handler; (void)gpio_interrupt_init(); res = max31856_interrupt_init(thermocouple_type, cold_junction_low, cold_junction_high, temperature_low, temperature_high, a_callback); if (res != 0) { (void)gpio_interrupt_deinit(); g_gpio_irq = NULL; return 1; } ... /* init 0 */ gs_flag = 0; /* wait for timeout */ for (i = 0; i < timeout; i++) { /* delay 1ms */ max31856_interface_delay_ms(1); if (gs_flag != 0) { max31856_interface_debug_print("max31856: find interrupt.\n"); break; } ... } ... /* deinit */ max31856_interrupt_deinit(); (void)gpio_interrupt_deinit(); g_gpio_irq = NULL; return 0; ``` ### 文档 在线文档: [https://www.libdriver.com/docs/max31856/index.html](https://www.libdriver.com/docs/max31856/index.html)。 离线文档: /doc/html/index.html。 ### 贡献 请参考CONTRIBUTING.md。 ### 版权 版权 (c) 2015 - 现在 LibDriver 版权所有 MIT 许可证(MIT) 特此免费授予任何获得本软件副本和相关文档文件(下称“软件”)的人不受限制地处置该软件的权利,包括不受限制地使用、复制、修改、合并、发布、分发、转授许可和/或出售该软件副本,以及再授权被配发了本软件的人如上的权利,须在下列条件下: 上述版权声明和本许可声明应包含在该软件的所有副本或实质成分中。 本软件是“如此”提供的,没有任何形式的明示或暗示的保证,包括但不限于对适销性、特定用途的适用性和不侵权的保证。在任何情况下,作者或版权持有人都不对任何索赔、损害或其他责任负责,无论这些追责来自合同、侵权或其它行为中,还是产生于、源于或有关于本软件以及本软件的使用或其它处置。 ### 联系我们 请联系lishifenging@outlook.com。