感谢解答。
另外再请教下:
uint8_t Spi_ReceiveData(en_spi_channel_t enCh,boolean_t bMasterOrSlave)
{
uint8_t temp;
ASSERT(IS_VALID_CH(enCh));
if(Spi0 == enCh)
{
if(1 == bMasterOrSlave)
{
M0P_SPI0->DATA = 0x00;
}
while(0 == M0P_SPI0->STAT_f.RXNE){;}
temp = M0P_SPI0->DATA;
}
else
{
if(1 == bMasterOrSlave)
{
M0P_SPI1->DATA = 0x00;
}
while(0 == M0P_SPI1->STAT_f.RXNE){;}
temp = M0P_SPI1->DATA;
}
return temp;
}
接收的函数中bMasterOrSlave==1 应该是表示是主机的意思,为什么主机接收需要进行M0P_SPI0->DATA = 0x00 操作?
另外,在HC32L136的LITE版本库函数中,发送和接收都很简单。
en_result_t Spi_SendData(M0P_SPI_TypeDef* SPIx, uint8_t u8Data)
{
SPIx->DATA = u8Data;
return Ok;
}
uint8_t Spi_ReceiveData(M0P_SPI_TypeDef* SPIx)
{
return SPIx->DATA;
}
|