Interfacing RS232
What is RS232 RS means Recommended Standard. RS 232 uses both synchronous and asynchronous communication. In microcontrollers like ATmel 89C51 asynchronous communication is used and it is called as UART – universal asynchronous receiver and transmitter
Interfacing RS232 We need a driver to use the RS232 with microcontroller That driver turned out to be MAX232 It is a16 PIN Ic which is used to interface RS232 with any other devices. The transmission speed in the RS232 is called as baud rate.
Interfacing microcontroller with RS232 standard devices
Setting serial port In microcontroller there are some special function registers which are allocated to control the serial communication The list of registers which is used to control the serial port are  SCON PCON SBUF
Double the baud rate The baud rate standards are  1200 2400 4800 9600 But we can manually increase the baud rate into double the normal baud rate by setting the SMOD bit SMOD bit is located in PCON register.
How to calculate baud rate It is all depend upon the frequency Our frequency is 11.0592MHz Atmel has 12 Tcycles for a machine cycle Every instruction except branch instructions, execute in one machine cycle To obtain the speed of operation we have to use the timers again. Unlike the previous classes, timers will be used to generate speed here.
Speed calculation 11.0592M/12 = 921600 921600/32 = 28800   here 32 is the division factor it can be changed to 16 by setting SMOD bit 28800/?? = speed To get required speed we have to choose the value and store it in timer registers For example: for 9600 the value is 3. in TH1 it will be FD ie., 256-3=253  FD
Normal baud rate and double the normal baud rate SMOD = 0 SMOD = 1 1200 2400 2400 4800 4800 9600 9600 19200
Transmit and Receive Every thing is depends upon the interrupt when it comes to microcontroller, it is true that serial communication is not an exceptional for this. Transmit interrupt(TI) and receive interrupt(RI) are the two interrupt that control that operation of the serial communication
Transmission of data  Data can be store in the BUFFER assigned for serial communication(SBUF) Transmission will be complete when the transmit buffer is empty After acknowledging the transmit interrupt enabled due to empty transmit buffer we can reset the TI and continue the next transmission
Example for transmission Consider a letter A is going to be send through serial communication Then the coding should be SBUF=‘A’; While(TI==0); TI=0;
Receive operation It is reverse of the transmit operation The interrupt for the receive will be enabled when the receive buffer is full After receiving the acknowledgment of the receive complete the value can be read from BUFFER (SBUF)
Example for receive data Consider a ‘A’ is send to microcontroller through the serial port The program logic is  While(RI==0); Read=SBUF; RI=0;
Programming serial It is the same as all the interfacing with microcontroller Functions to solve the problem Since we not only receive or send a character but a lot of characters. Therefore a function will make it easy to get and send all the data we required.
Assignments  Send your name in serial port Get a data from serial port Try work with different baud rate Get a floating point from serial port and manipulate it and print in LCD(round off the floating point data)

Interfacing rs232

  • 1.
  • 2.
    What is RS232RS means Recommended Standard. RS 232 uses both synchronous and asynchronous communication. In microcontrollers like ATmel 89C51 asynchronous communication is used and it is called as UART – universal asynchronous receiver and transmitter
  • 3.
    Interfacing RS232 Weneed a driver to use the RS232 with microcontroller That driver turned out to be MAX232 It is a16 PIN Ic which is used to interface RS232 with any other devices. The transmission speed in the RS232 is called as baud rate.
  • 4.
    Interfacing microcontroller withRS232 standard devices
  • 5.
    Setting serial portIn microcontroller there are some special function registers which are allocated to control the serial communication The list of registers which is used to control the serial port are SCON PCON SBUF
  • 6.
    Double the baudrate The baud rate standards are 1200 2400 4800 9600 But we can manually increase the baud rate into double the normal baud rate by setting the SMOD bit SMOD bit is located in PCON register.
  • 7.
    How to calculatebaud rate It is all depend upon the frequency Our frequency is 11.0592MHz Atmel has 12 Tcycles for a machine cycle Every instruction except branch instructions, execute in one machine cycle To obtain the speed of operation we have to use the timers again. Unlike the previous classes, timers will be used to generate speed here.
  • 8.
    Speed calculation 11.0592M/12= 921600 921600/32 = 28800  here 32 is the division factor it can be changed to 16 by setting SMOD bit 28800/?? = speed To get required speed we have to choose the value and store it in timer registers For example: for 9600 the value is 3. in TH1 it will be FD ie., 256-3=253  FD
  • 9.
    Normal baud rateand double the normal baud rate SMOD = 0 SMOD = 1 1200 2400 2400 4800 4800 9600 9600 19200
  • 10.
    Transmit and ReceiveEvery thing is depends upon the interrupt when it comes to microcontroller, it is true that serial communication is not an exceptional for this. Transmit interrupt(TI) and receive interrupt(RI) are the two interrupt that control that operation of the serial communication
  • 11.
    Transmission of data Data can be store in the BUFFER assigned for serial communication(SBUF) Transmission will be complete when the transmit buffer is empty After acknowledging the transmit interrupt enabled due to empty transmit buffer we can reset the TI and continue the next transmission
  • 12.
    Example for transmissionConsider a letter A is going to be send through serial communication Then the coding should be SBUF=‘A’; While(TI==0); TI=0;
  • 13.
    Receive operation Itis reverse of the transmit operation The interrupt for the receive will be enabled when the receive buffer is full After receiving the acknowledgment of the receive complete the value can be read from BUFFER (SBUF)
  • 14.
    Example for receivedata Consider a ‘A’ is send to microcontroller through the serial port The program logic is While(RI==0); Read=SBUF; RI=0;
  • 15.
    Programming serial Itis the same as all the interfacing with microcontroller Functions to solve the problem Since we not only receive or send a character but a lot of characters. Therefore a function will make it easy to get and send all the data we required.
  • 16.
    Assignments Sendyour name in serial port Get a data from serial port Try work with different baud rate Get a floating point from serial port and manipulate it and print in LCD(round off the floating point data)