標題:
MAX31865 串口讀出數(shù)據(jù)為0 求教
[打印本頁]
作者:
WANhaodong
時間:
2019-4-21 11:33
標題:
MAX31865 串口讀出數(shù)據(jù)為0 求教
問有用51單片機與MAX31865模擬SPI通信的嗎,通過串口助手在電腦上顯示始終為0x00,希望有人能給指導一下,幫我看看是不是程序的問題
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit SDI=P2^0;
sbit SCLK=P2^1;
sbit CS=P2^2;
sbit DRDY=P2^3;
sbit SDO=P2^4;
uchar i=0;
float temps;
void Delay(uint nCount)
{
for(; nCount != 0; nCount--);
}
uchar MAX31865_Read(uchar addr) //SPI Single-Byte Read
{
uchar read = 0;
CS=0;
//SCLK=1;
Delay(0x1f);
for(i = 0; i < 8; i++)
{
SCLK=1;
if (addr & 0x80){SDI=1;}
else {SDI=0;}
Delay(0x1f);
SCLK=0;
addr <<= 1;
Delay(0x1f);
}
Delay(0x1f);
for(i = 0; i < 8; i++)
{
SCLK=1;
read = read<<1;
Delay(0x1f);
if(SDO){read++;}
SCLK=0;
Delay(0x1f);
}
CS=1;
return read;
}
void MAX31865_Write(uchar addr,uchar wdata)//SPI Single-Byte Write
{
CS=0;
Delay(0x1f);
for(i = 0; i< 8; i++)
{
SCLK=1;
if (addr & 0x80){SDI=1;}
else {SDI=0;}
Delay(0x1f);
SCLK=0;
addr <<= 1;
Delay(0x1f);
}
for(i = 0; i < 8; i++)
{
SCLK=1;
if (wdata & 0x80){SDI=1;}
else {SDI=0;}
Delay(0x1f);
SCLK=0;
wdata <<= 1;
Delay(0x1f);
}
CS=1;
}
void MAX31865_Init(void)
{
MAX31865_Write(0x80,0xd1);
Delay(0x1f);
CS=1;
SCLK=1;
}
void UART_send_byte(uchar dat)
{
SBUF=dat;
while(TI==0);
TI=0;
}
uchar Get_tempture(void)
{
uint dtemp[2];
uint data_temp;
dtemp[0]=MAX31865_Read(0x01);
dtemp[1]=MAX31865_Read(0x02);
data_temp=(dtemp[0]<<7)+(dtemp[1]>>1); //Get 15Bit DATA
//temps=(data_temp*402)/32768.0; //Here is the rtd R value;
//temps=(temps-100)/0.385055; //temperature
temps=data_temp/32.0-256;
return temps;
}
void configUART()
{
TMOD&=0X0F;
TMOD|=0x20;
SCON=0X50;
TH1=0Xfd;
TL1=TH1;
ET1=0;
TR1=1;
}
void main()
{
configUART();
MAX31865_Init();
Delay(0xff);
while(1)
{
Delay(0xff);
UART_send_byte(Get_tempture());
}
}
作者:
渚寒十一
時間:
2019-7-4 23:42
你好,請問這個問題解決了嗎?我遇到同樣的問題了
作者:
LONGSHEN1
時間:
2020-5-17 20:05
這里提供51和stm32的例程,可以點擊鏈接看看
MAX31865 RTD鉑電阻溫度檢測器 PT100至PT1000傳感器模塊-那個寶搜索這個
作者:
czhaii
時間:
2024-1-16 08:12
中斷EA呢
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1