Interfacing rs232

8,566 views

Published on

Published in: Technology

Interfacing rs232

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

×