ARM LPC2138/48 Mini Development Board – UART1 Interfacing
In ARM LPC2138/48 Mini Development Board, UART1 is accessible through connector K12 that has 3 pins namely GND,TXD1 & RXD1.
- TXD1 – Transmission pin of UART1 (P0.8)
- RXD1 – Reception pin of UART1 (P0.9)
- GND – Common ground
SchematicSample Code
Sample code to test both transmission & reception of UART1 module is given below. The code is such that initially it transmits the string “Checking UART1″ and on receiving a character, the same gets retransmitted.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
/************************************************************************* HEADER FILE **************************************************************************/ #include<lpc21xx.h> /************************************************************************* * Function : UART_Init * * * * Description : Function to initialize UART1 * * * * Parameters : None * **************************************************************************/ void UART_Init(void) { U1LCR = 0X83; /* DLAB=1, 8 bit character */ U1DLL = 0XC3; /* Divisor Latch LSB */ U1DLM = 0X00; /* Divisor Latch MSB */ U1LCR = 0X03; /* DLAB=0, 8 bit character */ } /************************************************************************* * Function : UART_Data * * * * Description : Function to transmit single character * * * * Parameters : data - character to be transmitted * **************************************************************************/ void UART_Data(unsigned char data) { U1THR = data; /* Load the character to Transmit Holding register*/ /* Wait here till the character is transmitted */ while((U1LSR & 0X20)!= 0X20); } /************************************************************************* * Function : UART_String * * * * Description : Function to transmit string * * * * Parameters : String to be transmitted * **************************************************************************/ void UART_String(unsigned char *dat) { while(*dat!='\0') /* Check for termination character */ { UART_Data(*dat); /* Transmit the character */ dat++; /* Increment the pointer */ } } /************************************************************************* * Function : PORT_Initial * * * * Description : Function to initialize ports * * * * Parameters : None * **************************************************************************/ void PORT_Initial(void) { PINSEL0 = 0x00050000; /* TXD & RXD for P0.8 & P0.9 resp. */ } /************************************************************************* MAIN FUNCTION **************************************************************************/ int main() { PORT_Initial(); /* Initialize the ports */ UART_Init(); /* Initialize UART1 */ UART_String("Checking UART1"); while(1) { if((U1LSR&0X01)==0X01) /* RDR set when U1RBR contains data */ { U1THR = U1RBR; /* Transmit the received character */ while((U1LSR&0X20)!=0X20); } } } /************************** END OF PROGRAM *****************************/ |
OutputFlash the code into the controller and connect it to PC using suitable interface.. Various steps to check the output using RealTerm are given below.
- Step 1: Launch RealTerm
- Step 2: RealTerm opens as shown below
- Step 3: Go to ‘Port’ option, set correct baudrate (which is set as 9600 in the sample code) and correct port
- Step 4: Click ‘Change’ (encircled in red) to apply the changes. Now check the status of Port. If it is closed, click ‘Open’ button (encircled in green) to open it.
- Step 5: The data transmitted from the board can be viewed as shown below.
- Step 6: To check reception, go to Send option, type the string in the space provided(encircled in green) and click Send ASCII button. The first “hello” in green colour is transmitted from PC & that in yellow colour is retransmitted by the controller
Topics related to ARM LPC2138/48 Mini Development Board
- ARM LPC2138/48 Mini Development Board – Overview
- ARM LPC2138/48 Mini Development Board – LED Interfacing
- ARM LPC2138/48 Mini Development Board – LCD Interfacing
- ARM LPC2138/48 Mini Development Board – UART0 Interfacing
- ARM LPC2138/48 Mini Development Board – UART1 Interfacing
- ARM LPC2138/48 Mini Development Board – Switches Interfacing
- ARM LPC2138/48 Mini Development Board – BUZZER Interfacing
- ARM LPC2138/48 Mini Development Board – POT Interfacing (ADC)
- ARM LPC2138/48 Mini Development Board – Temperature Sensor Interfacing(ADC)
- ARM LPC2138/48 Mini Development Board – Interfacing Servo motor
- ARM LPC2138/48 Mini Development Board – Internal Real Time Clock (RTC)
- ARM LPC2148 Mini Development Board – USB Interfacing (Human Interface Device)
Resources
- Softwares
- Datasheets
How to buy?
- Click here to buy rhydoLABZ ARM LPC2129 Development board-Mini
- Click here to buy rhydoLABZ ARM LPC2138 Development Board-Mini
- Click here to buy rhydoLABZ ARM LPC2148 Development Board-Mini
Support
Please share your ideas with us, visit our forum for discussion