用STM32IO口模拟SPI驱动MAX31865调试了好几天了就是没有调通,有没有大神帮帮忙啊?代码如下:
//===дÊý¾Ý===//
void Send_Write_Byte(u8 Address,u8 Data)
{
u8 i;
SPI_MAX31865_CS1_LOW();
for(i = 0;i < 8;i++)
{
SCLK_H;
Delay(1);
if((Address & 0x80) == 0x80)
{
MOSI_H;
}
else
{
MOSI_L;
}
SCLK_L;
Address <<= 1;
}
for(i = 0;i < 8;i++)
{
SCLK_H;
if((Data & 0x80) == 0x80)
{
MOSI_H;
}
else
{
MOSI_L;
}
SCLK_L;
Data <<= 1;
}
SPI_MAX31865_CS1_HIGH();
}
//====================================================================
//===¶ÁÊý¾Ý===//
u8 Send_Read_Byte(u8 Address)
{
u8 i,Temp=0;
SPI_MAX31865_CS1_LOW();
for(i = 0;i < 8;i++)
{
SCLK_H;
if((Address & 0x80) == 0x80)
{
MOSI_H;
}
else
{
MOSI_L;
}
SCLK_L;
Address <<= 1;
}
for(i = 0;i < 8;i++)
{
Temp <<= 1;
SCLK_H;
if(MISO)
{
Temp |= 0x01;
}
else
{
Temp &= 0xfe;
}
SCLK_L;
}
SPI_MAX31865_CS1_HIGH();
return Temp;
}
//====================================================================
//===ͨµÀת»»===//
void max31865_readwedu(void)
{
u8 Send_Read_Byte(u8 Address);
u8 Low=0;
u8 High=0;
Fault = Send_Read_Byte(0x00);
High = Send_Read_Byte(0x01);
Low = Send_Read_Byte(0x02);
Temp_Buff = (High << 8) + Low;
Temp_Buff >>= 1;
Fault_H[0] = Send_Read_Byte(0x03);
Fault_H[1] = Send_Read_Byte(0x04);
Fault_L[0] = Send_Read_Byte(0x05);
Fault_L[1] = Send_Read_Byte(0x06);
Error = Send_Read_Byte(0x07);
Temp_Now = (( Temp_Buff / 32) - 256);
}
//max31865初始化
void SPI_max31865_Init(void)
{
//SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable SPI1 and GPIO clocks */
/*!< SPI_FLASH_SPI_CS_GPIO, SPI_FLASH_SPI_MOSI_GPIO,
SPI_FLASH_SPI_MISO_GPIO, SPI_FLASH_SPI_DETECT_GPIO
and SPI_FLASH_SPI_SCK_GPIO Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC,ENABLE);
/*!< SPI_FLASH_SPI Periph clock enable */
//RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
/*!< Configure SPI_FLASH_SPI pins: SCK */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4;//|GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/*!< Configure SPI_FLASH_SPI pins: MISO */
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
//GPIO_Init(GPIOB, &GPIO_InitStructure);
/*!< Configure SPI_FLASH_SPI pins: MOSI */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //MOSI??????
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/*!< Configure SPI_FLASH_SPI_CS_PIN pin: SPI_FLASH Card CS pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
SPI_MAX31865_CS1_HIGH();
SPI_MAX31865_CS2_HIGH();
Send_Write_Byte(0x80,0xC1);
} |