Serial Port Complete - Latest Microcontroller projects

(lily) #1
Formats and Protocols

   


In some applications, the transmitting computer needs an acknowledgment
that the data was received. Acknowledgments are especially useful in networks
where multiple computers share a communications path and a driver’s switch-
ing on at the wrong time can block another computer’s transmission.
An acknowledgment can be a defined value, or the transmitting computer can
assume that a computer received its message on receiving a response with
requested data or other information. A transmitting computer that doesn’t
receive an expected response can assume there is a problem and retry or take
other action.
When sending to a computer that has no input buffer or a very small buffer, a
transmitting computer can use a full handshake to ensure that the receiving
computer is ready to receive a block of data. The transmitting computer can
begin by sending a code, repeatedly if needed, to announce that the computer
wants to send data. On detecting the code, the receiving computer can send a
code to acknowledge and then devote full attention to monitoring the serial
input. On seeing the acknowledgment, the transmitting computer knows it’s
OK to send the rest of the data.

0 
  


A receiver can use error checking to verify that all data arrived correctly. Ways to
check a message for errors include parity bits, checksums, and sending duplicate
data.
As described earlier in this chapter, a parity bit in each transmitted word enables
the receiving computer to detect most errors introduced between the transmit-
ter and receiver. When using .NET’s SerialPort class or other serial-port classes
or libraries for PC applications, the application only needs to select a parity
type. The software automatically calculates and places the correct parity bit in
each transmitted word and can raise an error on receiving data with incorrect
parity. Microcontroller hardware and software may require the firmware to cal-
culate and set or check the parity bit for each transmitted and received word.
A checksum is an error-checking value obtained by performing mathematical or
logical operations on the contents of a block of data. Applications can choose
from a variety of methods to calculate checksums.
A basic checksum calculation adds the values of the bytes in a block and uses
the lowest byte of the result as the checksum. A checksum for ASCII Hex data
Free download pdf