[Cortex-M0技术交流] LPC1114 uart发送问题

[复制链接]
 楼主| zero0915 发表于 2013-9-26 14:44 | 显示全部楼层 |阅读模式
各位大侠,小弟现在在搞一块LPC1114的板子,用的坏境是IAR6.3,在测试uart时,发现用IAR上自带的例程可以收发,例程是用中断将受到的数据在用查询发回电脑。但是我自己加了个发字节的函数都总是发不了,请同事也看过了,也找不到原因。现在有点困扰,想请大家帮忙看看。
附上代码 除了 UARTSendByte 其他都是例程自带的。
中断处理
  1. /*****************************************************************************
  2. ** Function name:                UART0_IRQHandler
  3. **
  4. ** Descriptions:                UART interrupt handler
  5. **
  6. ** parameters:                        None
  7. ** Returned value:                None
  8. **
  9. *****************************************************************************/
  10. #pragma diag_suppress=Pa082
  11. void UART0_IRQHandler(void)
  12. {
  13.   uint8_t IIRValue, LSRValue;
  14.   uint8_t Dummy = Dummy;

  15.   IIRValue = LPC_UART->IIR;    // interrupt ID Register
  16.    
  17.   IIRValue >>= 1;                        /* skip pending bit in IIR */
  18.   IIRValue &= 0x07;                        /* check bit 1~3, interrupt identification */
  19.   if (IIRValue == IIR_RLS)                /* Receive Line Status */
  20.   {
  21.     LSRValue = LPC_UART->LSR;           /* Receive Line Status */
  22.     if (LSRValue & (LSR_OE | LSR_PE | LSR_FE | LSR_RXFE | LSR_BI))
  23.     {
  24.       /* There are errors or break interrupt */
  25.       /* Read LSR will clear the interrupt */
  26.       UARTStatus = LSRValue;
  27.       Dummy = LPC_UART->RBR;        /* Dummy read on RX to clear
  28.                                                                 interrupt, then bail out */
  29.       return;
  30.     }
  31.     if (LSRValue & LSR_RDR)        /* Receive Data Ready */                       
  32.     {
  33.       /* If no error on RLS, normal ready, save into the data buffer. */
  34.       /* Note: read RBR will clear the interrupt */
  35.       UARTBuffer[UARTCount++] = LPC_UART->RBR;
  36.       if (UARTCount == BUFSIZE)
  37.       {
  38.         UARTCount = 0;                /* buffer overflow */
  39.       }       
  40.     }
  41.   }
  42.   else if (IIRValue == IIR_RDA)        /* Receive Data Available */
  43.   {
  44.     /* Receive Data Available */
  45.     UARTBuffer[UARTCount++] = LPC_UART->RBR;
  46.     if (UARTCount == BUFSIZE)
  47.     {
  48.       UARTCount = 0;                /* buffer overflow */
  49.     }
  50.   }
  51.   else if (IIRValue == IIR_CTI)        /* Character timeout indicator */
  52.   {
  53.     /* Character Time-out indicator */
  54.     UARTStatus |= 0x100;                /* Bit 9 as the CTI error */
  55.   }
  56.   else if (IIRValue == IIR_THRE)        /* THRE, transmit holding register empty */
  57.   {
  58.     /* THRE interrupt */
  59.     LSRValue = LPC_UART->LSR;                /* Check status in the LSR to see if
  60.                                                                 valid data in U0THR or not */
  61.     if (LSRValue & LSR_THRE)
  62.     {
  63.       UARTTxEmpty = 1;
  64.     }
  65.     else
  66.     {
  67.       UARTTxEmpty = 0;
  68.     }
  69.   }

  70.   return;
  71. }
  72. #pragma diag_default=Pa082
发送字符串
  1. *****************************************************************************
  2. ** Function name:                UARTSend
  3. **
  4. ** Descriptions:                Send a block of data to the UART 0 port based
  5. **                                on the data length
  6. **
  7. ** parameters:                buffer pointer, and data length
  8. ** Returned value:        None
  9. **
  10. *****************************************************************************/
  11. void UARTSend(uint8_t *BufferPtr, uint32_t Length)
  12. {
  13.   
  14.   while ( Length != 0 )
  15.   {
  16.           /* THRE status, contain valid data */
  17. #if !TX_INTERRUPT
  18.           LPC_UART->THR = *BufferPtr;
  19.           while ( !(LPC_UART->LSR & LSR_THRE) ); //polling
  20.           
  21. #else
  22.           /* Below flag is set inside the interrupt handler when THRE occurs. */
  23.       while ( !(UARTTxEmpty & 0x01) );
  24.           LPC_UART->THR = *BufferPtr;
  25.       UARTTxEmpty = 0;        /* not empty in the THR until it shifts out */
  26. #endif
  27.       BufferPtr++;
  28.       Length--;
  29.   }
  30.   return;
  31. }
发字节
  1. /*****************************************************************************
  2. ** Function name:                UARTSendByte
  3. **
  4. ** Descriptions:                Send a block of data to the UART 0 port based
  5. **                                on the data length
  6. **
  7. ** parameters:                buffer pointer, and data length
  8. ** Returned value:        None
  9. **
  10. *****************************************************************************/
  11. void UARTSendByte(uint8_t dat)
  12. {
  13.   
  14.           LPC_UART->THR = dat;
  15.           while ( !(LPC_UART->LSR & LSR_THRE) ); //polling         
  16.          
  17. }
main
  1. int main (void) {

  2.   SystemInit();

  3.   /* NVIC is installed inside UARTInit file. */
  4.   UARTInit(9600);

  5. #if MODEM_TEST
  6.   ModemInit();
  7. #endif
  8.   
  9. UARTSendByte(0xaa);


  10.   while (1)
  11.   {               
  12.    /* Loop forever */
  13.    
  14.         if ( UARTCount != 0 )
  15.         {
  16.           LPC_UART->IER = IER_THRE | IER_RLS; /* Disable RBR */
  17.          
  18.            UARTSendByte(0xaa);
  19.           UARTSend( (uint8_t *)UARTBuffer, UARTCount );
  20.          
  21.           UARTCount = 0;
  22.           LPC_UART->IER = IER_THRE | IER_RLS | IER_RBR;        /* Re-enable RBR */
  23.         }
  24.   }
  25. }
 楼主| zero0915 发表于 2013-9-29 22:01 | 显示全部楼层
没人给点意见吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

9

主题

91

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部