/**************************************************************************** * $Id:: uarttest.c 3635 2012-10-31 00:31:46Z usb00423 * Project: NXP LPC8xx USART example * * Description: * This file contains USART test modules, main entry, to test USART APIs. * ****************************************************************************/ #include "LPC8xx.h" #include "lpc8xx_clkconfig.h" #include "lpc8xx_uart.h" volatile uint32_t UARTLoopbackCount = 0; extern volatile uint32_t UARTRxCount; extern volatile uint32_t RxErrorCount; extern volatile uint8_t UARTRxBuffer[BUFSIZE]; /***************************************************************************** ** Function name: Main ** ** Descriptions: Main entry ** parameters: None ** Returned value: int ** *****************************************************************************/ int main (void) { /* Main Program */ uint32_t i, regVal; SystemCoreClockUpdate(); CLKOUT_Setup( CLKOUTCLK_SRC_MAIN_CLK ); /* * Initialize UARTx pin connect * connect the UART0 TXD abd RXD sigals to port pins(P0.4-P0.0) */ regVal = LPC_SWM->PINASSIGN0 & ~( 0xFF << 0 ); LPC_SWM->PINASSIGN0 = regVal | ( 4 << 0 ); /* P0.4 is UART0 TXD, ASSIGN0(7:0) */ regVal = LPC_SWM->PINASSIGN0 & ~( 0xFF << 8 ); LPC_SWM->PINASSIGN0 = regVal | ( 0 << 8 ); /* P0.0 is UART0 RXD. ASSIGN0(15:8) */ UARTInit(LPC_USART0, 9600); UARTSend(LPC_USART0, (uint8_t *)"Hello World!\r\n", 14); for ( i = 0; i < 0x10000; i++ ); while ( 1 ){ if ( UARTRxCount && !RxErrorCount ){ LPC_USART0->INTENCLR = RXRDY; /* Disable RXRDY */ UARTSend( LPC_USART0, (uint8_t *)UARTRxBuffer, UARTRxCount ); UARTRxCount = 0; LPC_USART0->INTENSET = RXRDY; /* Re-enable RXRDY */ } } }