我有一块F103C8T6的板子,有例程,可实现正常TCP客户端通信。
发送函数为:
void SPI1_Send_Byte(unsigned char dat)
{
SPI_I2S_SendData(SPI1,dat);
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
}
void SPI_I2S_SendData(SPI_TypeDef* SPIx, uint16_t Data)
{
assert_param(IS_SPI_ALL_PERIPH(SPIx));
SPIx->DR = Data;
}
FlagStatus SPI_I2S_GetFlagStatus(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG)
{
FlagStatus bitstatus = RESET;
assert_param(IS_SPI_ALL_PERIPH(SPIx));
assert_param(IS_SPI_I2S_GET_FLAG(SPI_I2S_FLAG));
if ((SPIx->SR & SPI_I2S_FLAG) != (uint16_t)RESET)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
return bitstatus;
}
接收函数
unsigned char Read_W5500_1Byte(unsigned short reg)
{
unsigned char i;
GPIO_ResetBits(W5500_SCS_PORT, W5500_SCS);
SPI1_Send_Short(reg);
SPI1_Send_Byte(FDM1|RWB_READ|COMMON_R);
i=SPI_I2S_ReceiveData(SPI1);
SPI1_Send_Byte(0x00);
i=SPI_I2S_ReceiveData(SPI1);
GPIO_SetBits(W5500_SCS_PORT, W5500_SCS);
return i;
}
uint16_t SPI_I2S_ReceiveData(SPI_TypeDef* SPIx)
{
assert_param(IS_SPI_ALL_PERIPH(SPIx));
return SPIx->DR;
}
我另一块板子F303ZET6,用STM32CubeMX生成TCP客户端初始化代码。
生成的发送函数原型:
HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout);
接收函数原型:
HAL_StatusTypeDef HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout);
我的发送函数:
void SPI1_Send_Byte(unsigned char dat)
{
unsigned char Data[1];
Data[0]=dat;
HAL_SPI_Transmit(&hspi1, Data, 1, 1000);
}
接收函数
unsigned char Read_W5500_1Byte(unsigned short reg)
{
unsigned char i;
uint8_t pData[1]={0};
HAL_GPIO_WritePin(W5500_SCS_PORT, W5500_SCS,GPIO_PIN_RESET);
SPI1_Send_Short(reg);
SPI1_Send_Byte(FDM1|RWB_READ|COMMON_R);
HAL_SPI_Receive(&hspi1, pData, 1, 1000);
HAL_SPI_Transmit(&hspi1, 0x00, 1, 1000);
HAL_SPI_Receive(&hspi1, pData, 1, 1000);
i=pData[0];
HAL_GPIO_WritePin(W5500_SCS_PORT, W5500_SCS,GPIO_PIN_SET);
return i;
}
程序下载进去,拼不通。
仿真:
卡在这条语句。
请问高手,如何解决呀?谢谢!