打印
[其他ST产品]

str731串口接收 问大家

[复制链接]
2005|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
dkill|  楼主 | 2008-8-14 16:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
程序
  void UART0_IRQHandler (void)
{
 
#if 1
  
 
  UART_ITConfig(UART0,UART_IT_TimeOutIdle, ENABLE);
  

  if(UART_FlagStatus(UART0,UART_Flag_RxBufFull)==1)
  {   UART0->SR & 0xfffe;
   
       if((Uart0_rev_buff[counter++]=(u8)UART0->RxBUFR)!='%' && i!= 2 )
        {   i=0;
        
           counter = 0;
           UART_ByteSend(UART0,'a' );
         
          UART_ITConfig(UART0,UART_IT_TimeOutIdle, DISABLE);
   
        }

     else{
         i++;
         if(i>2)
            { i=2;
         
            }
        if(Uart0_rev_buff[counter]=='!'&& j!=2)
            { GPIO_WordWrite(GPIO4, ~(GPIO_WordRead(GPIO4)));
              j++;
            }
        if(j==2)
           { i=0;
             j=0;
            UART_ITConfig(UART0,UART_IT_TimeOutIdle, DISABLE);
           // UART_ITConfig(UART0,UART_IT_RxBufFull, DISABLE);

           //返回接受的字符串***********************************8

             for(k=0;k<counter;k++)
                { 
                  while ((UART0->SR & UART_Flag_TxEmpty) != UART_Flag_TxEmpty);
                  UART_ByteSend(UART0, Uart0_rev_buff[k] );
                 
         
                 }
              while ((UART0->SR & UART_Flag_TxEmpty) != UART_Flag_TxEmpty);
            counter=0; 
            
            // UART_FifoReset (UART0 , UART_RxFIFO);
           //  UART_ITConfig(UART0,UART_IT_RxBufFull, DISABLE);
         //UART_ITConfig(UART0,UART_IT_RxBufFull, ENABLE);
          
          }
       }
  }
  else if(UART_FlagStatus(UART0,UART_IT_TimeOutIdle)==1)
      {    UART_SetTimeOutValue(UART0, 0xff);
           time++;
           UART0->SR & 0xff7f;
           if(time==0xff)
            {
           UART_ITConfig(UART0,UART_IT_TimeOutIdle, DISABLE);
           UART_ByteSend(UART0,'b' );
           time=0;
            }
       }
#endif

}
识别特定的帧   当发送%%sdfdssdfafdsfsfs!!时  能顺利接收
  但是返回接受的字符串时  后面总是带个a  就是%%sdfdssdfafdsfsfs!!a
  不知道为什么我发送完后  好像是什么又触动了中断  才返回的a
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

62

主题

201

帖子

0

粉丝