Download cpe323_Serial_IO

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Telecommunications engineering wikipedia , lookup

Multidimensional empirical mode decomposition wikipedia , lookup

Immunity-aware programming wikipedia , lookup

Serial digital interface wikipedia , lookup

Transcript
Serial I/O
by Alex Milenkovich, [email protected]
To interface other devices in the system our microcontrollers may use parallel I/O interfaces. If
we want to read a byte from a device connected to our microcontroller we may have our parallel
I/O interface configured as an input port and once data become available we can read it from the
input port. The problem with this approach is that we need at least 8 wires to connect the device
and our microcontroller, which is expensive if the devices are on a single board (more PCB
traces) or we need to use a wide parallel cable that is bulky and expensive. In addition, multiple
transmission lines may induce noise or become susceptible to noise. A possible solution to these
problems is offered by serial I/O interfaces. Data are sent one bit at a time, thus reducing the
number of transmission lines required. Next, adopted standards defining appropriate logic levels
we can better cope with noise and reduce the effects of long transmission lines.
1.
Principles of Asynchronous Communication
Transmitter (device T) – wants to send a byte to device R (Receiver)
1. Microcontroller (T side): Write the byte into the Transmit Data Buffer (visible to the
programmer) of the Serial I/O interface
2. Serial I/O interface (T side): Loads the data from the Data Transmit Buffer into a shift
register (parallel-in/serial-out); The data are shifted out of this register using Tclock clock
signal.
3. Serial I/O interface (R side): The data from a single transmission line that goes from
device T to device R are shifted in the serial-in/parallel out shift register. The data are
shifted on every Rclock cycle. It is assumed that Tclock=Rclock
4. Serial I/O interface (R side): When all 8 bits are received by in the shift register, the data
is transferred to the Receive Data Buffer in parallel.
5. Microcontroller (R side): Read the byte from the Receive Data Buffer (visible to the
programmer) of the Serial I/O interface.
Such a device is called Universal Asynchronous Receiver/Transmitter (or UART for short) and
is the basis for most serial communication hardware.
Communication is called asynchronous serial communication because the characters can be sent
at any time and not synchronized with any process in either transmitter or receiver device.
Questions:
1) Data encoding?
ASCII
2) Which bit is sent first?
LSB bit is sent first.
3) How is the receiver synchronized with the transmitter? The data bits are encapsulated
between two other bits known as the START bit and STOP bit.
Illustrations of the serial character transmission.
Logic one – MARK level
Logic zero – SPACE level
If nothing to transmit, the transmitter holds the MARK level (logic one).
Start bit: to mark the beginning of a new character, the line changes from the mark to the space
level for one bit time. This synchronizes the transmitter and receiver. When the receiver detects
the start bit, it knows to start clocking in the serial data bits.
Data bits: any number of bits can be theoretically sent. In practice, it is between 5 and 8 bits.
Parity bit: 7 bits are needed to encode a character. Most UARTS allow 8 bits to be sent. The
parity bit is added to the data to make the total of ones odd (ODD parity) or even (EVEN parity).
The parity bit is used to detect possible errors in the data stream.
Stop bit: The stop bit is added at the end of the data bits. This gives at least one bit time period
between successive characters. Some systems require 2 or more stop bits.
What is the data rate?
The rate at which bits are sent and received is bit rate and is often referred to as baud rate
(misleading name). The standard data rates are 110; 150; 300; 600; 900; 1200; 2400; 4800;
9600; 14,400; 19,200; 38,400; 57,800;
What the logic levels of on transmission lines? Any handshaking?
Several standards are defined. They specify: handshaking signals, direction of signal flow, types
of communication devices, connectors and interface mechanical considerations, electrical signal
levels. The RS-232-C standard is used in most serial interfaces.
First, take a look at types of communication systems and modems.
Simplex system: data are sent in one direction only (data + ground lines).
Full-duplex system: data flow in both directions (2 data lines + ground)
Half-duplex systems: Data are transferred in two directions but only in one direction at a time
(bidirectional data line + ground). Often requires additional handshaking signals.
2.
UARTS
3.
Standards for the Serial I/O Interface
There exists several standards that define the interface between two UARTs in a serial
communication system. These standards allow us to connect equipment from different
manufacturers and typically define the following components:





Handshaking signals
Direction of signal flow
Types of communication devices
Connectors and interface mechanical considerations
Electrical signal levels
EIA (Electronic Industry Association) RS-232-C standards is used in most serial interfaces.
However, when the signals are transmitted farther than 50 feet or at greater speeds, other
standards such as RS-422, RS-423, and RS-485 should be used.
Handshaking signals.
They are used for synchronization and control of the transmitter and receiver. All signals except
RxD and TxD are for handshaking. <<More on this later>>
Communication system types.
Simplex system: Data are sent in one direction only (two lines: data, ground)
A full duplex system: Data are sent in both directions (three line: RxD, TxD, ground; sometimes
referred to as a 4-wire system – two pairs of signal wires;)
A half-duplex system: Data are transferred in two directions with only one pair of signal wires.
Additional hardware and handshaking signals must be added. For example, let us consider
terminal to computer communication on the figure below. The interface blocks are responsible
for the following: 1) provide full duplex communication to the terminal or computer; 2) decide
whether they or their opposite interface is sending or receiving data, and 3) use and control the
handshaking signals RTS and CTS. RTS is asserted by computer or terminal when data are to be
sent. When the interface finds that the other side is not sending data, it asserts the CTS signal.
The computer or terminal must wait until it is clear to send before transmitting.
Terminal
RTS
CTS
Interface
Interface
RTS
CTS
RTS
CTS
Computer
RTS
CTS
Data Terminal Equipment/Data Communication Equipment (DTE/DCE)
In practice the interface blocks are models, and two-wire half-duplex line is a telephone line.
Modems are called DCEs and terminals and computers are called DTEs.
Modems: how do they work?
Modulator/demodulator. It converts logic levels into tones to be sent over a telephone line. This
is the modulation process. At the other end of the line a demodulator converts the tones back to
logic levels. In a half-duplex system, a single set of tones is defined, one tone fro mark and one
for space.
Half-duplex modems are no longer used because modems have been developed to allow fullduplex data transmission over a telephone line. A full duplex system has two kinds of modems,
called originate and answer modems, and two sets of tones.
Originate modem
Modulator tones
1070 Hz-Space
1270 Hz-Mark
Demodulator
Direction
Answer modem
Demodulator
->
->
Modulator tones
2025 Hz – Space
2225 Hz - Mark
<<-
Modems Handshaking Signals
25 Pin Connector on a DTE device (PC connection)
Male RS232
DB25
Pin Number
Direction of signal:
1
Protective Ground
2
Transmitted Data (TD) Outgoing Data (from a DTE to a DCE)
3
Received Data (RD) Incoming Data (from a DCE to a DTE)
4
Request To Send (RTS) Outgoing flow control signal controlled by DTE
5
Clear To Send (CTS) Incoming flow control signal controlled by DCE
6
Data Set Ready (DSR) Incoming handshaking signal controlled by DCE
7
Signal Ground Common reference voltage
8
Carrier Detect (CD) Incoming signal from a modem
20
Data Terminal Ready (DTR) Outgoing handshaking signal controlled by DTE
22
Ring Indicator (RI) Incoming signal from a modem
9 Pin Connector on a DTE device (PC connection)
Male RS232
DB9
Pin Number
Direction of signal:
1
Carrier Detect (CD) (from DCE) Incoming signal from a modem
2
Received Data (RD) Incoming Data from a DCE
3
Transmitted Data (TD) Outgoing Data to a DCE
4
Data Terminal Ready (DTR) Outgoing handshaking signal
5
Signal Ground Common reference voltage
6
Data Set Ready (DSR) Incoming handshaking signal
7
Request To Send (RTS) Outgoing flow control signal
8
Clear To Send (CTS) Incoming flow control signal
9
Ring Indicator (RI) (from DCE) Incoming signal from a modem
References:
http://www.bb-elec.com/bb-elec/literature/tech/faq_rs232_connections_work.pdf
http://www.connectworld.net/rs232.html