打印
[Cortex-M0技术交流]

LPC1114 uart发送问题

[复制链接]
2434|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zero0915|  楼主 | 2013-9-26 14:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
各位大侠,小弟现在在搞一块LPC1114的板子,用的坏境是IAR6.3,在测试uart时,发现用IAR上自带的例程可以收发,例程是用中断将受到的数据在用查询发回电脑。但是我自己加了个发字节的函数都总是发不了,请同事也看过了,也找不到原因。现在有点困扰,想请大家帮忙看看。
附上代码 除了 UARTSendByte 其他都是例程自带的。
中断处理
/*****************************************************************************
** Function name:                UART0_IRQHandler
**
** Descriptions:                UART interrupt handler
**
** parameters:                        None
** Returned value:                None
**
*****************************************************************************/
#pragma diag_suppress=Pa082
void UART0_IRQHandler(void)
{
  uint8_t IIRValue, LSRValue;
  uint8_t Dummy = Dummy;

  IIRValue = LPC_UART->IIR;    // interrupt ID Register
   
  IIRValue >>= 1;                        /* skip pending bit in IIR */
  IIRValue &= 0x07;                        /* check bit 1~3, interrupt identification */
  if (IIRValue == IIR_RLS)                /* Receive Line Status */
  {
    LSRValue = LPC_UART->LSR;           /* Receive Line Status */
    if (LSRValue & (LSR_OE | LSR_PE | LSR_FE | LSR_RXFE | LSR_BI))
    {
      /* There are errors or break interrupt */
      /* Read LSR will clear the interrupt */
      UARTStatus = LSRValue;
      Dummy = LPC_UART->RBR;        /* Dummy read on RX to clear
                                                                interrupt, then bail out */
      return;
    }
    if (LSRValue & LSR_RDR)        /* Receive Data Ready */                       
    {
      /* If no error on RLS, normal ready, save into the data buffer. */
      /* Note: read RBR will clear the interrupt */
      UARTBuffer[UARTCount++] = LPC_UART->RBR;
      if (UARTCount == BUFSIZE)
      {
        UARTCount = 0;                /* buffer overflow */
      }       
    }
  }
  else if (IIRValue == IIR_RDA)        /* Receive Data Available */
  {
    /* Receive Data Available */
    UARTBuffer[UARTCount++] = LPC_UART->RBR;
    if (UARTCount == BUFSIZE)
    {
      UARTCount = 0;                /* buffer overflow */
    }
  }
  else if (IIRValue == IIR_CTI)        /* Character timeout indicator */
  {
    /* Character Time-out indicator */
    UARTStatus |= 0x100;                /* Bit 9 as the CTI error */
  }
  else if (IIRValue == IIR_THRE)        /* THRE, transmit holding register empty */
  {
    /* THRE interrupt */
    LSRValue = LPC_UART->LSR;                /* Check status in the LSR to see if
                                                                valid data in U0THR or not */
    if (LSRValue & LSR_THRE)
    {
      UARTTxEmpty = 1;
    }
    else
    {
      UARTTxEmpty = 0;
    }
  }

  return;
}
#pragma diag_default=Pa082
发送字符串
*****************************************************************************
** Function name:                UARTSend
**
** Descriptions:                Send a block of data to the UART 0 port based
**                                on the data length
**
** parameters:                buffer pointer, and data length
** Returned value:        None
**
*****************************************************************************/
void UARTSend(uint8_t *BufferPtr, uint32_t Length)
{
  
  while ( Length != 0 )
  {
          /* THRE status, contain valid data */
#if !TX_INTERRUPT
          LPC_UART->THR = *BufferPtr;
          while ( !(LPC_UART->LSR & LSR_THRE) ); //polling
          
#else
          /* Below flag is set inside the interrupt handler when THRE occurs. */
      while ( !(UARTTxEmpty & 0x01) );
          LPC_UART->THR = *BufferPtr;
      UARTTxEmpty = 0;        /* not empty in the THR until it shifts out */
#endif
      BufferPtr++;
      Length--;
  }
  return;
}
发字节
/*****************************************************************************
** Function name:                UARTSendByte
**
** Descriptions:                Send a block of data to the UART 0 port based
**                                on the data length
**
** parameters:                buffer pointer, and data length
** Returned value:        None
**
*****************************************************************************/
void UARTSendByte(uint8_t dat)
{
  
          LPC_UART->THR = dat;
          while ( !(LPC_UART->LSR & LSR_THRE) ); //polling         
         
}
main
int main (void) {

  SystemInit();

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

#if MODEM_TEST
  ModemInit();
#endif
  
UARTSendByte(0xaa);


  while (1)
  {               
   /* Loop forever */
   
        if ( UARTCount != 0 )
        {
          LPC_UART->IER = IER_THRE | IER_RLS; /* Disable RBR */
         
           UARTSendByte(0xaa);
          UARTSend( (uint8_t *)UARTBuffer, UARTCount );
         
          UARTCount = 0;
          LPC_UART->IER = IER_THRE | IER_RLS | IER_RBR;        /* Re-enable RBR */
        }
  }
}

相关帖子

沙发
zero0915|  楼主 | 2013-9-29 22:01 | 只看该作者
没人给点意见吗

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

9

主题

91

帖子

1

粉丝