使用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; } } |