Serial Port Complete - Latest Microcontroller projects

(lily) #1
Formats and Protocols


   

6 



In many serial-port applications on PCs, the user interface provides a combo
box where the user can select a bit rate for the port. The ultimate in user conve-
nience is computers that automatically configure themselves to use the same bit
rate. To achieve matching bit rates, one computer (we’ll call it the sending com-
puter) can detect and match the bit rate of the other computer (we’ll call it the
receiving computer). There are a couple of ways to implement automatic
matching of bit rates.
In one approach, the sending computer establishes communications by repeat-
edly sending a byte. The byte can be any value from 00h to EFh, where the
most significant data bit, which is the last bit to transmit, is zero.
The receiving computer attempts to receive data at the highest supported bit
rate. On detecting a Start bit, the computer must receive data for a period equal
to or greater than the time required to read a byte at the lowest supported bit
rate (for example, 33 ms at 300 bps).
If the receiving computer detects more than one received byte, the bit rates
don’t match. The sending computer tries again using the next lowest bit rate.
When the receiving computer detects one and only one received byte, the bit
rates match. As an extra check, the receiving computer can verify that the
received byte matches an expected value. The receiving computer can send a
byte to acknowledge the match, and on receiving the byte, the computers can
begin normal communications.
The method works like this: when the receiving computer’s bit rate is faster
than the transmitting computer’s bit rate and the last transmitted data bit is
zero, the receiving computer finishes reading the byte while the bits are still
arriving. (A receiving computer that doesn’t see a logic 1 Stop bit will generate a
framing error, but the error is unimportant for detecting the bit rate.) After the
receiving computer thinks the word has finished transmitting, any received
logic 0 (such as the last bit in the transmitted byte) looks like a Start bit, which
causes the receiving computer to try to read another byte. If the receiving com-
puter doesn’t see another Start bit, the bit rates match.
Another approach for automatically detecting a bit rate requires code that can
measure the width of a a received bit on the port. If the sending computer sends
a specific value, the receiving computer can measure a received pulse’s width
and set a bit rate to match.
Free download pdf