The Secrets of RS-485 Half-duplex Communication



Similar documents
The Secrets of Flow Control in Serial Communication

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

Using KEPServerEX OPC Server (Kepware)with the iologik E2210

NPort s Ethernet Modem Mode

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)

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

The Shift to Wireless Data Communication

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

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

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

The Answer to the 14 Most Frequently Asked Modbus Questions

EZ-View Network Communications Guide

LINDY ELECTRONICS LIMITED & LINDY-ELEKTRONIK GMBH - SECOND EDITION

The I2C Bus. NXP Semiconductors: UM10204 I2C-bus specification and user manual HAW - Arduino 1

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

Serial Communications

How to design and implement firmware for embedded systems

Using Xbee in Serial Communication

UART IP Core Specification. Author: Jacob Gorban

Manual Serial PCI Cards

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

1 Application Description Objective Goals... 3

Modbus and ION Technology

P-660HW-Tx v g Wireless ADSL2+ 4-port Gateway DEFAULT LOGIN DETAILS. Firmware v3.70 Edition 1, 2/2009

BIT COMMANDER. Serial RS232 / RS485 to Ethernet Converter

Software User Guide UG-461

RS-485 Protocol Manual

Modbus and ION Technology

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

VSCOM USB PRO Series Industrial I/O Adapters

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

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

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

SURVEY PRO. GPS Quick Start Guide

Using the AnyBus -X Gateway to Communicate between a DVT camera and a Profibus Master

1-Port R422/485 Serial PCIe Card

RS485 & RS422 Basics

How to setup a serial Bluetooth adapter Master Guide

Hello, and welcome to this presentation of the STM32 SDMMC controller module. It covers the main features of the controller which is used to connect

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

Single channel data transceiver module WIZ2-434

WUA Mbps Wireless USB Network Adapter

TCP/IP MODULE CA-ETHR-A INSTALLATION MANUAL

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

1. Computer System Structure and Components

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

Operation Manual of EX9132C-RS485. Serial to TCP/IP Converter

Industrial Multi-port Serial Cards

How To Set Up A Modbus Cda On A Pc Or Maca (Powerline) With A Powerline (Powergen) And A Powergen (Powerbee) (Powernet) (Operating System) (Control Microsci

PCS0100en Persy Control Services B.V. Netherlands

Welcome to the Introduction to Controller Area Network web seminar My name is William Stuart, and I am a Applications Engineer for the Automotive

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

How to Prevent Power Surges: The Leading Cause of Serial Device Server Failures

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

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

Wireless LAN g USB Adapter

OPT SERIAL TO FIBER OPTIC CONVERTER

Cisco - Configure the 1721 Router for VLANs Using a Switch Module (WIC-4ESW)

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

Research of PROFIBUS PA s integration in PROFINET IO

White Paper. Technical Capabilities of the DF1 Half-Duplex Protocol

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

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

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

Fingerprint Based Biometric Attendance System

Programming Flash Microcontrollers through the Controller Area Network (CAN) Interface

RN-131-PICTAIL & RN-171-PICTAIL Evaluation Boards

LDG Electronics External Meter Serial Communications Protocol Specification

SolarEdge. RS485 Expansion Kit Installation Guide. Version 1.0

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

CONTROL MICROSYSTEMS DNP3. User and Reference Manual

Serial Communications

ISDN Phone Lines with Metasys

Device Type Manager (DTM) Basic HART

Overcoming IP Address Issues with GPRS Remote Monitoring and Alarm Systems

eztcp Technical Document Modbus/TCP of eztcp Caution: Specifications of this document may be changed without prior notice for improvement.

CAN bus board. EB018

Designing VM2 Application Boards

WAGO PFC as a MODBUS MASTER Application note

P-660HNU-Tx. Wireless N ADSL2+ 4-port Gateway DEFAULT LOGIN DETAILS. Firmware v1.02 Edition 1, 11/2011. IP Address:

Programmable set for Ethernet Modbus/TCP in IP67 TI-BL67-PG-EN-2

Local Interconnect Network Training. Local Interconnect Network Training. Overview

Computer Systems Structure Input/Output

Using the HT46R46 I/O Ports to Implement Half-Duplex SPI Communication

TRP-C31M MODBUS TCP to RTU/ASCII Gateway

Quick Installation. A Series of Intelligent Bar Code Reader with NeuroFuzzy Decoding. Quick Installation

NPort DE-311 Hardware Installation Guide

The GV-I/O Box 8 Ports provides 8 inputs and 8 relay outputs, and supports both DC and AC output voltages.

User manual Compact Web PLC WP240 series IEC-line

CENTRONICS interface and Parallel Printer Port LPT

Redundant Gigabit Backbone Adds Speed and Reliability to Industrial Networks

USB to RS-422/485 Serial Adapter

DeviceMaster UP Modbus Controller to Controller Communication

Modbus TCP / DALI converter

Real-time Operating Systems Lecture 27.1

PCMCIA 1 Port RS EDITION OCTOBER 1999

Straton and Zenon for Advantech ADAM Copalp integrates the straton runtime into the ADAM-5550 device from Advantech

Quick Start Guide. MRB-KW01 Development Platform Radio Utility Application Demo MODULAR REFERENCE BOARD

Transcription:

Communication Casper Yang, Senior Product Manager support@moxa.com RS-485 is a good choice for long distance serial communication since using differential transmission cancels out the vast majority of electromagnetic disturbances picked up by the signal. A simple RS-485 network consists of one master and up to 32 slave devices. Since RS-485 uses half-duplex communication that is, the same two wires (D+ and D- shown below) are used for both transmission and reception some means of controlling which side of the connection can transmit must be built into the system. In this article, we discuss the ADDC (Automatic Data Direction Control) concept and explain how ADDC works. D+ D+ Fig. 1: RS-485 Half-duplex Communication Copyright 2009 Moxa Inc. Released on Sep 28, 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.

The most common way of controlling the transmit (Tx) and receive (Rx) direction is to use an RTS signal between the UART and the RS-485 half-duplex wiring. By adding a simple logic circuit (see Fig. 2), you can turn RTS on or off to switch the direction between Tx and Rx. That is, to transmit data you turn RTS on, and then you turn it off when the transmission is finished. Although the overall concept is easy to describe and understand, devising a precise enough timing mechanism can be quite a challenge. UART Tx Rx D + RTS Fig. 2: Using RTS to Control Data Direction In most cases, the RS-485 bus uses a master-slave architecture, which requires that each device on the RS-485 bus have a unique id. The master will send a command with an id and ask each slave to respond one by one. The default RTS state is off, which means that all devices are in the Rx state and are waiting to receive data (either a command or a response to a command) from one of the other devices. A typical scenario is as follows: (1) The master switches to the Tx state, transmits a command to query a device, and then switches back to the Rx state and waits for a response. (2) The slave whose id matches the id queried by the master switches to the Tx state, transmits its response, and then switches back to the Rx state. Copyright 2009 Moxa Inc. Page 2 of 5

If the master switches back to the Rx state too slowly, it will not receive the entire response. If the master switches back too quickly, the command will not be sent correctly. To control the timing properly, you need to know when the data was sent out. Master Tx: Command Rx State Slave Rx State Response Master-RTS If too fast, the slave cannot receive all commands from the master. Good Timing If too slow, the master cannot receive all responses from the slave. Fig. 3: Using RTS to Control Direction UART Holding and Shift Registers For Controlling the UART Directly With the UART s Transmitter Empty Interrupt (TxINT) enabled, you may think it s okay to turn the RTS to off if no more data need to be sent. However, checking the TxINT value will only tell you that the holding register is empty, when in fact an additional byte could still be transmitting from the shift register. The UART s transmit shift register is used to transmit data bit by bit. Every time you put data in the FIFO, the UART will move data into the shift register automatically. To confirm that the shift register is empty, you need to read the Line Status Register (LSR) and check if both the Transmitter Holding Register Empty (THRE) bit and Transmitter Empty (TEMT) bit are set or not. If both are set, it is safe to turn the RTS to off. Copyright 2009 Moxa Inc. Page 3 of 5

UART Enhanced Mode with TTL Setting For Controlling the UART Directly To improve performance some advanced UARTs, such as the 16950 and Moxa s MU150/MU860, support Transmit Interrupt Trigger Level (TTL). This level defines when the UART needs to issue a Transmitter Empty Interrupt (TxINT) and cause the Interrupt Service Routine (ISR) to put more data into the UART. With this level set to a nonzero value, the UART can issue an interrupt even though some data is still queued in the Tx FIFO. To work properly in an RS-485 application, you need to set TTL to zero. This means that if you get a TxINT, the UART holding register and shift register are empty and you can turn RTS to off immediately if no more data in the buffer needs to be sent. Applications in Win32 and UNIX/Linux For Serial Application Programmers In most cases, you do not need to control the UART manually, and instead just use the API provided by the operating system. You can use WriteFile() for Win32 systems, and write() for UNIX/Linux systems. Win32 provides the function RTS_CONTROL_TOGGLE to work with the RTS automatically. If frtscontrol is set to this value in the DCB structure by calling SetCommState(), the driver should turn RTS on automatically before sending the data and turn RTS off automatically when it finishes. Before using this approach, you should first make sure that it is supported by the vendor if you are using a serial expansion solution (which means that you are not using serial.sys, Windows built-in serial port driver). If RTS_CONTROL_TOGGLE is not supported, controlling RTS manually will cause a lot of timing problems, and is not reliable. For UNIX/Linux, the POSIX tty API does not support the RTS toggle function, and you need to control RTS manually. In this case, you can call tcdrain() to wait until data is sent and turn RTS off. The problem is that tty drivers only check the driver buffer and UART holding register. Unfortunately, there is no way to confirm that the shift register is empty. If you really want to use RS-485 in UNIX/Linux with RTS control, you need to modify the driver or call your vendor for support. Copyright 2009 Moxa Inc. Page 4 of 5

Working with Virtual Serial Ports For Serial Application Programmers If the serial port is a virtual port, such as is created by a USB-to-serial or Ethernet-to-serial product, it s not easy to know when all the data has been sent out because the driver needs to work with the firmware in the product and not a real UART. For virtual serial drivers, the write operation will be finished immediately when the data is moved to the local driver buffer. This is good for performance but is not good for RS-485 RTS control. If you turn RTS off immediately when the write operation is finished, the data will still be transmitting, which will cause problems. In this case, in Win32 you can use RTS_CONTROL_TOGGLE if it is supported by the driver. If not, you need to see if the driver supports an advanced option (such as Moxa s classical mode in UPort and NPort) for confirming that all data will be sent out before the WriteFile() is returned. For virtual serial ports it is impossible to control RTS manually without RTS_CONTROL_TOGGLE or classical mode supported in Windows/UNIX/Linux. Controlling RTS Automatically For Everyone Controlling RTS by software (driver or application) can give rise to a number of problems, and consequently many hardware vendors solve this problem by controlling the direction automatically. This means that the RS-485 hardware can switch the Tx/Rx direction automatically, such as is done with Moxa s ADDC (Automatic Data Direction Control) function. It is compatible with existing software and if you want to transmit commands over the RS-485 bus, you can just send, instead of worrying about controlling the RTS signal. The hardware will detect the action and switch to the Tx state automatically. Note that some converter products require users to configure the baudrate first. Please read the manual of your product for detailed information. Conclusion A good way to simplify RS-485 implementation is to choose a product that supports ADDC. With ADDC you do not need to waste time modifying your programming to match the timing. You can keep your existing programming as is, and rest assured that it works with ADDC. Controlling the RTS on/off process will be ignored by ADDC, and all you need to do is configure the hardware properly. Copyright 2009 Moxa Inc. Page 5 of 5