实验如何关闭自动片选来进行双击通讯,发现master tx工作正常,master rx 收到的数据全部为零。slave tx应该没有
问题,从slave写法来看一样,既然rx ok,tx应该也是没有问题。那么应该是M-tx的问题
主机发送函数,接收函数
void SPI_WriteByte(uint32_t TxData)
{
SPI_SET_SS_LOW(SPI0);
while(SPI_GET_TX_FIFO_EMPTY_FLAG(SPI0)==0);
SPI_WRITE_TX(SPI0,TxData);
while(SPI_IS_BUSY(SPI0));
SPI_READ_RX(SPI0);
SPI_SET_SS_HIGH(SPI0);
}
/**
* @brief 从SPI总线读取1字节数据
* @retval 读到的数据
*/
uint32_t SPI_ReadByte(void)
{
uint32_t ret;
SPI_SET_SS_LOW(SPI0);
// while((SPI1->SR&SPI_I2S_FLAG_TXE)==0); //等待发送区空
//while(SPI_GET_TX_FIFO_EMPTY_FLAG(SPI0)==0);
//while((SPI_GET_TX_FIFO_FULL_FLAG(SPI0) == 1));
SPI_WRITE_TX(SPI0,0xff);
//while((SPI1->SR&SPI_I2S_FLAG_RXNE)==0); //等待接收完一个byte《m4没有rx不为空这个标志/函数/宏?
while(SPI_IS_BUSY(SPI0));
ret= SPI_READ_RX(SPI0);
SPI_SET_SS_HIGH(SPI0);
return ret;
}
从机接收
while(u32RxDataCount < 16)
{
/* Check TX FULL flag and TX data count */
if((SPI_GET_TX_FIFO_FULL_FLAG(SPI0) == 0) && (u32TxDataCount < TEST_COUNT))
SPI_WRITE_TX(SPI0, g_au32SourceData[u32TxDataCount++]); /* Write to TX FIFO */
/* Check RX EMPTY flag */
if(SPI_GET_RX_FIFO_EMPTY_FLAG(SPI0) == 0)
g_au32DestinationData[u32RxDataCount++] = SPI_READ_RX(SPI0); /* Read RX FIFO */
}
|