Texas Instruments | AN-739 RS-232C Interface with COP800 | Application notes | Texas Instruments AN-739 RS-232C Interface with COP800 Application notes

Texas Instruments AN-739 RS-232C Interface with COP800 Application notes
COP820CJ,COP840CJ,COP880C,COP884BC,
COP888CF,COP888CL,COP888EK,COP888FH,
COP888GW,COP8ACC5,COP8AME9,COP8CBE9,
COP8CBR9,COP8CCE9,COP8CCR9,COP8CDR9,
COP8SAA7,COP8SAC7,COP8SBR9,COP8SCR9,
COP8SDR9,COP8SGE5,COP8SGE7,COP8SGG5,
COP8SGH5,COP8SGK5,COP8SGR5,COP8SGR7,
COP912C,DS3658
AN-739 RS-232C Interface with COP800
Literature Number: SNLA021
National Semiconductor
Application Note 739
Michelle Giles
May 1991
INTRODUCTION
This application note describes an implementation of the
RS-232C interface with a COP888CG. The COP888CG 8-bit
microcontroller features three 16-bit timer/counters,
MICROWIRE/PLUSTM Serial I/O, multi-source vectored interrupt capability, two comparators, a full duplex UART, and
two power saving modes (HALT and IDLE). The COP888CG
feature set allows for efficient handling of RS-232C hardware handshaking and serial data transmission/reception.
The terminal is setup to interface with the COP888CG by
selecting the 9600 baud, 7 bits/character, odd parity and
one stop bit options. The local echo back of characters is
disabled to allow the COP888CG to perform the echo back
function. The terminal is also configured to use the hardware control signals (CTS, DSR, RTS, DTR) for handshaking.
SYSTEM OVERVIEW
In this application, a COP888CG is connected to a terminal
using the standard RS-232C interface. The serial port of the
terminal is attached to the COP888CG interface hardware
using a standard ribbon cable with DB-25 connectors on
either end. The terminal keyboard transmits ASCII characters via the cable to the COP888CG interface. All characters
received by the COP888CG are echoed back to the terminal
screen. If the COP888CG detects a parity or framing error, it
transmits an error message back to the terminal screen.
HARDWARE DESCRIPTION
The COP888CG features used in this application include the
user programmable UART, the 8-bit configurable L PORT,
and vectored interrupts. In addition to the COP888CG, the
RS-232C interface requires a DS14C88 driver and a
DS14C89A receiver. The DS14C88 converts TTL/CMOS
level signals to RS-232C defined levels and the DS14C89A
does the opposite. Figure 1 contains a diagram of the
COP888CG interface hardware.
The COP888CG is configured as data communications
equipment (DCE) and the terminal is assumed to be data
terminal equipment (DTE). The following RS-232C signals
are used to communicate between the COP888CG (DCE)
and the terminal (DTE):
RS-232C Signal Name
Signal Origin
TxD (Transmit Data)
RxD (Receive Data)
CTS (Clear To Send)
RTS (Request To Send)
DSR (Data Set Ready)
DTR (Data Terminal Ready)
DCD (Data Carrier Detect)
DTE
DCE
DCE
DTE
DCE
DTE
DCE
MICROWIRE/PLUSTM is a trademark of National Semiconductor Corporation.
C1995 National Semiconductor Corporation
TL/DD11110
RRD-B30M75/Printed in U. S. A.
AN-739
Five general purpose I/O pins on the COP888CG L PORT
are used for the control signals CTS, DSR, DCD, RTS and
DTR. Two additional L PORT pins are used for TxD and
RxD. These two general purpose pins are configured for
their alternate functions, UART transmit (TDX) and UART
receive (RDX). According to the RS-232C interface standard, DCE transmits data to DTE on RxD and receives data
from DTE on TxD. Therefore, the UART transmit data pin
(TDX) is used for the RS-232C receive data signal (RxD)
and the UART receive data pin (RDX) is used for the RS232C transmit data signal (TxD). In this example, all handshaking between DCE and DTE is performed in hardware.
SOFTWARE DESCRIPTION
The software for this application consists of an initialization
routine, several interrupt routines, and a disable routine.
These routines handle RS-232C handshaking, transmitting
and receiving of characters, error checking, and echoing
back of received characters. Figures 2 thru 5 contain flowcharts of the routines. The complete code is given at the
end of this application note.
The initialization routine configures the UART, initializes the
transmit/receive data buffer, and enables the 8-bit L PORT
handling of RS-232C control signals. In this particular example, the UART is configured to operate at 9600 BAUD in full
duplex, asynchronous mode. The framing format is chosen
to be: 7 bits/character, odd parity, and one stop bit. Different baud rates, modes of operation, and framing formats
may be selected by setting the ENUCMD, ENUICMD,
BAUDVAL and PSRVAL constants located at the beginning
of the code to alternative values. (Refer to the COP888CG
data sheet or COP888 Family User’s Manual for details on
configuring the UART.) Each RS-232C control signal is assigned to an L PORT pin. Pins L0, L2, L5 and L6 are configured as outputs for the DCD, TxD, CTS and DSR signals,
respectively. Pins L3, L4 and L7 are configured as inputs for
TxD, RTS and DTR, respectively. The transmit/receive data
buffer is a circular buffer whose location and size is selected
by setting the START and END constants located at the
beginning of the program. The initialization routine sets up
the buffer based on these constants.
The interrupt routines respond to transmit buffer empty, receive buffer full, and L PORT interrupts. A generic context
switching routine is used for entering and exiting all interrupts. This routine saves the contents of the accumulator,
the PSW register and the B pointer before vectoring to the
appropriate interrupt routine. It also restores the contents of
saved registers before a return from interrupt is executed.
The UART transmitter interrupt is called when the transmit
buffer empty flag (TBMT) is set. This routine checks for active RTS and DTR control signals. If both signals are active
and there is data to be transmitted, a byte of data is loaded
into the UART transmit buffer. Otherwise, the UART transmitter is disabled.
The L PORT interrupts are used to indicate an active-low
transition of RTS and/or DTR. When both signals are active
(the remote receiver is ready to accept data), this routine
enables the UART transmitter.
The UART receiver interrupt routine is called when the receive buffer full flag (RBFL) is set. This routine reads the
RS-232C Interface with COP800
RS-232C Interface with
COP800
UART receive buffer and checks for errors. If no errors are
detected, the incoming data is placed in the data buffer for
echoing. If errors are detected, an error message is queued
for transmission.
CONCLUSION
The user configurable UART, multiple external interrupt capabilities, and vectored interrupt scheme of the COP888CG
microcontroller allow for an efficient implementation of the
RS-232C interface standard. This application note shows
how the COP888CG may be configured for connection to a
terminal using these features. However, the code for this
application can be easily adapted to other applications requiring different baud rates or framing formats, connection
to a modem (DCE), separate transmit and receive buffers,
incoming command decoding and/or handling of character
strings. The versatility of the RS-232C standard and the
COP888CG provides a means to develop practical solutions
for many applications.
The receiver interrupt disables the remote transmitter by deactivating CTS whenever the transmit/receive data buffer is
almost full. This action prevents the data buffer from overflowing. Note that CTS is turned off before the buffer is completely full to insure buffer space will exist for storing characters which are in the process of being sent when CTS is
deactivated.
The disable routine clears the UART control registers, disables the L PORT interrupts, and de-activates the RS-232C
control signals.
TL/DD/11110 – 1
FIGURE 1. Interface Diagram
2
TL/DD/11110 – 2
FIGURE 2. Main Program Flow
3
TL/DD/11110 – 3
FIGURE 3. Receiver Interrupt Routine
4
TL/DD/11110 – 4
FIGURE 4. Transmitter Interrupt Routine
5
TL/DD/11110 – 5
FIGURE 5. L Port Interrupt Routine
6
TL/DD/11110 – 6
7
TL/DD/11110 – 7
8
TL/DD/11110 – 8
9
TL/DD/11110 – 9
10
TL/DD/11110 – 10
11
RS-232C Interface with COP800
TL/DD/11110 – 11
TL/DD/11110 – 12
LIFE SUPPORT POLICY
NATIONAL’S PRODUCTS ARE NOT AUTHORIZED FOR USE AS CRITICAL COMPONENTS IN LIFE SUPPORT
DEVICES OR SYSTEMS WITHOUT THE EXPRESS WRITTEN APPROVAL OF THE PRESIDENT OF NATIONAL
SEMICONDUCTOR CORPORATION. As used herein:
AN-739
1. Life support devices or systems are devices or
systems which, (a) are intended for surgical implant
into the body, or (b) support or sustain life, and whose
failure to perform, when properly used in accordance
with instructions for use provided in the labeling, can
be reasonably expected to result in a significant injury
to the user.
National Semiconductor
Corporation
2900 Semiconductor Drive
P.O. Box 58090
Santa Clara, CA 95052-8090
Tel: 1(800) 272-9959
TWX: (910) 339-9240
National Semiconductor
GmbH
Livry-Gargan-Str. 10
D-82256 F4urstenfeldbruck
Germany
Tel: (81-41) 35-0
Telex: 527649
Fax: (81-41) 35-1
National Semiconductor
Japan Ltd.
Sumitomo Chemical
Engineering Center
Bldg. 7F
1-7-1, Nakase, Mihama-Ku
Chiba-City,
Ciba Prefecture 261
Tel: (043) 299-2300
Fax: (043) 299-2500
2. A critical component is any component of a life
support device or system whose failure to perform can
be reasonably expected to cause the failure of the life
support device or system, or to affect its safety or
effectiveness.
National Semiconductor
Hong Kong Ltd.
13th Floor, Straight Block,
Ocean Centre, 5 Canton Rd.
Tsimshatsui, Kowloon
Hong Kong
Tel: (852) 2737-1600
Fax: (852) 2736-9960
National Semiconductores
Do Brazil Ltda.
Rue Deputado Lacorda Franco
120-3A
Sao Paulo-SP
Brazil 05418-000
Tel: (55-11) 212-5066
Telex: 391-1131931 NSBR BR
Fax: (55-11) 212-1181
National Semiconductor
(Australia) Pty, Ltd.
Building 16
Business Park Drive
Monash Business Park
Nottinghill, Melbourne
Victoria 3168 Australia
Tel: (3) 558-9999
Fax: (3) 558-9998
National does not assume any responsibility for use of any circuitry described, no circuit patent licenses are implied and National reserves the right at any time without notice to change said circuitry and specifications.
IMPORTANT NOTICE
Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications, enhancements, improvements,
and other changes to its products and services at any time and to discontinue any product or service without notice. Customers should
obtain the latest relevant information before placing orders and should verify that such information is current and complete. All products are
sold subject to TI’s terms and conditions of sale supplied at the time of order acknowledgment.
TI warrants performance of its hardware products to the specifications applicable at the time of sale in accordance with TI’s standard
warranty. Testing and other quality control techniques are used to the extent TI deems necessary to support this warranty. Except where
mandated by government requirements, testing of all parameters of each product is not necessarily performed.
TI assumes no liability for applications assistance or customer product design. Customers are responsible for their products and
applications using TI components. To minimize the risks associated with customer products and applications, customers should provide
adequate design and operating safeguards.
TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right, copyright, mask work right,
or other TI intellectual property right relating to any combination, machine, or process in which TI products or services are used. Information
published by TI regarding third-party products or services does not constitute a license from TI to use such products or services or a
warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual
property of the third party, or a license from TI under the patents or other intellectual property of TI.
Reproduction of TI information in TI data books or data sheets is permissible only if reproduction is without alteration and is accompanied
by all associated warranties, conditions, limitations, and notices. Reproduction of this information with alteration is an unfair and deceptive
business practice. TI is not responsible or liable for such altered documentation. Information of third parties may be subject to additional
restrictions.
Resale of TI products or services with statements different from or beyond the parameters stated by TI for that product or service voids all
express and any implied warranties for the associated TI product or service and is an unfair and deceptive business practice. TI is not
responsible or liable for any such statements.
TI products are not authorized for use in safety-critical applications (such as life support) where a failure of the TI product would reasonably
be expected to cause severe personal injury or death, unless officers of the parties have executed an agreement specifically governing
such use. Buyers represent that they have all necessary expertise in the safety and regulatory ramifications of their applications, and
acknowledge and agree that they are solely responsible for all legal, regulatory and safety-related requirements concerning their products
and any use of TI products in such safety-critical applications, notwithstanding any applications-related information or support that may be
provided by TI. Further, Buyers must fully indemnify TI and its representatives against any damages arising out of the use of TI products in
such safety-critical applications.
TI products are neither designed nor intended for use in military/aerospace applications or environments unless the TI products are
specifically designated by TI as military-grade or "enhanced plastic." Only products designated by TI as military-grade meet military
specifications. Buyers acknowledge and agree that any such use of TI products which TI has not designated as military-grade is solely at
the Buyer's risk, and that they are solely responsible for compliance with all legal and regulatory requirements in connection with such use.
TI products are neither designed nor intended for use in automotive applications or environments unless the specific TI products are
designated by TI as compliant with ISO/TS 16949 requirements. Buyers acknowledge and agree that, if they use any non-designated
products in automotive applications, TI will not be responsible for any failure to meet such requirements.
Following are URLs where you can obtain information on other Texas Instruments products and application solutions:
Products
Applications
Audio
www.ti.com/audio
Communications and Telecom www.ti.com/communications
Amplifiers
amplifier.ti.com
Computers and Peripherals
www.ti.com/computers
Data Converters
dataconverter.ti.com
Consumer Electronics
www.ti.com/consumer-apps
DLP® Products
www.dlp.com
Energy and Lighting
www.ti.com/energy
DSP
dsp.ti.com
Industrial
www.ti.com/industrial
Clocks and Timers
www.ti.com/clocks
Medical
www.ti.com/medical
Interface
interface.ti.com
Security
www.ti.com/security
Logic
logic.ti.com
Space, Avionics and Defense
www.ti.com/space-avionics-defense
Power Mgmt
power.ti.com
Transportation and Automotive www.ti.com/automotive
Microcontrollers
microcontroller.ti.com
Video and Imaging
RFID
www.ti-rfid.com
OMAP Mobile Processors
www.ti.com/omap
Wireless Connectivity
www.ti.com/wirelessconnectivity
TI E2E Community Home Page
www.ti.com/video
e2e.ti.com
Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright © 2011, Texas Instruments Incorporated
Was this manual useful for you? yes no
Thank you for your participation!

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

Download PDF

advertising