使用
STM32,通过spi的dma 收发,运行多次读写以后w5500发送正常,接收卡死,高人帮忙看看
void PY_W5500_Read(uint8_t ah, uint8_t al, uint8_t ctl, uint8_t* data, uint16_t length)
{
PY_W5500_CS_EN
PY_SPIDMA__Status = 1;
PY_CMD_Seg[0] = ah;
PY_CMD_Seg[1] = al;
PY_CMD_Seg[2] = ctl & 0xfb;//hwy----三个函数主要是控制字区别
//HAL_SPI_Transmit_DMA(&hspi2, PY_CMD_Seg, 3);
HAL_SPI_Transmit(&hspi2, PY_CMD_Seg, 3,4096);
//while(PY_SPIDMA__Status == 1) ;
//DWT_DELAY_uS(1);
PY_SPIDMA__Status = 1;
//HAL_SPI_Receive_DMA(&hspi2, data, length);
HAL_StatusTypeDef st = HAL_SPI_Receive(&hspi2, data, length,4096);//注意超时参数
if(st == HAL_
tiMEOUT)
{
PY_SPIDMA__Status = 2;
}
// uint8_t timeout_temp = 0;
// while(PY_SPIDMA__Status == 1)// ;//卡卡卡
// {
// DWT_DELAY_uS(1);
// timeout_temp++;
// if(timeout_temp > 200)
// break;
// }
PY_W5500_CS_DEN
DWT_DELAY_uS(1);
}
//---------发送缓冲区地址高位,地址低位,控制字,数据,长度
void PY_W5500_Send(uint8_t ah, uint8_t al, uint8_t ctl, uint8_t* data, uint16_t length)
{
PY_W5500_CS_EN
PY_SPIDMA__Status = 1;
PY_CMD_Seg[0] = ah;
PY_CMD_Seg[1] = al;
PY_CMD_Seg[2] = ctl | 0x04;//hwy----三个函数主要是控制字区别
//HAL_SPI_Transmit_DMA(&hspi2, PY_CMD_Seg, 3);
HAL_SPI_Transmit(&hspi2, PY_CMD_Seg, 3,4096);
//while(PY_SPIDMA__Status == 1) ;//发送命令码要等发送完
PY_SPIDMA__Status = 1;
//HAL_SPI_Transmit_DMA(&hspi2, data, length);
HAL_SPI_Transmit(&hspi2, data, length,4096);
//while(PY_SPIDMA__Status == 1) ;//发送内容完全可以不等
PY_W5500_CS_DEN
DWT_DELAY_uS(1);
}