You are on page 1of 17

AN INTRODUCTION TO SERIAL PORT INTERFACING

An Introduction to Serial communication


As the name implies, in the Serial communication you send bits of data serially i.e. one bit at a time. Normally we predefine rate of transfer such as 2400 bits/sec. (2400bps) 56,000 bits/sec. (56 kbps) And then depending upon this rate we interpret bits boundaries.

Example of Serial Waveform


For example you receive following waveform from serial port of your PC and it is stated that data rate is 2400bps

Methods of timing used to find bit boundaries


Synchronous communication

Asynchronous Communication
In Asynchronous communication the sender and receiver decide a data rate before communication. They decide upon signaling used for start & stop of data transmission. Both sender & receiver use a precise timing reference internally to divide serial received data into bits.

Basics of Serial Communication


Baud Rate The baud rate is simply the rate of data transmission expressed in bits per second, kilo Bits per second or Mega bits per second etc. The sender & receiver decide upon no of bits in one data word such as 8 bits (1byte) etc. More over they decide that: A first bit before transmission of data word will always be 0 (or 1) after which data bits will follow. It is called

start bit.

The last bit followed by data bits will always be 1(or 0) after which it requires start bit for transmission of next word. This bit is called stop bit

Advantage of Start / Stop bits

EIA RS232C Serial Interface Standard


A Space (logic 0) will be between 3 and 25 volts. A Mark (logic 1) will be between -3 and -25 volts. The region between 3 & -3 volts is undefined. Maximum data rates may be up to 20 kbps. Maximum serial cable length may be 15 meters. The reason to study RS-232C is that the serial part (Com port) found in PCS uses this standard. Above are the sufficient points to start implementation of the serial interfacing on PC.

Serial / RS-232 Port on PC & its Pin Out

Introduction of UART & USART


UART Stands for Universal Asynchronous Receiver Transmitter USART Stands for Universal Synchronous Asynchronous Receiver Transmitter In RS-232 we implement serial port with UART Actually UART receives/sends data to microprocessor through data bus. The remaining part of signal handing of RS-232 is done by UART i.e. start bit, stop bit, parity etc.

Port Address of Serial Part


Name COM 1 COM 2 COM 3 COM 4 Address IRQ 3F8-3FF 4 2F8-2FF 3 3E8-3EF4 2E8-3FF 3

The Function of various pins on Serial Port


Pin # on DB 9 1 2 3 4 5 6 7 Pin Symbol CD RD TD DTR SG DSR RTS Function Carrier Detect: It is used by Modem to inform PC that it has detected Carrier on Phone Line. Serial data is received on this line by PC. Serial Data is transmitted on this pin by PC. Data Terminal Ready When terminal (computer) powers up it asserts DTR high. It is signal ground with reference to which voltages are interpreted as high or low. Data Set Ready. When modem powers up it asserts DSR high. Request to Send. Request to send is sent from (DTE) terminal (PC) to modem (DCE) to inform it that PC wants to send some data to modem.

The Function of various pins on Serial Port (Contd)

CTS

Clear To Send. Upon received RTS from DTE (PC), the modem (DCE) asserts CTS high whenever it is ready to receive data. Ring Indicator. It is set by modem to indicate the PC that a ringing signal has been detected on line.

RI

Common way of Handling Flow Control Signals.


PC1 Serial Port DB 9 Pins 3 TD 2 RD 5 SG 4 DTR 6 DSR 1 CD 7 RTS 8 CTS 9 Open Ckt. PC2 Serial Port DB 9 pins RD 2 TD 3 SG 5 DTR 4 DSR 6 CD 1 RTS 7 CTS 8 9

Details of remaining registers


To study details of each bit of remaining registers of serial port you can refer to the documentation provided in the document Interfacing the Serial /RS232 port found on www.beyondlogic.org by Craig C Peacock A discussion of important registers follows:

Writing a C Program to Send Serial Data to Micro-Controller for Motor Control #include <stdio.h>
#include <conio.h> #define PORT1 0x3F8 void main(void) { int c; outportb(PORT1+1,0);/* Turn off interrupts*/ /* of Port1 to use software testing mode*/ /* Now we set baud rate to 2400 bps */ outportb(PORT1+3,0x80); /* SET DLAB ON */ outportb(PORT1+0,0x30); /*Divisor Latch Low Byte */ outportb(PORT1 + 1 , 0x00); /*Divisor Latch High Byte */

outportb(PORT1+3,0x03); /* 8 Bits, No Parity, 1 Stop Bit */ printf("\n Motor Speed Control Program\n"); printf(" Enter 27 to quit \n"); do { printf("\n Please enter a number between 0 to 255 except 27 : "); scanf("%d",&c); printf("\n"); outportb(PORT1,c); /* Send the input number to Serial Port */ } while (c !=27); /* Quit when 27 is entered */ }