Académique Documents
Professionnel Documents
Culture Documents
INTERFACING
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.
For example you receive following waveform from serial port of your PC and it
is stated that data rate is 2400bps
Synchronous communication
1
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
2
Overview of total bits with Parity
Odd Parity
Odd parity is added to keep the
no. of 1’s odd in transmission.
For example for above case of
data being
10011101
The odd parity will be added as 0 as no of 1’s are already 5 (an odd no.).
Failure of Parity
What if you transmit above byte 10011101 with even parity being used and
on receiver side you receive
10000101 1
shows bits inverted during transmission
On receiver side the no. of 1’s including parity=4 (no error for even parity).
But actually it is false.
So parity does not ensure error detection in all cases.
3
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 Address IRQ
COM 1 3F8-3FF 4
COM 2 2F8-2FF 3
COM 3 3E8-3EF 4
COM 4 2E8-3FF 3
+0 0 W - Transmit holding
0 R - buffer
1 R/W - Receive Buffer
Divisor latch low byte
+1 0 R/W IER Interrupt enable
1 R/W register
Divisor latch high byte
+2 - R IIR Interrupt Identification
- W FCR Register
FIFO Control register.
+3 - R/W LCR Line Control Register
+4 - R/W MCR Modem Control
Register
+5 - R LSR Line Status Register
+6 - R MSR Modem Status
Register
+7 - R/W - Scratch Register.
4
After setting DLAB bit in LCR, the function of registers at 0x3F8 & 0x3F9
changes as follows
5
The Function of various pins on Serial Port
6
Modem Control Register (MCR)
Bit Notes
Bit 7 Reserved
Bit 6 Reserved
Bit 5 Autoflow Control Enabled (16750 only)
Bit 4 LoopBack Mode
Bit 3 Aux Output 2
Bit 2 Aux Output 1
Bit 1 Force Request to Send
Bit 0 Force Data Terminal Ready
Bit Notes
Bit 7 Carrier Detect
Bit 6 Ring Indicator
Bit 5 Data Set Ready
Bit 4 Clear To Send
Bit 3 Delta Data Carrier Detect
Bit 2 Trailing Edge Ring Indicator
Bit 1 Delta Data Set Ready
Bit 0 Delta Clear to Send
Bit Notes
Bit 7 Error in Received FIFO
Bit 6 Empty Data Holding Registers
Bit 5 Empty Transmitter Holding
Register
Bit 4 Break Interrupt
Bit 3 Framing Error
Bit 2 Parity Error
Bit 1 Overrun Error
Bit 0 Data Ready
7
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 */
}