打印
[ZLG-ARM]

在线救助 无法实现UART0月UART1的通信

[复制链接]
1367|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
chris1013|  楼主 | 2007-3-7 00:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
使用LPC2142与XBee的Zigebee模块,打算先由UART0读入数据,传入UART1,再从UART1传出数据到Zigbee模块,但发现UART0与UART1之间无法通信,初步估计是UART1的初始化失败,请高人指点,小弟在线等待~~QQ 157493515
/******************************************************
 * Include files
 ******************************************************/
#include <general.h>
#include <lpc2xxx.h>
#include <config.h>
#include <printf_P.h>
#include <ea_init.h>


/******************************************************
 * Defines
 ******************************************************/
#define UART_DLL_VALUE (tU16)((60000000 / (9600 * 16.0)) + 0.5)
#define UART_DLL_VAL (tU16)((60000000 / (38400 * 16.0)) + 0.5)


/*****************************************************************************
 *
 * Description:
 *    Initializes the UART channel #0 (38400 kbps, 8N1)
 *
 ****************************************************************************/
void
initUart1(void)
{
//enable uart #1 pins (P0.8 = TxD0, P0.9 = RxD0)
 PINSEL0 = (PINSEL0 & 0xfff0ffff) | 0x00050000;

  //initialize bitrate (by first enable DL registers, DLAB-bit = 1)
  U1LCR = 0x80;
  U1DLL = (tU8)(UART_DLL_VALUE & 0x00ff);
  U1DLM = (tU8)(UART_DLL_VALUE>>8);
  U1LCR = 0x00;

  //initialize LCR: 8N1
  U1LCR = 0x03;

  //disable FIFO
  U1FCR = 0x00;

  //clear interrupt bits, just in case (not used)
  U1IER = 0x00;
  //U1MCR = 0x00;
}
void
initUart0(void)
{
  //enable uart #0 pins (P0.0 = TxD0, P0.1 = RxD0)
  PINSEL0 = (PINSEL0 & 0xfffffff0) | 0x00000005;

  //initialize bitrate (by first enable DL registers, DLAB-bit = 1)
  U0LCR = 0x80;
  U0DLL = (tU8)(UART_DLL_VAL & 0x00ff);
  U0DLM = (tU8)(UART_DLL_VAL>>8);
  U0LCR = 0x00;

  //initialize LCR: 8N1
  U0LCR = 0x03;

  //disable FIFO
  U0FCR = 0x00;

  //clear interrupt bits, just in case (not used)
  U0IER = 0x00;
}

/*****************************************************************************
 *
 * Description:
 *    Blocking output routine, i.e., the routine waits until the uart 
 *    buffer is free and then sends the character. 
 *
 * Params:
 *    [in] charToSend - The character to send/print
 *
 ****************************************************************************/
tBool receiveCharPoll()
{  
   if(!(U0LSR & 0x01))
   {
      return 0;
    }
    else 
        {      
      return 1;
      }
}
void
sendToZigbee(tBool t)
{
  //Wait until THR register is empty
  while(!(U0LSR & 0x20))
    ;
      
    if(t)
  //output character value to THR
 { 
     
           U1THR = U0RBR;
     }  
 }
void 
returnState()
{
    tU8 anrry[10];
   tU16 i,j;
   i=0;
    while(U1LSR & 0x01)
    {
        anrry=U1RBR;
        i++;
    }
    for(j=0;j<=i;j++)
    {
     U0THR = anrry;
    }
 }

相关帖子

沙发
hotpower| | 2007-3-7 00:50 | 只看该作者

倒塌了~~~真心在线肯定不睡觉~~~

使用特权

评论回复
板凳
chris1013|  楼主 | 2007-3-7 01:47 | 只看该作者

在吃晚饭呢...继续在线求助~~

使用特权

评论回复
地板
zlgARM| | 2007-3-7 08:58 | 只看该作者

RE

UART0和UART1在基本的串口通讯功能初始化上,除了涉及的寄存器地址不一样外,初始化流程几乎完全一样。
先参照例程单独调试一下UART1的基本串口功能。

使用特权

评论回复
5
hotpower| | 2007-3-7 12:15 | 只看该作者

先各自调试好再链接,应该很容易~~~

使用特权

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

本版积分规则

1

主题

2

帖子

0

粉丝