The Secrets of Flow Control in Serial Communication



Similar documents
The Secrets of RS-485 Half-duplex Communication

NPort. Copyright 2008 Moxa Inc. Released on July 15, 2008

NPort s Ethernet Modem Mode

Using KEPServerEX OPC Server (Kepware)with the iologik E2210

How to use KEPServerEX OPC Server (Kepware) with iologik 4000 (Modbus TCP/IP NA-4010 and Modbus Serial NA-4020/NA-4021)

How to use Citect (SCADA) with iologik 4000 (Modbus TCP/IP NA-4010 and Modbus Serial NA-4020/NA-4021)

WHQL Certification Approval...2 User Interface...3 SUNIX s COMLab..4

ELAN DIGITAL SYSTEMS LTD. SL232 PC- CARD USER S GUIDE

RJ45 Shielded (standard) port pinout. CS9000, Jetstream , Lanstream 2000, RTA8/RJX, RRC16, MTA8/RJX & SXDC8/RJX

LINDY ELECTRONICS LIMITED & LINDY-ELEKTRONIK GMBH - SECOND EDITION

ALL-USB-RS422/485. User Manual. USB to Serial Converter RS422/485. ALLNET GmbH Computersysteme Alle Rechte vorbehalten

Manual Serial PCI Cards

The Shift to Wireless Data Communication

RS-422/485 Multiport Serial PCI Card. RS-422/485 Multiport Serial PCI Card Installation Guide

EtherNet/IP Scanner Configuration for the Moxa MGate 5105-MB-EIP

USB to RS-422/485 Serial Adapter

Objectives. Basics of Serial Communication. Simplex vs Duplex. CMPE328 Microprocessors (Spring ) Serial Interfacing. By Dr.

BIT COMMANDER. Serial RS232 / RS485 to Ethernet Converter

When we look at the connector pinout of the RS232 port, we see two pins which are certainly used

Using HyperTerminal with Agilent General Purpose Instruments

PCMCIA 1 Port RS EDITION OCTOBER 1999

How to setup a serial Bluetooth adapter Master Guide

Eliminate Risk of Contention and Data Corruption in RS-485 Communications

Cable Specifications and Information

Remote Serial over IP Introduction on serial connections via IP/Ethernet

LS-101 LAN to Serial Device server. User s Manual

2-Port RS232/422/485 Combo Serial PCI Card

WHQL Certification Approval...2 User Interface K software FIFO 4 Universal PCI Interface...5 Ready for 64-bit System...5

RS-232 Communications Using BobCAD-CAM. RS-232 Introduction

Advanced Data Capture and Control Systems

Configuring IP to Serial with Auto Answer and Serial to IP

PFB366 Profibus-DP Gateway User Manual

RS232C < - > RS485 CONVERTER S MANUAL. Model: LD15U. Phone: / 97 / 98 (M)

Encore Controller to Router Connections

Introduction. Features. Industrial 2 ports RS-422/485 with Surge PCI-Express Low Profile Serial Card

Moxa TCC-100/100I User s Guide

Industrial Multi-port Serial Cards

TTL-232R-3V3 USB to TTL Serial Converter Cable

RS-232 COMMUNICATIONS

2-port RS-232 High Speed Low Profile Universal PCI Serial Board

How To Use A Sunix Ser5037A Card On A Pc Or Mac Or Mac With A Microsoft Powerbook (Powerbook) With A Powercard (Powercard) And Powercard With A Mini Usb (Powerboard) With An

VSCOM USB PRO Series Industrial I/O Adapters

Real-time Video Monitoring Increases the Efficiency of SCADA Process Management

TRP-C31M MODBUS TCP to RTU/ASCII Gateway

BLUETOOTH SERIAL PORT PROFILE. iwrap APPLICATION NOTE

Future Technology Devices International Ltd

Quectel Cellular Engine

Using Xbee in Serial Communication

2-port RS-422 / 485 Universal PCI

Operation Manual of EX-9132C-2. Serial to TCP/IP Converter

Why you need to monitor serial communication?

SC16C652B. 1. General description. 2. Features. 5 V, 3.3 V and 2.5 V dual UART, 5 Mbit/s (max.) with 32-byte FIFOs and infrared (IrDA) encoder/decoder

LTM-1338B. Plus Communications Manual

XPort Universal Demo Board User Guide

PCI 2 Port Fast Serial Communication Adapter Card User Manual

Smartio C168H/PCI User s Manual

Serial Over IP Ethernet Device Server

NPort 6110 Modbus/TCP to Serial Communication Gateway

isco Connecting Routers Back to Back Through the AUX P

Omron I/O Driver (Series 2) Programmable Serial Interface Card

TCP/IP MODULE CA-ETHR-A INSTALLATION MANUAL

Cabling Guide for Console and AUX Ports

1-Port R422/485 Serial PCIe Card

USB TO SERIAL ADAPTER

MODBUS TCP to RTU/ASCII Gateway

How to setup a serial Bluetooth adapter

Cable Guide. Click on the subject to view the information. Digi Cables Building Cables General Cable Information

How to design and implement firmware for embedded systems

SPI I2C LIN Ethernet. u Today: Wired embedded networks. u Next lecture: CAN bus u Then: wireless embedded network

1 Application Description System Topology Hardware and Software Requirements... 3

1.1 Connection Direct COM port connection. 1. Half duplex RS232 spy cable without handshaking

Future Technology Devices International Ltd. USB to RS232 UART Serial Converter PCB. Datasheet

The Answer to the 14 Most Frequently Asked Modbus Questions

USB-to-Serial RS-232 Hub USB-to-Serial RS-422/485 Hub USER MANUAL UC2322 / UC2324 / UC4852 / UC4854

Concept XXMIT / RTXMIT Transmit (Receive) Function Block

Configuring Allen-Brandly ControlLogix PLC with Moxa MGate 5105-MB-EIP. 1 Application Description Objective Goals...

User s Manual TCP/IP TO RS-232/422/485 CONVERTER. 1.1 Introduction. 1.2 Main features. Dynamic DNS

SUDT AccessPort TM Advanced Terminal / Monitor / Debugger Version 1.37 User Manual

Redundant Serial-to-Ethernet Data Connections for Mission-critical Devices

Application Note 83 Fundamentals of RS 232 Serial Communications

UART IP Core Specification. Author: Jacob Gorban

DSX Master Communications

16-Port RS232 to USB2.0 High Speed Multi Serial Adapter (w/ Metal Case) Installation Guide

EZ-View Network Communications Guide

Single channel data transceiver module WIZ2-434

Docklight Pro Monitor User Manual 10/2015

21152 PCI-to-PCI Bridge

Redundant Gigabit Backbone Adds Speed and Reliability to Industrial Networks

Cable Pinouts. SRP I/O Module

Fast Ethernet and Gigabit Ethernet. Networks: Fast Ethernet 1

USB to Serial Quick Installation Guide

Computer Systems Structure Input/Output

1 Software Overview ncp-uart ash-v3-test-app ash-v3-test-app Command Line Options Testing... 2

Serial ATA technology

MGate-4101-MB-PBS Modbus Serial-to-PROFIBUS Slave Gateway User s Manual

Elettronica dei Sistemi Digitali Costantino Giaconia SERIAL I/O COMMON PROTOCOLS

SC16IS740/750/760. Single UART with I 2 C-bus/SPI interface, 64 bytes of transmit and receive FIFOs, IrDA SIR built-in support

Serial Communications

Transcription:

in Serial Communication Casper Yang, Senior Product Manager support@moxa.com Although RS-232/422/485 serial communication is no longer considered to be high speed, flow control is still an important function for many applications. Most people know what flow control is, but do not know how it works or how it influences the behavior of a communications system. In this paper, we describe flow control in detail, and give you the knowhow needed to fix certain types of communication problems. High/Low Water Level Whenever a buffer is used to store data as it is being transmitted, some type of flow control is required to prevent data overrun. Flow control is used in UART FIFOs, drivers, and OS kernels. To implement flow control, the engineer needs to configure both the receive buffer high water level (RBH) and receive buffer low water level (RBL). RBH prevents the receive buffer from overrunning by telling the transmitting side to stop sending data before the Rx buffer is full. For example, if the receive buffer can store 4 KB of data, then you might want to set the RBH value to 3 KB since data will continue to be sent until the transmitting side receives the stop command. That is, incoming data will continue to arrive for a little while even after you say stop. RBL, on the other hand, defines when data transmission should be resumed. When in doubt, just set RBL to zero, since doing so will ensure that the buffer is completely empty before transmission resumes. However, setting RBL to zero is not very efficient since it could introduce an undesirably large time lag. Copyright 2009 Moxa Inc. Released on Sep 30, 2009 About Moxa Moxa manufactures one of the world s leading brands of device networking solutions. Products include serial boards, USB-to-serial hubs, media converters, device servers, embedded computers, Ethernet I/O servers, terminal servers, Modbus gateways, industrial switches, and Ethernet-to-fiber converters. Our products are key components of many networking applications, including industrial automation, manufacturing, POS, and medical treatment facilities. How to Contact Moxa Tel: 1-714-528-6777 Fax: 1-714-528-6778 Web: www.moxa.com Email: info@moxa.com This document was produced by the Moxa Technical Writing Center (TWC). Please send your comments or suggestions about this or other Moxa documents to twc@moxa.com.

Data RBH RBH Stop sending! Data Length is higher than the RBH. Turn RTS off or send XOFF. Fig. 1: How the Receive Buffer s RBH Value Controls Data Transmission Data RBL RBL Go! Data Length is less than the RBL. Turn RTS on or send XON. Fig. 2: How the Receive Buffer s RBL Value Controls Data Transmission RTS/CTS vs. XON/XOFF Flow Control In serial communication, there are two types of flow control hardware flow control and software flow control. Hardware flow control uses the RTS/CTS (or DTR/DSR) signals to communicate. When connecting a serial device to a computer, connect the CTS pins to the RTS pins (for DTR/DSR flow control, DSR connects to DTR). The transmitting side checks the state of its CTS pin before transmitting, and then Copyright 2009 Moxa Inc. Page 2 of 6

starts transmitting if it sees CTS On, and does not transmit (or stops transmitting) if it sees CTS Off. On the other hand, the receiving side uses RTS to say go or stop. Turning RTS from off to on indicates that the amount of data in the Rx buffer is lower than the RBL, and turning it from on to off means the length is higher than the RBH. RTS RTS CTS CTS Fig. 3: RTS/CTS Flow Control Cable Wiring Software flow control uses the Tx and Rx signals to send XOFF and XON control characters. The receiving side sends an XOFF character over its Tx line (which is equivalent to turning RTS from on to off) to tell the transmitting side to stop transmitting, and sends an XON character over its Tx line (which is equivalent to turning RTS from off to on) to tell the transmitting side to resume transmitting. Most serial devices use 0x11 for XON and 0x13 for XOFF by default, although in most cases the values can be set to other values. If your data includes either of the XON/XOFF characters, which could be true for binary execution files, you will need to use other characters instead. Serial communication requires connecting at least the Tx, Rx, and GND pins, but when using hardware flow control, you also need to connect the RTS and CTS pins. Although this will increase the cost of the cable, hardware flow control is more reliable. If cost is an issue you can use software flow control, provided your data does not conflict with the XON/XOFF characters. You should also keep in mind that the serial driver needs to check each byte of data one by one for the XON/XOFF characters. Because of the problems associated with software flow control, many advanced UARTs support on-chip software flow control. RS-422/485 Considerations RS-422/485 uses differential signal paths, which increases the maximum transmission distance, but also requires more cabling than RS-232. For this reason, most RS-422/485 connections only provide Tx and Rx signals and do not provide Copyright 2009 Moxa Inc. Page 3 of 6

RTS/CTS or DTR/DSR signals. In this case, using XON/XOFF flow control is a necessity. Note, however, that 2-wire RS-485 data transmission is a bit different since it uses half-duplex transmission. Since data can only be transmitted in one direction at a time, flow control is not needed. If you are using 4-wire RS-422/485 communication and you want to use RTS/CTS flow control, make sure that both the host and serial device support this function. In fact, most serial solutions (including PCI boards and devices) do not support the RTS/CTS pins when using 4-wire RS-422/485. XON/XOFF Needs More Latency Before discussing on-chip flow control, let s look at how a driver implements the flow control function. Hardware flow control uses the CTS and RTS signals. The driver checks the signal on its CTS pin before transmitting, and set its RTS signal to ON when it s ready to receive. Adjusting the RTS signal and reading the CTS state is very easy and fast, and if cost is not an issue, then using hardware flow control will ensure greater reliability. For software flow control, the driver needs to check each incoming byte of data to see if an XON or XOFF character has been received. Doing this wastes time and is not reliable since before the XOFF character is received the driver may still need to read out data from the UART. This latency will cause the driver to send more data and may cause a data overrun on the receiving side. Data Data XOFF Data Data Fig. 4: Including XOFF in the data stream could result in too much of a delay. On-chip Flow Control Lets You Stop Transmitting in Time Many advanced UARTs have incorporated on-chip flow control to circumvent the complexities inherent in flow control schemes. On-chip means that the UART processes the RTS/CTS signals and XON/XOFF characters automatically. To prevent overrun in the UART FIFO, the UART uses an internal RBH and RBL. When the RBH is reached it drops the RTS or sends an XOFF character immediately. It also stops transmitting immediately when the CTS is low or an XOFF character is received. For slower devices this function can be very useful. This is because slower devices Copyright 2009 Moxa Inc. Page 4 of 6

generally have a smaller buffer, and consequently it is essential to stop transmitting in time when an XOFF character is received. Even if a UART supports on-chip flow control, using a poorly designed driver could cause data loss. This is because even though the UART might have enough space for additional data, the driver may not. Knowing how to prevent driver buffer overrun and designing the driver to work well with UART on-chip flow control is very important, and depends to a large extent on the experience the vendor has with developing drivers. To enable flow control, you need to check both software and hardware settings. For software flow control, Windows and UNIX/Linux provide standard interfaces. For more information, please check the Win32/UNIX/Linux programming guide. For hardware flow control, make sure the RTS/CTS or DTR/DSR pins are connected correctly. If you don t need to use flow control, make sure the setting is off. If flow control is enabled without an RTS/CTS cable connection, data cannot be sent out because the CTS state is low. Solution for UART without On-chip Flow Control On-chip flow control is extremely important for applications that cannot tolerate data loss or buffer overruns. If you have any doubts about your serial device, check with your vendor to see if the device supports on-chip hardware or on-chip software flow control. If not, disabling the device s FIFO could be more reliable. This is because the driver will only send one byte for each interrupt issued, and give the receiving side more time to process the data. For XON/XOFF flow control, disabling the FIFO will result in better latency, and provide enough time to process the XOFF character and prevent overruns. Conclusion Many advanced UARTs support on-chip flow control with high/low water settings in the transmit/receive FIFO. To prevent overrun and get good throughput, choose a UART with on-chip flow control and set the high/low water level properly. In most cases, you can set the high water level to 3/4 the buffer length and set the low water level to 1/4 the buffer length. The next time you experience an overrun or data loss, check the flow control settings first. Copyright 2009 Moxa Inc. Page 5 of 6

Question 1 What should I do if I have enabled flow control but still get an overrun or experience data loss? Answer Check both sides of the connection and enable flow control properly. Check to make sure that RTS connects to CTS (and vice versa) if your are using RTS/CTS flow control. If you are using XON/XOFF flow control without on-chip support, try disabling the FIFO. Try using UARTs with on-chip flow control on both sides of the connection, and make sure the driver you re using supports this function. If you are using UARTs that support on-chip flow control on both sides of the connection, then the problem is probably caused by the driver. 2 Does my UART support on-chip flow control? Most motherboards provide 1 or 2 UARTs, but they are 16550A and do not support this function. Some advanced UARTs, such as Moxa s MU860 or 16950, support both RTS/CTS and XON/XOFF flow control, but most UARTs, such as the 16550C, only support RTS/CTS. Read your product s datasheet or check with your vendor for details. Copyright 2009 Moxa Inc. Page 6 of 6