Rs 16x Serial
Become a subscriber (Free)Join 29,000 other subscribers to receive subscriber sale discounts andother free resources.Name:E-Mail:Don't worry - youre-mail address is totallysecure. I promise to use it only to send youMicroZine.How RS232 worksHow RS232 works: RS232 defines a protocol that details how a stream of data bits issequentially transmitted onto a wire i.e.
Combined 12-gauge 'Model 11' and 'The Sportsman' serial numbers reached 499,999 on August 1, 1943. Serial numbers were then jumped to 700,000 and continued.' I've seen plenty of Sportsmen guns with S18xx, 509,xxx, and S500,8xx serial numbers all of which have the Sportsman engraved in them.
A bit stream. The order andmeaning of each bit is defined by the protocol. The simple explanationbelow is sufficient to understand RS232 - no need to read a big manual!RS232 is a serial information transfer protocol standardthat defines both the protocol (method of transmission of data) and thephysical hardware to do it. This document describes how it works at thephysical level so you will know what signals you can expect to see at themicrocontroller pins.What is RS232?Fundamentally it is a method of transferring data across a single wire (youneed two wires to get data back since each wire transfers data in one directiononly):It is a method (or protocol - an agreed standard) that defines how totransfer data between two devices using a few wires. It uses a serialtransmission method where bytes of data are output one bit at a time onto asingle wire.Data is only transmitted in one directionfor each wire so for bi-directional communication (two directions) youneed two wires. So this is not a multidrop lan communication system such as RS485 but a point-to-point protocol.These two along with a ground reference (total: three wires) make up theminimum configuration that you can get away with.Note: For more reliable communication overlong distances you may need to use other connections defined in the RS232standard such as DTR DCT etc. Handshake signals etc.
More formally RS232 is an asynchronous communication protocol that lets youtransfer data between electronic devices.Basically it can transfer a single byte of data over a serial cable havingbetween 3 to 22 signals and running at speeds from 100 to 20k baud. Commonbaud rates used are 2.4k, 9.6k, 19.2k, The cable length can be up to 50ft.Higher baud rates are used but not covered by the standard they still workthough e.g. 0 Baud (bits/s).To transfer a block of data individual bytes are transmitted one afteranother.
IntroductionThis section describes how RS232 works in general without describinghandshake methods - only the simplest system is described - this it themostuseful and the most likely to work!Handshake signals need extra level translation hardware (an RS232chip with more I/O) and although simple are not typically required forPC to development board operation. You may need them for systems thatare controlling multiple devices where you may need to temporarily stopdata from a unit. There is a section on later in this document.Data is transmitted serially in one direction over a pair of wires. Datagoing out is labeled Tx (indicating transmission) while data coming in islabelled Rx (indicating reception).
To create a two way communication system aminimum of three wires are needed Tx, Rx and GND (ground). Crossing over Tx& Rx between the two systems lets each unit talk to the opposite one. Note: Each signal (TX and RX) requires a level translator since highvoltages are used for transmitting the data onto the wires (typicallyoutput from ±5V to ±25V).Each byte can be transmitted at any time (as long as the previous byte hasbeen transmitted). The transmitted byte is not synchronized to the receiver -it is an asynchronous protocol i.e. There is no clock signal. For this reasonsoftware at each end of the communication link must be set up exactly the sameso that each serial decoder chip can decode the serial data stream.Note: The signal level inversion (logic 1is -12V and logic 0 is +12V).Baud RateHow RS232 works in the relationship between baud rate and signalfrequency.The baud rate is simply the transmission speed measured in bits per second.It defines the frequency of each bit period.For a baud rate of 2400 (2400 bps) the frequency is 2400Hz and the bitperiod is 1/2400 or 416.6us. Download torrent hannibal serie tv italia. This is the information that a receiver uses torecover the bits from the data stream.
How RS232 Works - Voltagelevels Transmitter Voltage LevelsTo make it work over long cables high voltages are sent from eachtransmitter since due to cable resistance the voltage reduces the further thesignal has to travel. The output voltage specification is from +5V to +25V(transmitting a logical zero) and -5V to -25V (transmitting a logical one).Note: all signals in the cable have to generate the same voltage levels e.g.DTR, DSR, RTS, CTS. So you need a lot of level translator chips for a fullinterface but for very short distances you only need TX and RX and ground.The maximum voltage of ±25V does not have to be used and a commonvoltage in use is ±12V (output by MAX232 transceiver chip).A mark (logical one) is sent as -12V and a space (logical zero) is sent as+12V i.e. The logic sense is inverted.Note: The fact that high voltages exist at the serial port allowspowering devices that you would not normally expect to find on it. But theymust draw very little current. Receiver Voltage LevelsAt the receiver the input the minimum voltage levels are defined as ±3V i.e. To receivea logic zero the voltage must be greater than 3V and to receive a logic one thevoltage must be smaller than -3V.
This allows for losses as the signal travelsdown the cable and provides noise immunity i.e. Any spurious noise up to alevel of ±3V can be tolerated without it having any effect on the receiver.How RS2332 Works - The Bits How RS232 works - TheRS232 Start BitThe protocol is described as asynchronous as there is no clock transmittedat all. Instead a different method of clock recovery is used.At the beginning of each transmission a start bit is transmitted indicatingto the receiver that a byte of data is about to follow. Since the idle state ofthe RS232 lines is low (-12V) to signal a start condition the line is set high(+12V) for 1 bit period. This means a transition on the line is alwaysgenerated so that a receiver knows when the 1st edge of the data burstoccurs.The start bit lets the receiver synchronize to the data bits since it cansee the rising edge of the signal on the line. What this means is that thereceiver can create its own sample clock at the middle of each bit - to decide if the bit is actually a data zero or data one.Once the start bit is found the receiver knows where the followingbits will beas it is given the sample period (derived from the baud rate) as part oftheinitialization process. This is why you must set the same settings inboth the receiver and the transmitter hardware i.e.
Baud rate, number ofstop bits, number of data bits, and parity bit (on or off). If youdon't then usually nothing will happen - or you will see rubbishcharacters at the receiver.How RS232 works - The DatabitsData bits follow the start bit. There will usually be seven or eight databits with the lsb transmitted first.
The reason you can choose between seven oreight is that ASCII is made up of the alphabet within the first seven bits (aswell as the control characters). The eighth bit extends the character set forgraphical symbols.If you only want to transmit text then you only need 7 bits.
This saves abit and increases transmission speed when transmitting large blocks of data.Other data bit sizes are 5, 6, 8, and 9 bits. However bit length is usuallyset to 8 bits - this is very commonly used. TIP: Since most modules are capable of handling nine bits youcould define a use for the ninth bit such as indicating that the data packetdefines a command. But of course you have to adjust your receiver software toprocess that information.Note: If you use RS232 to transmit raw data (binary data) then you willneed 8 data bits. How RS232 works - The Parity BitThe RS232 parity bit is a crude error detection mechanism.You can use either odd parity or even parity or none at all (in the diagramabove a parity bit is included (between the last data bit and the stop bit -Here the parity is indicated as a '1' meaning that there are an odd number ofdatabits.
So the parity in use is odd-parity. The diagram below (commonly usedin microcontroller work) does not use a parity bit.It simply evaluates all the data bits and for odd parity returns a logic oneif there is an odd number of data bits that are set. For even parity an evennumber of data bits that are set, sets the parity bit.At the receiver the parity bit is used to tell if an error occurred duringtransmission. You can use this in the receiver software by reading a flag inthe UART module.The problem with error detection using the parity bit is that if two bitsare in error then the parity check fails. This is because each error cancelsthe effect of the other (in terms of the parity calculation). Any even numberof errors causes a failure in error detection.It won't be a problem on a bench top based system (that has no critical datatransfer).
Over a short cable e.g. 6ft you probably won't see any errorsanyway. Normally I use no parity and there is no problem at all.For systems running over a long distance or in a noisy environment a bettersystem should be used e.g. Adding a cyclic redundancy check to the data streambefore and after it is sent over the RS232. CRCs let you check for and correctquite a few errors without re transmitting the data.
How RS232 works - The StopbitThe RS232 stop bit merely gives a period of time before thenext start bit can be transmitted. It is the opposite sense to the start bitand because of this allows the start bit to be seen i.e. A stop bit followed bya start bit always gives a rising edge signal for detection by the receiver.If there was no stop bit then the last bit in the data stream would be theparity bit (or data bit if parity is not active). This would change dependingon the data sent so if it had the same sense as the start bit then the startbit could not be seen!The stop bit can be set choosing from 1, 1.5, or 2 bit periods.At very high baud rates the period from stop bit to start bit(assuming data is being sent continuously) will be very small e.g. For abaud rate of 115200 baud the timeing to one bit is 1/115200 = 8.26us soby using 2 bit periods you will increase the time to 16.5us. This canallow the receiver to detect the start bit more easily since if there iscapacitance on the line the waveforms will exhibit a CR rise fall time.Extending the time period allows more capacitive loading. However italso depends on the receiver hardware used.Typical SettingsTypical settings for use on the desktop e.g.
Between a microcontroller and aterminal emulator program such as 'Tera Term'. How RS232 works: Typical Baud ratesettings. Baud9600Data bits8ParityNoneStop bits1Flow ControlNoneThis can also be compactly written as:9600 8N1Hardware Connections 3 (Rx,Tx,GND) - Rx and Tx crossed over.' Flow control' in the above list is referring to a hardware flow controlsignalling method that uses the signals DTR/DSR and RTS/CTS. See for more on that.RS232 Details How RS232 Works - Signal LevelsAt some point you may want to make a software UART perhaps to save codespace in your current design (maybe you don't need the receive part - as youare just outputting variables) or to use a spare pin.Note: you can find receive and transmitsoftware USART code in the Tutorialpages.To create it you need the actual signal diagrams that you see at themicrocontroller pin (strangely these are hard to find on the web).The following diagram shows the timed 0V and 5V bit stream at the output pinof the microcontroller. The lower diagram shows the translated signal levels atthe RS232 output drivers which are transmitted over the serial cable.These higher levels are are generated by sending the 0-5V logic levels to atransceiver chip e.g.
MAX232 which has a diode/capacitor boost conveter builtin that boosts the signal levels to the required RS232 voltageof ±12 volts. Note how the -12V level corresponds to a logical '1' and +12Vlevel corresponds to a logical '0'. How RS232 works when transmitting acharacterThe lower waveform in the bove diagram above shows the RS232signal that you would see using an oscilloscope on the output drive ofa translator chip such as the MAX232. Note that the RS232 idlevoltage is -12V, RS232 ClockThe above diagram also shows the RS232 timingdiagr am where each bit period is 1/frequency so for abaud rate of 9600 bps (bits per second) the period of each bit is 1/9600 or104.166us this is effectively the RS232 clock period required for the specificbaud rate in use. RS232 WaveformIn the diagram above the lower waveform shows the RS232 voltagesignal that you can expect to see at the output of the RS232 TX pin(also the same levels on the RX pin) on an oscilloscope.
In some chips themaximum signal level may not be ±12V - the max and min voltage could besmaller (as there will not be a large voltage drop over short distances). Forlong distances these should be ±12V - at the end of a long cable the voltagewill drop down across the resistance of the cable but must be more than ±3V atthe other end.The cable capacitance will also slow the rising and falling edges - roundingthem off.How RS232 Works - Handshake SignalsHandshake signals are simply a method of stopping data flowing. Ifsome part of the system is busy it may not be able to accept more dataand rather than losing it signals are used at each end of the link totell the other end to stop transmitting data.
There are two types usedin RS232: hardware handshake and software handshake.Hardware handshake. DTR - Data Terminal Ready. DSR - Data Set Ready. RTS - Request To send. CTS - Clear To Send.If you use these signals then they must all be transmitted at theRS232 levels i.e. ±25V (or whatever voltage is generated by thetranslator chip e.g.
The same as the TX output so you needan RS232 chip with more level translators to both transmit and receivethe signals.Remember that the protocol was based on a modem (the DCE or DataCommunication Equipment) sitting on a desk and an attached (via RS232)to the PC (the DTE or Data Terminal Equipment) - the controller. There'seven a ring indicator (RI) that signals when the telephone was ringing,wired directly to the telephone line, which would allow automatic modemdetection of an incoming data stream.Each signal is not orthogonal meaning that there is not an equivalentsignal going back the other way.
This part of the protocol grew overtime so there are different uses of these signals but in general thefollowing is used:To stop data coming from the PC i.e.