AN INTRODUCTION TO SERIAL PORT INTERFACING - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

AN INTRODUCTION TO SERIAL PORT INTERFACING

Description:

Setting Baud Rate. Usually the internal clock frequencies of UART=115, 200 Hz. Suppose we want to set baud rate to 2400 bps. Now ... Setting Baud Rate (Contd. ... – PowerPoint PPT presentation

Number of Views:204
Avg rating:3.0/5.0
Slides: 32
Provided by: mueens
Category:

less

Transcript and Presenter's Notes

Title: AN INTRODUCTION TO SERIAL PORT INTERFACING


1
AN INTRODUCTION TO SERIAL PORT INTERFACING
2
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.

3
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

4
Methods of timing used to find bit boundaries
  • Synchronous communication

5
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.

6
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

7
Advantage of Start / Stop bits
8
Some measures for error detection
  • Parity
  • Is of two types
  • 1. Even parity
  • 2. Odd parity
  • Suppose your data word is 8 bit in length i.e.
    one byte.
  • The sender, before transmitting byte, determines
    whether the no of bits in the byte to be sent are
    even. Suppose senders wants to send
  • 10011101
  • In which there are 5 1s and 3 0s .
  • To keep the no. of 1s even the sender adds an
    extra bit at the end of byte so that the total
    no. of 1s are 6 (an even no.). This extra bits
    is called parity bit. Since this bit keeps the
    no. of 1s even, so it is called even parity.

9
Overview of total bits with Parity
Odd Parity Odd parity is added to keep the no. of
1s odd in transmission. For example for above
case of data being 10011101 The odd parity
will be added as 0 as no of 1s are already 5 (an
odd no.).
10
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 1s including
    parity4 (no error for even parity). But
    actually it is false.
  • So parity does not ensure error detection in all
    cases.

11
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.

12
Serial / RS-232 Port on PC its Pin Out
13
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.

14
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

15
Configuration of Serial Port
16
Setting Baud Rate
  • Usually the internal clock frequencies of
    UART115, 200 Hz.
  • Suppose we want to set baud rate to 2400 bps.
  • Now we find the quotient.
  • 115,200/2400480x30
  • Taking it as 16 bit no the quotient is 0x00 high
    byte 0x30low byte
  • Now we set a bit DLAB (divisor latch access bit)
    which is bit 7 of the line control register
    (LCR)at base address 3
  • Usually the command is
  • outportb(0x3f8 3,inportb (0x3f83)0x80)

17
Setting Baud Rate (Contd.)
  • After setting DLAB bit in LCR, the function of
    registers at 0x3F8 0x3F9 changes as follows
  • Base Address Normal Function Function When
    DLAB1
  • Ox3F8 Tx/Rx register Divisor latch Low byte
  • Ox3F9 Interrupt enable register Divisor latch
    high byte.
  • For baud rate 2400bps
  • Divisor Latch Low byte 0x30
  • Divisor Latch high byte 0x00
  • Loading these registers with above values
    configures your serial port for baud rate of
    2400bps.

18
Specifying Start / Stop Bit Parity
  • The functionality of each bit of line control
    register (LCR) is shown in table below

19
(No Transcript)
20
The Function of various pins on Serial Port
21
The Function of various pins on Serial Port
(Contd)
22
Common way of Handling Flow Control Signals.
  • PC1 Serial Port PC2 Serial Port DB 9 Pins
    DB 9 pins
  • 3 TD RD 2
  • 2 RD TD 3
  • 5 SG SG 5
  • 4 DTR DTR 4
  • 6 DSR DSR 6
  • 1 CD CD 1
  • 7 RTS RTS 7
  • 8 CTS CTS 8
  • 9 Open Ckt. 9

23
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

24
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

25
Modem Status Register (MSR)
  • 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

26
Line Status Register (LSR)
  • 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

27
Writing a C Program to Send Serial Data to
Micro-Controller for Motor Control
  • include ltstdio.hgt
  • include ltconio.hgt
  • define PORT1 0x3F8
  • void main(void)
  • int c
  • outportb(PORT11,0)/ Turn off interrupts/
  • / of Port1 to use software testing mode/
  • / Now we set baud rate to 2400 bps /
  • outportb(PORT13,0x80) / SET DLAB ON /
  • outportb(PORT10,0x30)
  • /Divisor Latch Low Byte /
  • outportb(PORT1 1 , 0x00)
  • /Divisor Latch High Byte /

28
  • outportb(PORT13,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 /

29
Introduction to USB
  • USB Universal Serial Bus
  • A port to provide Plug and Play peripheral
    connectivity.
  • Developed and Standardized by joint venture of
    five major companies Compaq, DEC, IBM, Intel,
    Microsoft, NEC and Northern Telecom .
  • An expandable bus connectivity.
  • Facilitates use of Bus Powered Devices

30
Advantages offered by USB
  • USB provide fast data rate of transmission from
    1.5 Mb/sec to 12 megabit/s
  • Single model for cabling and connectors
  • Self identifying peripherals, automatic mapping
    of function to driver, and configuration
  • Dynamically attachable and reconfigurable
    peripherals

31
USB implementation model
Write a Comment
User Comments (0)
About PowerShow.com