搜索
bottom↓
回复: 0

求助----lpc1768串口2接收到\r\n后不能进中断

[复制链接]

出0入0汤圆

发表于 2013-5-24 14:55:38 | 显示全部楼层 |阅读模式
本帖最后由 cyj_0220 于 2013-5-24 15:00 编辑

初始化代码
  1. LPC_PINCON->PINSEL0 |= (1<<20);                        //pin P0.10 used as TXD2
  2.                         LPC_PINCON->PINSEL0 |= (1<<22);                        //pin P0.11 used as RXD2                                                                                                                 
  3.                         LPC_SC->PCONP |=(1<<24);                                //uart2 power on
  4.                         LPC_UART2->LCR = 0X83;                                        //enable set baud
  5.                         usfdiv= (FPCLK>>4)/usbaud;                                //set baud
  6.                         LPC_UART2->DLM = (usfdiv >> 8);
  7.                         LPC_UART2->DLL = (usfdiv & 255);
  8.                         LPC_UART2->LCR=0X03;                                        //lock baud
  9.                         LPC_UART2->FCR =0X06;
  10.                         LPC_UART2->IER = 0X01;                                        //enable receive interrupt
  11.             NVIC_EnableIRQ(UART2_IRQn);                                //enable irq in nvic
复制代码
中断代码
  1. void UART2_IRQHandler(void)
  2. {
  3.         UINT8 ucIIRVal = 0;
  4.     UINT8 ucLSRVal = 0;
  5.         UINT8 ucdummy  = 0;
  6.         UINT8 ucrecv   = 0;

  7.     ucdummy  = ucdummy;           //avoid wrong
  8.         ucIIRVal = LPC_UART2->IIR;    //read IIR register
  9.         ucIIRVal >>= 1;               // skip pending bit in IIR
  10.         ucIIRVal &= 0x07;             //check bit 1~3 ,interrupt identification
  11.         switch (ucIIRVal)
  12.         {
  13.                 //
  14.                 //receive line status
  15.                 //
  16.                 case IIR_RLS :                                                                                                                                                                       
  17.                 {
  18.                         ucLSRVal = LPC_UART2->LSR;
  19.                         if(ucLSRVal & (LSR_OE|LSR_PE|LSR_FE|LSR_RXFE|LSR_BI))
  20.                         {
  21.                                 //
  22.                                 //There are errors or break interrupt
  23.                                 // Read LSR will clear the interrupt
  24.                                 //
  25.                                 ulUART2Status = ucLSRVal;
  26.                                 ucdummy = LPC_UART2->RBR;      //Dummy read on RX to clear interrupt, then bail out
  27.                                 return;
  28.                         }
  29.                         if ( ucLSRVal & LSR_RDR )          //Receive Data Ready?                       
  30.                         {
  31.                                 //
  32.                                 //If no error on RLS, normal ready, save into the data buffer.
  33.                                 // Note: read RBR will clear the interrupt
  34.                                 //
  35.                                 ucrecv = LPC_UART2->RBR;
  36.                         }
  37.                 }break;
  38.                 //
  39.                 //Receive Data Available
  40.                 //
  41.                 case IIR_RDA :                                                                                                                                                                       
  42.                 {
  43.                                 ucrecv = LPC_UART2->RBR;
  44.                 }break;
  45.                 //
  46.                 //Character timeout indicator
  47.                 //
  48.                 case IIR_CTI :                                                                                                                                                                         
  49.                 {
  50.                         ulUART2Status |= 0x100;                   //Bit 9 as the CTI error
  51.                 }break;
  52.                 //
  53.                 //THRE interrupt,transmit holding register empty
  54.                 //
  55.                 case IIR_THRE :                                                                                                                                       
  56.                 {
  57.                         ucLSRVal = LPC_UART2->LSR;         //Check status in the LSR to see if valid data in U0THR or not
  58.                         if ( ucLSRVal & LSR_THRE )
  59.                         {
  60.                                 g_UART2TxEmptyFlag = TRUE;
  61.                         }
  62.                         else
  63.                         {
  64.                                 g_UART2TxEmptyFlag = FALSE;
  65.                         }
  66.                 }break;
  67.                 default : break;
  68.         }
  69.     EnQueue((Queue_Type *)&SIMRxQueue,ucrecv);
  70.     UART_SendByte(2,ucrecv);
  71.    
  72. }
复制代码
1.1234567890
abcd                      (a前面有一个回车符)
2.1234567890abcd  (a前面无回车符)

第一种格式在收到回车符后,串口接收不到abcd
第二种格式可以正常接收

也就是说如果数据中有回车符,串口2收到回车符后面的数据也不会进中断

阿莫论坛20周年了!感谢大家的支持与爱护!!

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

本版积分规则

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

GMT+8, 2024-5-12 06:23

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

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