Monday, 23 July 2018

Serial Uart Communication in ARM Microcontroller (LPC2148)

Aim:

USART is one of the primitive inter-device communication protocols. It is not used in modern computers. But still, a few mother boards come with the module necessary for an USART communication. Here, in the case of PCs, the port is known as COM port and it follows RS232 protocol. It is no different from USART except for the voltage levels and some additional signals. Commonly MAX232 IC is used to translate the voltage level. MAX232 is a simple voltage translator buffer that converts +12/-12V of RS232 to 5/0V for USART. Other specifications are similar for USART and RS232. To know more about USART read this article from Wikipedia.

Description:


UART

UART (Universal Asynchronous Receiver Transmitter) are one of the basic interfaces which provide a cost effective simple and reliable communication between one controller to another controller or between a controller and PC.

RS-232 Level Converter

Usually all the digital ICs work on TTL or CMOS voltage levels which cannot be used to communicate over RS-232 protocol. So a voltage or level converter is needed which can convert TTL to RS232 and RS232 to TTL voltage levels. The most commonly used RS-232 level converter is MAX232.
This IC includes charge pump which can generate RS232 voltage levels (-10V and +10V) from 5V power supply. It also includes two receiver and two transmitters and is capable of full-duplex UART/USART communication.
☞RS-232 communication enables point-to-point data transfer. It is commonly used in data acquisition applications, for the transfer of data between the microcontroller and a PC.
☞The voltage levels of a microcontroller and PC are not directly compatible with those of RS-232, a level transition buffer such as MAX232 be used.

Interfacing UART

Fig. 1 shows how to interface the UART to microcontroller. To communicate over UART or USART, we just need three basic signals which are namely, RXD (receive), TXD (transmit), GND (common ground). So to interface UART with LPC2148, we just need the basic signals.
Fig. 1 Interfacing UART to Microcontroller
Fig. 1 Interfacing UART to Microcontroller

Interfacing UART with LPC2148

Display a text in PC using LPC2148 Development Board through UART module. In LPC2148 Development Board contains two serial interfaces that are UART0 & UART1. Here we are using UART0. The Transmitter pins send the data into PC and the receiver pin receives the data from PC. The PC and microcontroller speed are denoted by using baud rate. When the baud rates of both PC and Microcontroller are same, then only the data transmit and receive correctly otherwise not.

Pin Assignment with LPC2148



UART DB-9 Connector
LPC2148
Processor Lines
Serial Port Section
UART0(P1)
ISP PGM
TXD-0
P0.0
             Serial Port Section
RXD-0
P0.1
UART1
(P2)
TXD-1
P0.8
RXD-1
P0.9

Block Diagram

uart

Schematic


Code

// *****************************************************
// Project: Serial UART communication using atmega8
// Author: Hack Projects India
// Module description: Operate max232
// *****************************************************
#include <LPC214x.H>              // LPC21xx definitions                      */
char a;
void uart0_init(){
  PINSEL0 = 0x00000005;           // Enable RxD0 and TxD0                     */
  U0LCR = 0x83;                   // 8 bits, no Parity, 1 Stop bit            */
  U0DLL = 97;                     // 9600 Baud Rate @ 15MHz VPB Clock         */
  U0LCR = 0x03;                   // DLAB = 0                                 */
}
void uart0_putc(char c){
 while(!(U0LSR & 0x20)); // Wait until UART0 ready to send character  
 U0THR = c; // Send character
}
int uart0_getc (void)  {                     
  while (!(U0LSR & 0x01));
  return (U0RBR);
}
int main (void)  {                
  uart0_init();      
  while (1) {                          
  a=uart0_getc();
   uart0_putc(a);
  }                               
}

Downloads:

The code was compiled in Keil uvision4 and simulation was made in Proteus v7.7.
To download code and proteus simulation click here.

Further Reading suggestions:

No comments:

Post a Comment