Spread the love

RS232 protocol of ARM7 ( LPC2148 )

____________________________________________________________________________________________________


What is serial COM ?

A computer transfers data by two methods called serially and paralleled, both have its own merits and demerits according to application. Here we discuss only about serial communication. In serial com data are transfers bit by bit from transmitter to receiver.

5404711652_d13f044690_m

About & Types serial COM-

  1. If data transmitted one way a time, it is referred to as half duplex.
  2. If data can go both ways at a time, it is full duplex.

Following are the pin connectors that are used to connect microcontroller with PCs.

product_image_113_8_9_18_45_36400px-RS232-TTL_Converter

  • Serial data communication uses two methods:
  1. Synchronous method transfers a block of data at a time
  2. Asynchronous method transfers a single byte at a time
  • Asynchronous serial data communication is widely used for character-oriented transmissions

(1)     Each character is placed in between start and stop bits, this is called framing (8-bit = single character)

(2)     Block-oriented data transfers use the synchronous method

  • The start bit is always one bit, but the stop bit can be one or two bits. Due to the extended ASCII Characters, 8-bit ASCII data is common. In modern PCs, the use of one stop bit is standard. Assuming that we are transferring a text file of ASCII characters using 1 stop bit, we have a total of 10 bits for each character including 8 character with 1 start and 1 stop bit.
  •  The rate of data transfer in serial data communication is stated in bps (bits per second). Another widely used terminology for bps is baud rate.  It is modem terminology and is defined as the number of signal changes per second. In modems, there are occasions when a single change of signal transfers several bits of data.
  • The data transfer rate of given computer system depends on communication ports incorporated into that system
    • IBM PC/XT could transfer data at the rate of 100 to 9600 bps
    • Pentium-based PCs transfer data at rates as high as 56Kbps
    • In asynchronous serial data communication, the baud rate is limited to 100Kbps
  • In RS232 protocol, a 1 is represented by -3  to -25 V, while a 0 bit is +3  to  +25 V, making -3 to +3 undefined and support TTL logics.
  • Microcontroller used CMOS logics generally, so we need a line driver such as the MAX232 chip which is required to convert RS232 voltage levels to CMOS levels, and vice versa.
  • Following diagram is shown interfacing diagram of ATmega32 with PC and use of MAX232 IC.

 RS232 protocol of ARM7 ( LPC2148 )

  • To allow data transfer between the PC and an microcontroller system without any error, we must make sure that the baud rate of microcontroller system matches the baud rate of the PC’s COM port.

Applications

  Communication between computer and microcontroller.

Click Here : Understanding of RS232 protocol and setting up baud rate

Click Here : Registers used in serial com programming

 

1. Circuit Diagram Of RS232 Protocol Of ARM7 (LPC2148)

Circuit Diagram Of RS232 Protocol Of ARM7 (LPC2148)

 2. Circuit Diagram Of RS232 Protocol Of ARM7 (LPC2148) With LCD

 Circuit Diagram Of RS232 Protocol Of ARM7 (LPC2148) With LCD

 

_______________________________________________________________________________________________________

 

1. Program of RS232 Protocol Of ARM7 (LPC2148) 

In this program controller send “www.firmcodes.com” to PC or Laptop and it will display on the hyper terminal of PC or Laptop

/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- DATA SEND FROM ARM7(LPC21XX) THROUGH 
RS232 PROTOCOL AND DISPLAY DATA ON PC
******************************************************/

#include<lpc21xx.h>

unsigned char rec;

void pll();
   
void serial_ini();
void serial_transmit(unsigned char x);

 void delay(int x);
 
int main()
   {
         PINSEL0 = 0x00000005;
         IO0DIR=0XFFFFFFFF;
         serial_ini();
         pll();
         while(1)
           {
                         serial_transmit('W');  //  call transmit function 
                         delay(100);            // calling of delay function
                         serial_transmit('W');  //  call transmit function
                         delay(100);            // calling of delay function
                         serial_transmit('W');  //  call transmit function
                         delay(100);            // calling of delay function
                         serial_transmit('.');  //  call transmit function
                         delay(100);            // calling of delay function
                         serial_transmit('F');  //  call transmit function
                         delay(100);            // calling of delay function
                         serial_transmit('I');  //  call transmit function
                         delay(100);            // calling of delay function
                         serial_transmit('R');  //  call transmit function
                         delay(100);            // calling of delay function
                         serial_transmit('M');  //  call transmit function
                         delay(100);            // calling of delay function
                         serial_transmit('C');  //  call transmit function
                         delay(100);            // calling of delay function
                         serial_transmit('O');  //  call transmit function
                         delay(100);            // calling of delay function
                         serial_transmit('D');  //  call transmit function
                         delay(100);            // calling of delay function
                         serial_transmit('E');  //  call transmit function
                         delay(100);            // calling of delay function
                         serial_transmit('S');  //  call transmit function
                         delay(100);            // calling of delay function
                         serial_transmit('.');  //  call transmit function
                         delay(100);            // calling of delay function
                         serial_transmit('C');  //  call transmit function
                         delay(100);            // calling of delay function
                         serial_transmit('O');  //  call transmit function
                         delay(100);            // calling of delay function
                         serial_transmit('M');  //  call transmit function
                         delay(100);            // calling of delay function
                        serial_transmit(0x0d);  //  call transmit function
                        delay(400);
                        delay(400);

           }
   }

void pll()
   {
        /*PLL IS CONFIGURED TO GET 60HZ pCLK*/
        PLLCFG=0X24;           // SET PSEL=2 AND MSEL=5
        PLLCON=0X01;           //PLL IS ACTIVE BUT NOT YET CONNECT
        PLLFEED=0XAA;          //FEED SEQUENCE
        PLLFEED=0X55;          //FEED SEQUENCE
        while((PLLSTAT & 0X400)==0);   //WAIT FOR FEED SEQUENCE TO BE INSERTED
        PLLCON=0X03;           // PLL HAS BEEN ACTIVE AND BEING CONNECTRD
        VPBDIV=0X00;           // SET PCLK SAME AS FCCLK
        PLLFEED=0XAA;          //FEED SEQUENCE
        PLLFEED=0X55;          //FEED SEQUENCE
   }
   
/* SERIAL INITILIZATION*/

void serial_ini()
   {
        
        U0LCR =0x83;
        U0DLM=0X00;
        U0DLL=0X5e;
        U0FDR=0X52;
        U0LCR =0x03;
   }
   
void serial_transmit(unsigned char x)
   {
        U0THR =x;                    // LOAD DATA IN U0THR REGISTER
        while ((U0LSR & 0x40)==0);  // WAIT FOR DATA TRANSMISSION
        U0LSR|=0X40;
   }
   
 void delay(int x)
   {
         int i,j;
         x=x*10;
         for(i=0;i<x;i++)
         for(j=0;j<350;j++);
   }

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)

download (1)

_______________________________________________________________________________________________________

2.Program Of RS232 Protocol Of ARM7 (LPC2148) With Lcd

In this program data entered from the hyper terminal of PC or Laptop is appeared on the LCD connected to the controller

/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- DATA SEND FROM PC BY RS232 PROTOCOL IS 
DISPLAYED ON LCD CONNECTED WITH ARM7(LPC2148)
******************************************************/

#include<lpc21xx.h>

#define LCD (0xff<<16)
#define RS (1<<13)
#define RW (1<<14)
#define EN (1<<15)

void delay_fv(unsigned int x,int y);

void lcd_display(unsigned int x);
void cmd(unsigned char m);
void lcd_ini();

unsigned char rec;

void pll();

void serial_ini();
char serial_re();

int main()
  {
         PINSEL0 = 0x00000005;
         PINSEL1 = 0x00000000;
         IO0DIR=0XFFFFFFFF;
         serial_ini();
         pll();
         lcd_ini();
         while(1)
           {
                serial_re();
                lcd_display(rec);
           }
   }

void delay_fv(unsigned int x,int y)
  {
      unsigned int i,j;
      for(i=0;i<x;i++)
         for(j=0;j<y;j++);
  }
  
void lcd_display(unsigned int x)
  {
     IO0CLR|=(RS|RW|EN|LCD);
     IO0SET|=(x<<16);
     IO0SET|=RS;
     IO0CLR|=RW;
     IO0SET|=EN;
     delay_fv(100,10);
     IO0CLR|=EN;
     delay_fv(10,10);
  }

void cmd(unsigned char m)
  {
     IO0CLR|=(RS|RW|EN|LCD);
     IO0SET|=(m<<16);
     IO0CLR|=RS;
     IO0CLR|=RW;
     IO0SET|=EN;
     delay_fv(100,100);
     IO0CLR|=EN;
     delay_fv(100,10);
  }

void lcd_ini()
  {
     cmd(0X38);
     cmd(0X0e);
     cmd(0X06);
     cmd(0X01);
     cmd(0X80);
  }
  
void pll()
  {
      /*PLL IS CONFIGURED TO GET 60HZ pCLK*/
      PLLCFG=0X24;           // SET PSEL=2 AND MSEL=5
      PLLCON=0X01;           //PLL IS ACTIVE BUT NOT YET CONNECT
      PLLFEED=0XAA;          //FEED SEQUENCE
      PLLFEED=0X55;          //FEED SEQUENCE
      while((PLLSTAT & 0X400)==0);   //WAIT FOR FEED SEQUENCE TO BE INSERTED
      PLLCON=0X03;           // PLL HAS BEEN ACTIVE AND BEING CONNECTRD
      VPBDIV=0X00;           // SET PCLK SAME AS FCCLK
      PLLFEED=0XAA;          //FEED SEQUENCE
      PLLFEED=0X55;          //FEED SEQUENCE
  }
  
void serial_ini()
{
        
        U0LCR =0x83;
        U0DLM=0X00;
        U0DLL=0X5e;
        U0FDR=0X52;
        U0LCR =0x03;
}

char serial_re()
  {
        while ((U0LSR & 0x01)==0); //  wait untill complete data is received 
        rec=U0RBR;   
        return rec;
  }

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)

download (1)

_______________________________________________________________________________________________________

Content for the tab VIDEO