panda1985 发表于 2012-12-25 16:38:26

请教一个关于LPC1788的SSP程序的问题,收发函数不理解

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;
    }
}

cjh8894 发表于 2012-12-25 16:52:45

while ( (LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );//因为SSP0是边发边收的,所以要检测BSY,RNE位,不然会冲掉现有的数据FIFO是只有8字节
LPC_SSP0->DR = 0xFF;//主机要接收先要发送数据才能启动时钟SCK0,只要发送数据就可以也可以是0X00
希望这些是你想要的答案。

panda1985 发表于 2012-12-25 22:49:37

cjh8894 发表于 2012-12-25 16:52 static/image/common/back.gif
while ( (LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );//因为SSP0是边发边收的,所以要检测BS ...

非常感谢{:3_48:}
页: [1]
查看完整版本: 请教一个关于LPC1788的SSP程序的问题,收发函数不理解