標(biāo)題:
STM32單片機(jī)MAX31865 rs485通信協(xié)議源程序
[打印本頁]
作者:
1225421164
時(shí)間:
2023-7-16 11:16
標(biāo)題:
STM32單片機(jī)MAX31865 rs485通信協(xié)議源程序
stm32-rs485通信協(xié)議源碼
MAX31865接線順序:
clk--PA5
SDO--PA6
SDI--PA7
CS--PA4
RDY--PB6
單片機(jī)源程序如下:
#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()
{
//獲取轉(zhuǎn)換的電阻值
temps=(temps*402.0f)/32768.0f;
//輸出結(jié)果
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;//獲得轉(zhuǎn)換的電阻值
//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();
}
復(fù)制代碼
原理圖:無
仿真:無
Keil代碼下載:
max31865程序.7z
(6.38 MB, 下載次數(shù): 26)
2023-7-16 15:08 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1