资源简介
max31865中文数据手册与spi模拟程序
代码片段和文件信息
#include“stm32f10x_conf.h“
#define SDI_H GPIO_SetBits(GPIODGPIO_Pin_2)
#define SDI_L GPIO_ResetBits(GPIODGPIO_Pin_2)
#define SCLK_H GPIO_SetBits(GPIODGPIO_Pin_3)
#define SCLK_L GPIO_ResetBits(GPIODGPIO_Pin_3)
#define NCS_H GPIO_SetBits(GPIODGPIO_Pin_4)
#define NCS_L GPIO_ResetBits(GPIODGPIO_Pin_4)
#define SDO GPIO_ReadInputDataBit(GPIODGPIO_Pin_0)
#define DRDY GPIO_ReadInputDataBit(GPIODGPIO_Pin_1)//iso module is not connect
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void Delay(vu32 nCount);
uint8_t MAX31865_SB_Read(uint8_t addr);
void MAX31865_SB_Write(uint8_t addruint8_t wdata);
float Get_tempture(void);
uint8_t Fault_Status;
float tempture;
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
NVIC_Configuration();
Delay(0xfff);
MAX31865_SB_Write(0x800xc1);//MAX31865 init (50Hz filter)
//MAX31865_SB_Write(0x800xFF);//Set High Fault Threshold MSB
//MAX31865_SB_Write(0x800xFF);//Set High Fault Threshold LSB
//MAX31865_SB_Write(0x800x00);//Set Low Fault Threshold MSB
//MAX31865_SB_Write(0x800x00);//Set Low Fault Threshold LSB
Delay(0xfff);
while (1)
{
Delay(0x1ffff);
tempture=Get_tempture();
Fault_Status=MAX31865_SB_Read(0x07);//Get Fault_Status
}
}
float Get_tempture(void)
{
float temps;
uint16_t dtemp[2];
uint16_t data_temp;
dtemp[0]=MAX31865_SB_Read(0x01);
dtemp[1]=MAX31865_SB_Read(0x02);
data_temp=(dtemp[0]<<7)+(dtemp[1]>>1);//Get 15Bit DATA;
temps=data_temp;
temps=(temps*402)/32768;//Here is the rtd R value;
temps=(temps-100)/0.385055;//A gruad
return temps;
}
uint8_t MAX31865_SB_Read(uint8_t addr)//SPI Single-Byte Read
{
uint8_t read = 0;
NCS_L;Delay(0x1f);
for(uint8_t i = 0; i < 8; i++)
{
SCLK_H;
if (addr & 0x80){SDI_H;}
else {SDI_L;}
Delay(0x1f);
SCLK_L;
addr <<= 1;
Delay(0x1f);
}
Delay(0x1f);
for (uint8_t i = 0; i < 8; i++)
{
SCLK_H;
read = read<<1;
Delay(0x1f);
if(SDO)
{
read++;
}
SCLK_L;
Delay(0x1f);
}
NCS_H;
return read;
}
void MAX31865_SB_Write(uint8_t addruint8_t wdata)//SPI Single-Byte Write
{
NCS_L;Delay(0x1f);
for(uint8_t i = 0; i < 8; i++)
{
SCLK_H;
if (addr & 0x80){SDI_H;}
else {SDI_L;}
Delay(0x1f);
SCLK_L;
addr <<= 1;
Delay(0x1f);
}
for(uint8_t i = 0; i < 8; i++)
{
SCLK_H;
if (wdata & 0x80){SDI_H;}
else {SDI_L;}
Delay(0x1f);
SCLK_L;
wdata <<= 1;
Delay(0x1f);
}
NCS_H;
}
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
FLASH_SetLatency(FLASH_Latency_2);
RCC_HCLKConf
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4468 2018-07-06 09:53 STM32模拟SPI参考程序\main.c
文件 1254447 2018-08-31 03:53 MAX31865_中文规格书.pdf
目录 0 2018-08-31 03:51 STM32模拟SPI参考程序
----------- --------- ---------- ----- ----
1258915 3
评论
共有 条评论