stm32-rs485通信协议源码
MAX31865接线顺序:
clk--PA5
SDO--PA6
SDI--PA7
CS--PA4
RDY--PB6
单片机源程序如下:- #include "max31865.h"
- void MAX31865_Init()
- {
- MAX31865_SB_Write(0x80,0xC1);//四线配置
- HAL_Delay(10);
- }
- /*输出电阻值
- #include "stm32f10x.h"
- #include <stdio.h>
- uint16_t temps;
- int main()
- {
- //获取转换的电阻值
- temps=(temps*402.0f)/32768.0f;
- //输出结果
- printf("temp: %f C\r\n ", temps);
- while(1) {
- //其他操作
- }
- }
- */
- #define RTD_A 3.9083e-3
- #define RTD_B -5.775e-7
- float Z1, Z2, Z3, Z4, Rt, temp;
- float Get_tempture(void)//PT100
- {
- float temps;
- uint16_t data_r;
- data_r = MAX31865_SB_Read(0x01) << 8;
- data_r |= MAX31865_SB_Read(0x02);
- data_r >>= 1;
- temps=data_r;
- temps=(temps*430.0f)/32768.0f;//获得转换的电阻值
- //return temps;
- Rt=temps;
- Z1 = -RTD_A;
- Z2 = RTD_A * RTD_A - (4 * RTD_B);
- Z3 = (4 * RTD_B) / 100;
- Z4 = 2 * RTD_B;
- temp = Z2 + (Z3 * Rt);
- temp = (sqrt(temp) + Z1) / Z4;
- if (temp >= 0)
- return temp;
- // ugh.
- Rt /= 100;
- Rt *= 100; // normalize to 100 ohm
- float rpoly = Rt;
- temp = -242.02;
- temp += 2.2228 * rpoly;
- rpoly *= Rt; // square
- temp += 2.5859e-3 * rpoly;
- rpoly *= Rt; // ^3
- temp -= 4.8260e-6 * rpoly;
- rpoly *= Rt; // ^4
- temp -= 2.8183e-8 * rpoly;
- rpoly *= Rt; // ^5
- temp += 1.5243e-10 * rpoly;
-
- //temps=(temps-100.0f)/0.385055f;
- return temp;
- }
- uint8_t MAX31865_SB_Read(uint8_t addr)//SPI Single-Byte Read
- {
- uint8_t read;
- MAX31685_CS_LOW();
- HAL_SPI_Transmit(&hspi1, &addr, 1, 60);
- HAL_SPI_Receive(&hspi1, &read, 1, 60);
- MAX31685_CS_HIGH();
- return read;
- }
- void MAX31865_SB_Write(uint8_t addr,uint8_t wdata)//SPI Single-Byte Write
- {
- uint8_t dat[2];
- dat[0] = addr;
- dat[1] = wdata;
- MAX31685_CS_LOW();
- HAL_SPI_Transmit(&hspi1,dat,2,60);
- MAX31685_CS_HIGH();
- }
复制代码 原理图:无
仿真:无
Keil代码下载:
max31865程序.7z
(6.38 MB, 下载次数: 26)
|