|
void SSPSend( uint32_t portnum, uint8_t *buf, uint32_t Length )
{
uint32_t i;
uint8_t Dummy = Dummy;
for ( i = 0; i < Length; i++ )
{
/* Move on only if NOT busy and TX FIFO not full. */
while ( (LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );
LPC_SSP0->DR = *buf;
buf++;
while ( (LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE ); //这个地方为什么要加上这一句呢?
/* Whenever a byte is written, MISO FIFO counter increments, Clear FIFO
on MISO. Otherwise, when SSP0Receive() is called, previous data byte
is left in the FIFO. */
Dummy = LPC_SSP0->DR;
}
}
void SSPReceive( uint32_t portnum, uint8_t *buf, uint32_t Length )
{
uint32_t i;
for ( i = 0; i < Length; i++ )
{
/* As long as Receive FIFO is not empty, I can always receive. */
/* If it's a loopback test, clock is shared for both TX and RX,
no need to write dummy byte to get clock to get the data */
/* if it's a peer-to-peer communication, SSPDR needs to be written
before a read can take place. */
LPC_SSP0->DR = 0xFF; //这里为什么要发送0xFFT呢?
/* Wait until the Busy bit is cleared */
while ( (LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );
*buf++ = LPC_SSP0->DR;
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|