搜索
bottom↓
回复: 2

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

[复制链接]

出0入0汤圆

发表于 2012-12-25 16:38:26 | 显示全部楼层 |阅读模式
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周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

发表于 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
希望这些是你想要的答案。

出0入0汤圆

 楼主| 发表于 2012-12-25 22:49:37 | 显示全部楼层
cjh8894 发表于 2012-12-25 16:52
while ( (LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );  //因为SSP0是边发边收的,所以要检测BS ...

非常感谢
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-6-11 02:15

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表