21
Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC Madison, WI 53704

Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

Embed Size (px)

Citation preview

Page 1: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

Serial Port Complete

COM Ports, USB Virtual COM Ports,

andPorts for Embedded Systems

Second Edition

Jan Axelson

Lakeview Research LLCMadison, WI 53704

Page 2: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

Serial Port Complete: COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition

Jan Axelson

Copyright 1998, 1999, 2000, and 2007 by Janet L. Axelson

All rights reserved. No part of the contents of this book, except the code examples, may bereproduced or transmitted in any form or by any means without the written permission ofthe publisher. The code examples may be stored and executed in a computer system andmay be incorporated into computer programs developed by the reader.

The information, computer programs, schematic diagrams, documentation, and othermaterial in this book are provided “as is,” without warranty of any kind, expressed orimplied, including without limitation any warranty concerning the accuracy, adequacy, orcompleteness of the material or the results obtained from using the material. Neither thepublisher nor the author shall be responsible for any claims attributable to errors, omissions,or other inaccuracies in the material in this book. In no event shall the publisher or authorbe liable for direct, indirect, special, incidental, or consequential damages in connectionwith, or arising out of, the construction, performance, or other use of the materials con-tained herein.

MPLAB, PICDEM, and PIC are registered trademarks of Microchip Technology Inc. in theU.S.A. and other countries. Other product and company names mentioned herein may betrademarks of their respective holders.

Published by Lakeview Research LLC, 5310 Chinook Ln., Madison WI 53704

On the web at www.Lvr.com

Distributed by Independent Publishers Group (www.ipgbook.com).

14 13 12 11 10 9 8 7 6 5 4 3 2 1

ISBN 978-1931448-07-9

Page 3: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

iii

��������

���������� ����

�������������� ���

� ������� �� ������� �

��������������� ����������

Advantages 2Limits 4

�������������������

The Computers 4The Physical Link 6Programming 6

���� �� ������

Example Systems 8Managing Communications 9Special-purpose Modules 9

Page 4: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

iv

� ������� �� ��������� ��

���� ������ ���������

Asynchronous and Synchronous Communications 11Word Formats 12Bit Rate and Baud Rate 13System Support for Low-level Protocols 14

���� ���� ������

The Format 15The Need for Accurate Timing 15Autodetecting the Bit Rate 17Autodetecting a COM Port 18

�������������

Binary Data 18Text Data 19ASCII Hex 22Application-specific Protocols 24

��� ��� ���! ����������

Flow Control 26Buffers 27Event-driven Programming and Polling 28Acknowledgments 29Error Checking 29

� ��� ����� �� ��� ��

��������� ����������"�

Device Manager 31Port Resources 36Serial Servers 37

���� ����������"�

Drivers 38Identifying Ports 39GUIDs for COM Ports 39COM Port Numbering 40INF Files 40Options for Application Programming 41

Page 5: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

v

� ����� !"��� ��

#���$��%���&����'������"

Signals 43Voltages 46Timing Limits 48

��� ��� ���(����������

Interface Chips 49Short-range Circuits 53

����)��%������ ��� ������

Using Outputs as a Power Source 56Regulating the Voltage 57

���������&����'�������

Direct Connection 58Other Unbalanced Interfaces 58

# $�������� !"��� %���� &�

����������������������*�

Connector Options 62Adapters 63Using Microcontroller Development Boards 65

�+�����*,

Length Limits 67Surge Protection 69

&������- �����,.

Ways to Achieve Isolation 70About Grounds 70Power Supply Grounds 72Optoisolating 75

��+��� ���#������,*

Using a Breakout Box 76Monitoring with a Voltmeter 77Oscilloscopes and Logic Analyzers 78

Page 6: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

vi

& ����� !"�'# ()

�+����/�)������,0

Balanced and Unbalanced Lines 80Voltage Requirements 84Current and Power 85Speed 87Internal Protection Circuits 88

&����'� ���1�� ������0

Chips 89Adding a Port on a PC 91Converting 3.3/5V Logic 91Converting RS-232 93

�������� ��������� ���2�+�����0*

Re-enabling the Driver 97Software-assisted Control 97Hardware Control 99

( $�������� !"�'# %���� �� *������� �+#

-�������������- ������.*

When Is a Line Long? 106Calculating Line Length 109Choosing a Driver Chip 111

- ���#��� �� ��������

Characteristic Impedance 112Adding a Termination 113Effects of Terminations 115Reflections 117Series Terminations 122Terminations for Short Lines 122AC Terminations 123Network Topologies 125

� �������- �������,

Open-circuit Protection 127Short-circuit Protection 130

Page 7: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

vii

�+���#�������"�

How a Wire Picks Up Noise 132Twisted-pair Cable 133Selecting Cable 133

3���������� ''����� ��- ������"�

Ensuring a Common Ground 134Isolated Lines 137

4 ���!��� �������������

Adding a Repeater 141Implementing a Star Topology 141

' ,���� -������� ��#

!�� ����!����� �������*

Using a Carrier Frequency 146Spread Spectrum Technology 147Ensuring Reliable Transfers 147

&�'����������

Transmitters and Receivers 148IrDA 149

/� �����5����������0

Complying with Regulations 149Choosing an RF Band 150Implementing a Link 151Using Other RF Standards 152

) .���� /*012� !��������� ����� �##

3 � ���������������������*

Finding Ports 156Opening a Port 156Timeouts 160Receive Threshold 161Closing a Port 161

#��'��� ���������*"

Transferring Bytes 167Transferring Text 170

Page 8: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

viii

4 ���������1+6�������,*

BinaryReader and BinaryWriter 177StreamReader and StreamWriter 182

� ������������������������*

The Application Settings Architecture 186Combo Box Example 187

�+ �������� ����� �� 1����3��� �� /*01 �')

/��� ���������0.

Setting Timeouts 190Detecting Received Data 190Collecting Received Data 197Ensuring Efficient Transfers 202

���� ���������."

Avoiding Timeouts 203Sending without Blocking the Application 203Preventing Buffer Overflows 207Ensuring Efficient Transfers 208

���%������������.0

Selecting a Method 209Monitoring and Controlling the Signals 209

$��� ���2����������

Exceptions 214The ErrorReceived Event 214Verifying Received Data 218

�������� ��������� �� ��������

Defining a ComPorts Class 218Setting Parameters with Combo Boxes 221Defining Application-specific Events 224

�� ����� 3�� 0�4�� !5����� ��)

��! ����������������� �����������0

About the PIC18F4520 230The Enhanced UART 230

Page 9: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

ix

/�� �������"�

Configuring and Accessing the Port 231Setting the Bit Rate 234Interrupts 237Basic Operations 239

���� ��������������

Configuring the Port 241Sending Data 243Receiving Data 244Using Interrupts 253Using Flow Control 256

��� �����������*�

Multiple On-chip UARTs 263Firmware UARTs 263External UARTs 263

�� *������ ����������� �&(

!�� ���#�'' �����*,

Steps in Exchanging a Message 268Protocols 268Using Existing Protocols 270Debugging Tips 271

����� ������,�

Assigning Addresses 272Detecting Addresses 272Reserving Address Values 273Defining a Message Format 2739-bit Format 274

�� �� !"�'# *������ �'�

������� �������7���������

Transceivers 281Terminating and Biasing 283Cabling 283

28������������������"

Addresses 283Message Format 283

Page 10: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

x

������������

Reading a Byte 284Writing a Byte 286

���� �������7��������,

Configuring the Driver-enable Line 287Sending Commands 288

/����� ��������������0�

Auxiliary Routines 291Decoding Received Data 303

�� ����� .!6 ��(

$�������� �����"�,

Assigning a Driver on the Host 318Requirements 318Host Responsibilities 319Device Responsibilities 319Speed 320Endpoints 320

4���#��'�����"��

Transfer Types 321Transactions 322The Data Toggle 323

�# .���� !������"3������ .!6 ����������� ��#

&� ��������� ����"�*

Serial Interface (FT232R) 326Parallel Interface (FT245R) 328Prototyping Modules 329

4 ��������������������"".

Drivers 330Adding Vendor-specific Data 330Implementing a Virtual COM Port 331Converting from RS-232 to USB 332

Page 11: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

xi

�& .���� ,������ .!6 ����������� ��#

#��������� �� ����� ��������""�

Documentation 336Overview 336Device Controllers 338Host Drivers 338

4 ��������+�������������!�������""0

POTS Models 339Virtual COM Ports 340Requests 341Notifications 344Maximizing Performance 345

���� ��������&7��� �����"�*

Device Descriptor 346Configuration Descriptor 346Communication Class Interface Descriptors 351Data Class Interface Descriptors 353String Descriptors 355The INF File 356Composite Devices 356

���� �&#

Page 12: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

1

������� ��� �����

A serial port is a computer interface that transmits data one bit at a time. Incommon use, the term “serial port” refers to ports that use a particular asyn-chronous protocol. These ports include the RS-232 ports on PCs and manyserial ports in embedded systems. Most serial ports are bidirectional: they canboth send and receive data. Transmitting one bit at a time might seem ineffi-cient but has advantages, including the ability to use inexpensive cables andsmall connectors.

In PCs, applications access most serial ports as COM ports. Applications thatuse Microsoft’s .NET Framework class library can use the SerialPort class toaccess COM ports. Some USB devices function as virtual COM ports, whichapplications can access in the same way as physical serial ports. Some Ethernetand Wi-Fi devices function as serial servers that enable applications to accessserial ports over a network.

Microcontrollers in embedded systems can use serial ports to communicatewith other embedded systems and PCs. Language compilers for microcontrol-lers often provide libraries with functions that simplify serial-port program-ming.

Page 13: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

Chapter 1

2

���� �� ��� � ���� ���

Device developers have many options for computer interfaces. Table 1-1 com-pares popular wired interfaces.

Serial ports are ideal for many communications between embedded systems orbetween embedded systems and PCs. Serial ports can also be a good choicewhen you need very long cables or a basic network among PCs, embedded sys-tems, or a combination. Some systems include a serial port that is hidden fromusers but available to technicians for debugging and diagnostics.

�8�������

These are some advantages of asynchronous serial ports and COM-port pro-gramming:

• Serial ports can exchange just about any type of information. Applicationssuited for serial ports often involve reading sensors, switches, or other inputsor controlling motors, relays, displays, or other outputs.

• The hardware is inexpensive and readily available. PCs that don’t havebuilt-in serial ports can use USB/serial converters. Just about every micro-controller family includes variants with built-in serial ports.

• Other than the Start, Stop, and optional parity bits added to each transmit-ted byte, serial interfaces assume nothing about the content of the databeing transmitted. In contrast, USB and Ethernet use sophisticated proto-cols that define the format of transmitted data. Hardware or firmware mustimplement these protocols, adding complexity that some applications don’tneed.

• Cables can be very long. An RS-232 interface can use cables of 130 ft ormore. An RS-485 cable can be over 4000 ft. In contrast, the maximum dis-tance between a USB device and its host is 16 ft, or 98 ft with five hubs.Ethernet cables have a maximum length of 328 ft.

• The cables are inexpensive. Many links can use unshielded cables with 3–9wires.

• For devices that connect to PCs, Windows and other operating systems pro-vide drivers for accessing COM ports. Programming languages provideclasses, libraries, or other tools for COM-port communications.

Page 14: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

Options and Choices

3

Table 1-1: Comparison of popular computer interfaces. Where a standard doesn’t specify a maximum, the table shows a typical maximum.Interface Format Number of

Devices (maximum)

Distance(maximum, ft)

Speed(maximum, bps)

Typical Use

RS-232 (TIA-232)

asynchronous serial

2 50-100 20k (faster with some hardware)

Modem, basic communications

RS-485 (TIA-485)

asynchronous serial

32 unit loads (up to 256 devices with some hardware)

4000 10M Data acquisition and control systems

Ethernet serial 1024 1600 10G PC network communications

IEEE-1394b (FireWire 800)

serial 64 300 3.2G Video, mass storage

IEEE-488 (GPIB)

parallel 15 60 8M Instrumentation

I2C synchronous serial

40 18 3.4M Microcontroller communications

Microwire synchronous serial

8 10 2M Microcontroller communications

MIDI serial current loop

2 (more with flow-through mode)

50 31.5k Music, show control

Parallel Printer Port

parallel 2 (8 with daisy-chain support)

10–30 8M Printer

SPI synchronous serial

8 10 2.1M Microcontroller communications

USB asynchronous serial

127 16 (up to 98 ft with 5 hubs)

1.5M, 12M, 480M

PC peripherals

Page 15: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

Chapter 1

4

• A USB device accessed as a COM port doesn’t have to have an asynchronousserial interface. The device can have a parallel or other interface as needed tosuit the application.

• Wireless technologies enable transmitting serial data without cables.

%�����

No single interface is ideal for every purpose. Limits to asynchronous serialinterfaces include these:

• The computers at each end must convert between the transmitted serial dataand the CPU’s parallel data bus. The conversion is usually handled automat-ically by hardware, however.

• The specified maximum bit rate for RS-232 is 20 kbps. But many interfacechips can exceed this rate, and RS-485 supports speeds of up to 10 Mbps.Communications between a PC and a USB Virtual COM ports aren’t lim-ited by RS-232’s maximum bit rate.

• Windows doesn’t promise real-time performance for serial communications.Sending or receiving data may need to wait as the operating system attendsto other tasks. But the delays are normally short and are common to otherinterfaces on Windows systems. Embedded systems typically can control thescheduling of serial communications more precisely.

� ���� ����������

Communicating via serial ports requires three things: computers with serialports, a cable or wireless interface that provides a physical link between theports, and programming to manage the communications.

1�� ��������

Just about any computer can use serial-port communications, including inex-pensive microcontrollers and PCs that don’t have built-in serial ports.

����������� ���� ��

Devices with asynchronous serial ports typically contain a hardware componentcalled a Universal Asynchronous Transmitter/Receiver (UART). The UARTconverts between parallel and serial data and handles other low-level details ofserial communications.

Page 16: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

Options and Choices

5

These are some examples of ports controlled by UARTs:

• Microcontroller serial ports. Many microcontrollers contain one or moreUARTs for serial-port communications. When a hardware UART isn’t avail-able, microcontroller firmware can emulate a UART’s functions, typicallywith assistance from an on-chip timer.

• External UART chips that interface to microcontrollers or other CPUs.• The RS-232 serial ports that were standard on PCs and other devices before

USB became common. Each of these ports contains a UART that interfacesto the system’s CPU. Any PC with a free expansion slot can add this type ofport on an expansion card.

• RS-232 ports on PC Cards (also called PCMCIA cards). Any PC with a freePC-Card slot can use these.

• Serial ports that connect to PCs via USB converter modules.• Other serial ports used in long-distance and networking applications, often

in industrial-control applications. These interfaces include RS-485, RS-422,and RS-423. Expansion cards, PC Cards, and USB converters with theseinterfaces are available.

• Ports on serial-server modules that connect to Ethernet or Wi-Fi networks.

On PCs, ports that applications can access as COM ports include these:

• RS-232 ports on older motherboards or on expansion cards.• Ports that connect to a PC via a USB converter that uses a driver that assigns

a COM port to the device. Converters are available as modules and as chipsfor incorporating into circuits. A converter can convert between USB andRS-232, RS-485, TTL serial, or even a parallel interface.

• Internal modems that interface to phone lines.• Serial ports on network serial-server modules.

For USB virtual COM-port devices, Windows includes a driver for USB’s com-munication devices class (CDC). For improved performance, some convertersuse vendor-specific drivers in place of the provided Windows drivers.

������ �����

Computers that communicate via serial ports don’t have to be all the same type.Tiny microcontrollers can talk to the latest PCs as long as both ends of the linkuse compatible interfaces and protocols. The PC examples in this book are forthe family of computers that has evolved from the IBM PC, including desktop

Page 17: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

Chapter 1

6

and notebook PCs. Other computer types also have serial ports that are built inor available via converters or expansion cards.

An embedded system is a computer-controlled device dedicated to performinga single task or a set of related tasks. Embedded systems are typically built into,or embedded in, the devices they control. For example, a modem is an embed-ded system that handles tasks of data communications over the phone system.Some embedded systems are one-of-a-kind or small-quantity projects. Manyinvolve monitoring or control tasks.

Embedded systems often use microcontrollers, which contain a CPU and I/Ohardware such as UARTs. Microcontroller chips can be classified by data-buswidth: 8-bit chips have an 8-bit data path and are popular in monitoring andcontrol applications. Chips with 4-, 16-, and 32-, and 64-bit data buses are alsoavailable. Different chips have different combinations of features and abilities,including asynchronous and synchronous serial ports, USB controllers, typeand amount of memory for storing programs and data, and support forpower-saving modes.

1�� ��5����� %���

The physical link between computers consists of the wires or other mediumthat carries information from one computer to another and the connectors andother components that interface the medium to the computers.

RS-232 links can use just about any cable type and require one line per signalplus a common ground line. RS-485 networks typically use twisted-pair cableswith a pair for each differential signal. Other options for serial communicationsinclude fiber-optic cable, which encodes data as the presence or absence oflight, and wireless technologies, which enable sending data as electromagnetic(radio) or infrared signals through the air.

Computers connected by wires must have a common ground reference, typi-cally provided by a ground wire in the cable.

�����������

A computer must perform the following tasks in serial communications:

• Detect and process received data.• Provide and send data as needed.• Carry out any other tasks the computer is responsible for.

Page 18: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

Options and Choices

7

If the connection is to a serial network, each computer must ignore communi-cations intended for other computers in the network and comply with networkprotocols for addressing transmitted data to the appropriate computer(s).

Program code carries out these tasks, often with help from hardware.

���������

The programming for a serial interface can use any language, and the languagedoesn’t have to be the same on every computer. The only requirement is that allof the computers must agree on a format. Microcontroller programs mightaccess UART registers directly or use library functions or other higher-levelmethods to set communications parameters and exchange data. PC applicationstypically use higher-level functions to access ports.

� ����

A protocol is a set of rules that defines how computers manage communica-tions. Serial communications must implement a low-level communication pro-tocol and may also implement a higher-level message protocol.

������������������ �

A communication protocol defines how the bits travel, including when a com-puter can transmit, the bit rate, and in what order the bits transmit. The UARTtypically handles the details of sending individual bits and storing received bitson the serial port.

Two computers that want to exchange data must agree on whether both endscan transmit at once or whether the computers need to take turns. Most wiredlinks between two computers are full duplex: both computers can transmit atthe same time. Many wireless links are half duplex: the computers must taketurns. A simplex link is one way only. A network with three or more computerssharing a data path must use a protocol that defines when a computer can trans-mit.

A communication protocol can include the use of status and control lines.These lines can indicate when a transmitter has data to send or when a receiveris able to accept new data. The process of exchanging this information is calledflow control. Hardware flow control uses dedicated lines for the signals. Devicescan also use software flow control to provide the same information by sendingdefined codes, typically in the same path used for data.

Page 19: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

Chapter 1

8

Additional status and control lines can provide other information such as thepresence of a carrier frequency or a ring signal on a phone line. In serial net-works where only one transmitter can be enabled at a time, a transmit-enableline at each computer can enable and disable the transmitters as needed.

������������� �

Serial communications often exchange messages that consist of blocks of datawith defined formats. A message protocol can specify what type of data a mes-sage contains and how information is structured within the message.

The computers in a network need a way to detect which computer is theintended receiver of transmitted data. Networks typically assign an address toeach computer and include the receiver’s address in each message. For example,a very basic message might consist of two bytes: one byte to identify the receiverand one byte containing data.

To enable a receiving computer to detect the start and end of a message, a mes-sage can include codes to indicate these events or a header that stores the mes-sage length. A message can also include one or more bytes that the receivingcomputer uses in error checking.

����������

One way to think about serial applications is by the primary direction of dataflow. In a link between two computers, one computer might gather data fromor send commands to the other computer. Or two computers may each beresponsible for various monitoring and control functions, sharing informationwith each other.

In some systems all computers send and receive more or less equally. In others,most of the data flows to or from a central computer. For example, most of theactivity in a network might involve one computer that collects data from com-puters in remote locations.

0������ !5�����

An everyday example of a system that collects data is a weather-watching net-work. A desktop PC might serve as a primary computer that controls the activ-ities of one or more secondary computers, which can be embedded systems orPCs. The primary computer sends commands to the secondary computers totell them how often to collect data, what data to send, and when to send. Thedata collected might include temperature, air pressure, rainfall, and so on. At

Page 20: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

Options and Choices

9

intervals, each secondary computer sends its collected data to the primary com-puter, which stores the data and makes it available for viewing and processing.This basic setup is adaptable to many other types of data-gathering systems.

Other systems are mainly concerned with controlling external devices, ratherthan gathering data from them. A store-window display might include a set ofsmall robots, each with switches and signals that control motors, lights, andother mechanical or electrical devices. Each robot is an embedded system, and aprimary computer controls the show by sending commands to the robots. Therobots can also return information about their current states, but the main jobof this type of system is to control devices, rather than to collect informationfrom them.

An example of a system involved with both monitoring and controlling is ahome-control system that monitors temperature, humidity, motion, switchstates, and other conditions throughout a house. Other circuits control thehome’s heating, cooling, lighting, audio and video systems, and alarms. Whenthe data (or a lack of data) indicates a problem, the system generates an alarm.

�������� �������������

In each of the examples above, one computer typically acts as a primary com-puter that controls a series of secondary computers. A secondary computertransmits only after the primary computer contacts it and gives it permission.

Some networks have no primary computer. Instead, each computer has equalstatus with the others, and each can request actions from the others. For exam-ple, each computer might transmit in a defined sequence. Or on receiving amessage, a computer might have permission to select any other computer totransmit to.

!������"������ �����

Many common peripheral functions are available as modules with serial inter-faces. These modules make it easy to add a function to a design. For example,LCD modules with serial interfaces are available from Scott Edwards Electron-ics (www.seetron.com). The USBwiz from GHI Electronics (www.ghielectron-ics.com) contains a USB host controller and makes it possible to access USBdevices via an asynchronous serial port. Motor controllers with serial interfacesare also available from a variety of sources.

Page 21: Serial Port Complete - DedicatedTeacher.com€¦Serial Port Complete COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems Second Edition Jan Axelson Lakeview Research LLC

Chapter 1

10

These are just a few examples. This book will guide you in choosing compo-nents and writing programs for whatever serial-port application you have inmind.