Serial Port Complete - Latest Microcontroller projects

(lily) #1

Chapter 2


intervals to a remote computer. Or a device might be responsible for monitor-
ing and controlling equipment while occasionally sending information or
receiving instructions via a serial link.
A transmitting computer might want to send data at a time when the receiving
computer is occupied with something else. Hardware and programming can
help ensure that a receiver sees all of the transmitted data and that data arrives
without errors.
Ways to ensure that data arrives without errors include flow control, buffering,
use of polling or interrupts to detect received data, error checking, and
acknowledging received data. The descriptions below are an introduction to
these concepts. The chapters that follow show how to implement the concepts
in applications.

 
 


With flow control, a transmitting computer can indicate when it has data to
send, and a receiving computer can indicate when it’s ready to receive data. The
computers in a serial link should use flow control unless the receive buffers are
large enough to hold all of the data that might arrive before the receiving com-
puter can read the data from the buffer.
In a common form of hardware flow control, the receiver sets a dedicated line
to a defined state when ready to receive data. The transmitting computer checks
the state of the line before sending data. If the line isn’t in the expected state, the
transmitting computer waits. Flow control in both directions requires a line for
each direction. Flow control is sometimes called handshaking. However, a full
handshake requires 2-way communication: the transmitting computer indicates
that it has data to send, and the receiving computer indicates when it is ready to
receive the data.
The RS-232 specification assigns names to flow-control signals. On a PC, the
input signal is Clear To Send (CTS) and the output signal is Request to Send
(RTS). (The names reflect an alternate usage of the lines to implement a full
handshake.) A cable that connects two PCs must connect each RTS output to
the other computer’s CTS input. A positive RS-232 voltage means ready to
receive and a negative voltage means not ready.
Microcontrollers typically don’t have dedicated CTS and RTS lines. Device
firmware can use any spare port pins for flow control. Source code can use the
names RTS and CTS or use names such as flow_control_in and
Free download pdf