Sie sind auf Seite 1von 3

1/7/2017 RS232,RS422,RS485SerialCommunicationGeneralConceptsNationalInstruments

RS232,RS422,RS485SerialCommunicationGeneralConcepts
PublishDate:Jun29,2016

Overview
ThisarticleexplainsthegeneralconceptsoftheserialcommunicationprotocolsRS232,RS422,andRS485,includingbasic
conceptslikebaudrate,databits,stopbits,parity,andhandshaking.

TableofContents
1.WhatisSerial?
2.WhatisRS232?
3.WhatisRS422?
4.WhatIsRS485?
5.HowdoRS232,RS422,andRS485Compare?
6.WhatisHandshaking?
7.RelatedLinks

1.WhatisSerial?
Theconceptofserialcommunicationissimple.Theserialportsendsandreceivesbytesofinformationonebitatatime.This
isslowerthanparallelcommunication,whichallowsthetransmissionofanentirebyteatoncehowever,itissimplerandcan
beusedoverlongerdistances.Forexample,theIEEE488specificationsforparallelcommunicationstatethatthecabling
betweenequipmentcanbenomorethan20meterstotal,withnomorethan2metersbetweenanytwodevicesserialcan
extendasmuchas1200meters.

Typically,serialisusedtotransmitASCIIdata.Communicationiscompletedusing3transmissionlines:(1)Ground,(2)
Transmit,and(3)Receive.Sinceserialisasynchronous,theportisabletotransmitdataononelinewhilereceivingdataon
another.ThisisreferredtoasFullDuplextransmission.Otherlinesareavailableforhandshaking,butarenotrequired.The
importantserialcharacteristicsarebaudrate,databits,stopbits,andparity.Fortwoportstocommunicate,theseparameters
mustmatch:
a.Baudrateisaspeedmeasurementforcommunication.Itindicatesthenumberofbittransferspersecond.Forexample,
300baudis300bitspersecond.Whenwerefertoaclockcycle,inthecontextofserial,wemeanthebaudrate.For
example,iftheprotocolcallsfora4800baudrate,thentheclockisrunningat4800Hz.Thismeansthattheserialportis
samplingthedatalineat4800Hz.Commonbaudratesfortelephonelinesare14400,28800,and33600.Baudrates
greaterthanthesearepossible,buttheseratesreducethedistancebywhichdevicescanbeseparated.Thesehighbaud
ratesareusedfordevicecommunicationwherethedevicesarelocatednearoneanother.

b.Databitsareameasurementoftheactualdatabitsinatransmission.Whenthecomputersendsapacketofinformation,
theamountofactualdatamaynotbeafull8bits.Standardvaluesforthedatapacketsare5,7,and8bits.Whichsetting
youchoosedependsonwhatinformationyouaretransferring.Forexample,standardASCIIhasvaluesfrom0to127(7
bits).ExtendedASCIIuses0to255(8bits).Ifthedatabeingtransferredissimpletext(standardASCII),thensending7
bitsofdataperpacketissufficientforcommunication.Apacketreferstoasinglebytetransfer,includingstart/stopbits,
databits,andparity.Sincethenumberofactualbitsdependontheprotocolselected,thetermpacketisusedtocoverall
instances.

c.Stopbitsareusedtosignaltheendofcommunicationforasinglepacket.Typicalvaluesare1,1.5,and2bits.Sincethe
dataisclockedacrossthelinesandeachdevicehasitsownclock,itispossibleforthetwodevicestobecomeslightlyout
ofsync.Therefore,thestopbitsnotonlyindicatetheendoftransmissionbutalsogivethecomputerssomeroomforerror
intheclockspeeds.Themorebitsthatareusedforstopbits,thegreaterthelenienceinsynchronizingthedifferentclocks,
buttheslowerthedatatransmissionrate.

d.Parityisasimpleformoferrorcheckingthatisusedinserialcommunication.Therearefourtypesofparity:even,odd,
marked,andspaced.Theoptionofusingnoparityisalsoavailable.Forevenandoddparity,theserialportwillsetthe
paritybit(thelastbitafterthedatabits)toavaluetoensurethatthetransmissionhasanevenoroddnumberoflogichigh
bits.Forexample,ifthedatawas011,thenforevenparity,theparitybitwouldbe0tokeepthenumberoflogichighbits
even.Iftheparitywasodd,thentheparitybitwouldbe1,resultingin3logichighbits.Markedandspacedparitydoesnot
actuallycheckthedatabits,butsimplysetstheparitybithighformarkedparityorlowforspacedparity.Thisallowsthe
receivingdevicetoknowthestateofabitwhichenablesthedevicetodetermineifnoiseiscorruptingthedataorifthe
transmittingandreceivingdevices'clocksareoutofsync.
2.WhatisRS232?
RS232(ANSI/EIA232Standard)istheserialconnectionhistoricallyfoundonIBMcompatiblePCs.Itisusedformany
purposes,suchasconnectingamouse,printer,ormodem,aswellasindustrialinstrumentation.Becauseofimprovementsin
linedriversandcables,applicationsoftenincreasetheperformanceofRS232beyondthedistanceandspeedlistedinthe
standard.RS232islimitedtopointtopointconnectionsbetweenPCserialportsanddevices.RS232hardwarecanbeused
forserialcommunicationuptodistancesof50feet.

Data

TXD(pin3) SerialDataOutput

RXD(pin2) SerialDataInput

Handshake

RTS(pin7) RequesttoSend

CTS(pin8) CleartoSend

DSR(pin6) DataSetReady

DCD(pin1) DataCarrierDetect

DTR(pin4) DataTerminalReady

Ground

GND(pin5) Ground

Other

RI(pin9) RingIndicator

Table1:PinFunctionsforRS232

3.WhatisRS422?
http://www.ni.com/whitepaper/11390/en/ 1/3
1/7/2017 RS232,RS422,RS485SerialCommunicationGeneralConceptsNationalInstruments
3.WhatisRS422?
RS422(EIARS422AStandard)istheserialconnectionhistoricallyusedonAppleMacintoshcomputers.RS422usesa
differentialelectricalsignal,asopposedtounbalancedsignalsreferencedtogroundwiththeRS232.Differentialtransmission
usestwolineseachfortransmitandreceivesignalswhichresultsingreaternoiseimmunityandlongerdistancesascompared
totheRS232.TheseadvantagesmakeRS422abetterfitforindustrialapplications.
4.WhatIsRS485?
RS485(EIA485Standard)isanimprovementoverRS422,becauseitincreasesthenumberofdevicesfrom10to32and
definestheelectricalcharacteristicsnecessarytoensureadequatesignalvoltagesundermaximumload.Withthisenhanced
multidropcapability,youcancreatenetworksofdevicesconnectedtoasingleRS485serialport.Thenoiseimmunityand
multidropcapabilitymakeRS485theserialconnectionofchoiceinindustrialapplicationsrequiringmanydistributeddevices
networkedtoaPCorothercontrollerfordatacollection,HMI,orotheroperations.RS485isasupersetofRS422thus,all
RS422devicesmaybecontrolledbyRS485.RS485hardwaremaybeusedforserialcommunicationwithupto4000feetof
cable.

Data

TXD+(pin8) SerialDataOutput(differe
ntial)

TXD(pin9) SerialDataOutput(differe
ntial)

RXD+(pin4) SerialDataInput(differenti
al)

RXD(pin5) SerialDataInput(differenti
al)

Handshake

RTS+(pin3) RequesttoSend(different
ial)

RTS(pin7) RequesttoSend(different
ial)

CTS+(pin2) CleartoSend(differential)

CTS(pin6) CleartoSend(differential)

DSR(pin6) DataSetReady

Ground

GND(pin1) Ground

Table2:PinFunctionsforRS485andRS422

5.HowdoRS232,RS422,andRS485Compare?
RS232isthemostcommonserialinterfaceandusedtoshipasastandardcomponentonmostWindowscompatibledesktop
computers.NowitismorecommontouseRS232overUSBusingaconverter.RS232onlyallowsforonetransmitterand
onereceiveroneachline.RS232alsousesaFullDuplextransmissionmethod.SomeRS232boardssoldbyNational
Instrumentssupportbaudratesupto1Mbit/s,butmostdevicesarelimitedto115.2kbits/s.
RS422(EIARS422AStandard)istheserialconnectionusedonlegacyApplecomputers.Itprovidesamechanismfor
transmittingdataupto10Mbits/s.RS422sendseachsignalusingtwowirestoincreasethemaximumbaudrateandcable
length.RS422isalsospecifiedformultidropapplicationswhereonlyonetransmitterisconnectedto,andtransmitson,abus
ofupto10receivers.
RS485isasupersetofRS422andexpandsonthecapabilities.RS485wasmadetoaddressthemultidroplimitationofRS
422,allowingupto32devicestocommunicatethroughthesamedataline.AnyoftheslavedevicesonaRS485buscan
communicatewithanyother32slavedeviceswithoutgoingthroughamasterdevice.SinceRS422isasubsetofRS485,all
RS422devicesmaybecontrolledbyRS485.
BothRS485andRS422havemultidropcapability,butRS485allowsupto32devicesandRS422hasalimitof10.For
bothcommunicationprotocols,youshouldprovideyourowntermination.AllNationalInstrumentsRS485boardswillwork
withRS422standards.
Thefollowingtablecomparesmodeofoperation,totalnumberofdriversandreceivers,maximumcablelength,andmaximum
datarate.

Specifications RS232 RS422 RS485

ModeofOperatio SingleEnded Differential Differential


n

NumberofDriver 1Driver 1Driver 32Drivers*


s/Receiverson 1Receiver 10Receiv 32Receivers
OneLine ers

MaximumCable 50ft(2500pF) 4000ft 4000ft


Length

MaximumDataR 160kbits/s(canbeupto1Mbit/s) 10Mbit/s 10Mbit/s


ate(atmaxcable
length)

http://www.ni.com/whitepaper/11390/en/ 2/3
1/7/2017 RS232,RS422,RS485SerialCommunicationGeneralConceptsNationalInstruments
Table3:SpecificationsofRS232,RS422,andRS485
*Onlyonedriverisactiveatatime

6.WhatisHandshaking?
ThemethodusedbyRS232forcommunicationallowsforasimpleconnectionofthreelines:TX,RX,andground.
Forthedatatobetransmitted,bothsideshavetobeclockingthedataatthesamebaudrate.Although,thismethodis
sufficientformostapplications,itislimitedinbeingabletorespondtoproblemssuchasthereceivergettingoverloaded.This
iswhereserialhandshakingcanhelp.InthissectionwewilldiscussthreeofthemostpopularformsofhandshakingwithRS
232:SoftwareHandshaking,HardwareHandshaking,andXmodem.
a.SoftwareHandshaking:Thefirstformofhandshakingwewilldiscussissoftwarehandshaking.Thisstyleusesactualdata
bytesascontrolcharacters,similartothewayGPIBusescommandstrings.Thelinesnecessaryarestillthesimplethree
linesetofTX,RX,androundsincethecontrolcharactersaresentoverthetransmissionlinelikeregulardata.Thefunction
SetXModeallowstheusertoenableordisabletheuseoftwocontrolcharacters,XONandXOFF.Thesecharactersare
sentbythereceiverofthedatatopausethetransmitterduringcommunication.
Asanexample,assumethatthetransmitterbeginstotransmitdataatahighbaudrate.Duringthetransmission,the
receiverfindsthattheinputbufferisbecomingfullduetotheCPUbeingbusywithotherduties.Totemporarilypausethe
transmission,thereceiversendsXOFF,typicallydecimal19orhex13,untiltheinputbufferhasbeenemptied.Oncethe
receiverisreadyformoredataitsendsXON,typicallydecimal17orhex11,toresumecommunication.LabWindowswill
sendXOFFwhenitsinputbufferbecomeshalffull.Inaddition,incasetheXOFFtransmissionwascorrupted,LabWindows
willalsotransmitXOFFwhenthebufferhasreached75%and90%capacity.Obviously,thetransmittermustalsobe
followingthisprotocolforittosucceed.
Thebiggestdrawbacktothismethodisalsothemostimportantfacttokeepinmind:decimal17and19arenowofflimits
fordatavalues.InASCIItransmissionsthistypicallydoesnotmattersincethesevaluesarenoncharactervalueshowever,
ifthedataisbeingtransmittedviabinary,itisverylikelythatthesevaluescouldbetransmittedasdataandthe
transmissionwouldfail.
b.HardwareHandshaking:Thesecondmethodofhandshakingistouseactualhardwarelines.LiketheTXandRXlines,
theRTS/CTSandDTR/DSRlinesworktogetherwithonebeingtheoutputandtheothertheinput.Thefirstsetoflinesare
RTS(RequesttoSend)andCTS(CleartoSend).Whenareceiverisreadyfordata,itwillasserttheRTSlineindicatingit
isreadytoreceivedata.ThisisthenreadbythesenderattheCTSinput,indicatingitiscleartosendthedata.Thenext
setoflinesareDTR(DataTerminalReady)andDSR(DataSetReady).Theselinesareusedmainlyformodem
communication.Theyallowtheserialportandthemodemtocommunicatetheirstatus.Forexample,whenthemodemis
readyfordatatobesentfromthePC,itwillasserttheDTRlineindicatingthataconnectionhasbeenmadeacrossthe
phoneline.ThisisreadinthroughtheDSRlineandthePCcanbegintosenddata.Thegeneralruleofthumbisthatthe
DTR/DSRlinesareusedtoindicatethatthesystemisreadyforcommunicationwheretheRTS/CTSlinesareusedfor
individualpacketsofdata.
InLabWindows,thefunctionSetCTSModeenablesordisablestheuseofhardwarehandshaking.IftheCTSmodeis
enabled,LabWindowsemploysthefollowingrules:
WhenthePCsendsdata:
TheRS232librarymustdetectthatitsCTSlineishighbeforesendingdata.
WhenthePCreceivesdata:
Iftheportisopenedandtheinputqueuehasroomfordata,thelibraryraisesRTSandDTR.
Iftheport'sinputqueueis90%full,thelibrarylowersRTSandleavesDTRhigh.
Iftheport'sinputqueueisnearlyempty,thelibraryraisesRTSandleavesDTRhigh.
Iftheportisclosed,thelibrarylowersRTSandDTR.
c.XModemHandshaking:ThelastmodediscussedhereistheXModemfiletransferprotocol.Thisprotocolisverycommon
inmodemcommunication.Althoughitisoftenusedformodemcommunication,theXModemprotocolcanbeuseddirectly
betweenotherdevicesiftheybothfollowtheprotocol.InLabWindows,theactualimplementationofXModemishidden
fromtheuser.AslongasthePCisconnectedtoanotherdeviceusingXModemprotocol,theLabWindows'XModem
functionscanbeusedtotransferfilesfromonesitetoanother.ThefunctionsareXModemConfig,XModemSend,and
XModemReceive.
XModemusesaprotocolbasedonthefollowingparameters:start_of_data,end_of_trans,neg_ack,ack,wait_delay,
start_delay,max_tries,packet_size.Theseparametersneedtobeagreeduponbybothsides.StandardXModemhasa
standarddefinitionofthesehowever,theycanbemodifiedthroughtheXModemConfigfunctioninLabWindowstomeet
anyrequirement.ThewaythattheseparametersareusedinXModemisbyhavingtheneg_ackcharactersentbythe
receiver.Thistellsthesenderthatitisreadytoreceivedata.Itwilltryagainwithstart_delaytimeinbetweeneachtryuntil
eitheritreachesmax_triesorreceivesstart_of_datafromthesender.Ifitreachesmax_triesitwillinformtheuserthatit
wasunabletocommunicatewiththesender.Ifitdoesreceivestart_of_datafromthesender,itwillreadthepacketof
informationthatfollows.Thispacketcontainsthepacketnumber,thecomplementofthepacketnumberasanerrorcheck,
theactualdatapacketofpacket_sizebytes,andachecksumonthedataformoreerrorchecking.Afterreadingthedata,
thereceiverwillcallwait_delayandthensendackbacktothesender.Ifthesenderdoesnotreceiveack,itwillresendthe
datapacketmax_triesoruntilitreceivesack.Ifitneverreceivestheack,itinformstheuserthatithasfailedtotransferthe
file.
Sincethedatamustbesentinpacketsofpacket_sizebytes,whenthelastpacketissent,ifthereisnotenoughdatatofill
thepacket,thedatapacketispaddedwithASCIINUL(0)bytes.Thiscancausethereceivedfiletobelargerthanthe
original.ItisalsoimportanttoremembernottouseXON/XOFFwiththeXModemprotocolsincethepacketnumberfrom
theXModemtransferisverylikelytoincrementtotheXON/OFFcontrolcharactervalues,whichwouldcauseabreakdown
incommunication.
7.RelatedLinks
WhitePaper:SerialCommunicationStartingPoint(http://www.ni.com/whitepaper/4049/en)
WhitePaper:ConnectingRS232andRS485OverUSB(http://www.ni.com/whitepaper/3146/en/)
ProductsandServices:NISerialInterfacesforRS232,RS422,andRS485(http://www.ni.com/serial/)

http://www.ni.com/whitepaper/11390/en/ 3/3

Das könnte Ihnen auch gefallen