Skip to main content

A blog on RS232 and UART

A blog on RS232  and UART

I found my presentation on RS232 from my college days, so I thought it would be a great idea to share it here. You can download this as a presentation HERE. But I have added a little bit more content to it and typed it in below. I hope this helps you.

RS232 (Recommended Standard 232) and UART (Universal Asynchronous Receiver and Transmitter) are serial communication standards. A simple explanation of RS232 and UART without diving into anything too technical would be like this: They are serial communication standards which clearly define how each byte of data should be transferred over a communication channel. They serialize each byte of data and send them one byte after the other. Each byte is sent serially, as one bit after the other.

[read IInd paragraph of the topic RS232 Standard, to understand difference between UART and RS232]

The text below concentrates on RS232 than on UART and if you came here hoping to understand everything from an UART perspective, you should understand this: UART and RS232 majorly only differ in the voltage levels used to represent a logic high and logic low, so read on!

Important Terminologies
I think it is important that we clear up few terms before we proceed. Two terms that are most commonly used in respect to serial communication is DTE and DCE.
> DTE stands for Data Terminal Equipment
> DCE stands for Data Communications Equipment
In layman's terms DTE is the end user equipment (e.g. your PC) and DCE is the device that communicates the data (e.g. a modem)

Serial Port
No one can explain what RS232 is without explaining serial ports. Have you heard of them? well you don't find them on your personal computer anymore so I wouldn't be surprised. But they sure do exist and RS232 is still a thing! There are still banks and other industries who are happily using it.

A serial port is what we used to connect printers back in the day. They used to look like this.
But, don't get the wrong idea, serial ports are a communication port of the computer. You can connect, printers, modems or any other compatible data communication equipment to a serial port.

What qualifies as a compatible device? Well, any device that followed RS232 communication standard is compatible with a serial port.

read more: https://en.wikipedia.org/wiki/Serial_port

> The figure shows a DB-9 type connector, apart from this there is a DB-25 type connector.
> Serial ports are bi-directional, they send and recieve

1 - Carrier Detect (CD)
2 - Received Data (RD)
3 - Transmitted Data (TD)
4 - Data Terminal Ready (DTR)
5 - Signal Ground Common reference voltage
6 - Data Set Ready (DSR)
7 - Request To Send (RTS)
8 - Clear To Send (CTS)
9 - Ring Indicator (RI)


1 - Protective Ground
2 - Transmitted Data (TD)
3 - Received Data (RD)
4 - Request To Send (RTS)
5 - Clear To Send (CTS)
6 - Data Set Ready (DSR)
7 - Signal Ground Common reference voltage
8 - Carrier Detect (CD)
20 - Data Terminal Ready
22 - Ring Indicator (RI)


Serial ports transfer data asynchronously [asynchronous - communication starts at random time e.g. A telephone call]. Since the serial port can send data at anytime, the receiver should be capable of distinguishing input as data or noise. In serial communication this is achieved by using a start bit and a stop bit, and hence asynchronous communication is sometimes called start-stop communication.

RS232 Standard
RS232 is a standard that multiple devices uses to communicate with each other and hence, it is necessary to define how they communicate. This will be explained in much detail from now on. But to start off, we have to talk about voltage levels. RS232 defines that a logic high should be reflected on the signal line as a voltage between -3v and -25v and a logic low as a voltage between +3v and +25v.

Signal
Voltage levels
Volts
Logical State
-3 to -25 
1
+3 to +25 
0

> Higher voltage levels compensate for lengthy wired transmission drops
> Logic states are inverted, - voltage is High and + voltage is low

And this is the fundemental difference between UART and RS232. UART doesn't define voltage levels, there is only logic high and logic low in UART. If you are using UART on a TTL IC, then that will be 5v and 0v respectively, if you are using a 3.3v controller then your UART voltage levels are 3.3v and 0v.

> Data is sent serially on RS232
> Each bit of data gets sent after the previous one
> A logic 0 (start bit) is sent for synhronization (for other device to distinguish b/w data and noise)
> Data is normally sent using ASCII code (murray code or EBCDIC can be used as well)
> Since multiple formats can be used, the transmitter and receiver should know what format is being used beforehand.
> After the data itself a parity bit is sent (this is optional therefore both sides should agree to using it)
> After the optional parity bit, the stop bit is sent. Which brings the communication line to its idle logic high state (RS232 -ve voltage).

RS232 HANDSHAKING
In order that data can be exchanged on an RS 232 link, the control signals must indicate that the equipment at either end of the link is ready to send the data and ready to receive the data. This can be achieved in a number of ways, but one of the more common methods is to use the RTS , CTS, and DTR lines.

Line abbreviation
Line Name
Equipment
RTS 
Request to Send 
DTE 
CTS 
Clear to Send 
DCE 
DTR 
Data Terminal Ready 
DTE 

Procedure
1. RTS is put in the ON state by the DTE

2. The DCE then put the CTS line into the ON state

3. The DTE then responds by placing the DTR line into the ON state.

4. The DTR line remains on while data is being transmitted.

The above steps where the two devices indicate their desire to communicate data can be thought of as a handshake.



Normal Connection
Normally all pins of DTE are connected to same pins on DCE with the exception of pins 2 and 3. Pins 2 and 3 (DB-9 port) and TX and RX, since TX of DTE needs to be RX of DCE and vice versa they have to be connected inversely.


Well, the connection above is extensive and is usually not required everywhere. A minimal connection can be achieved as shown below.


The catch here is that if one device sends data at a faster rate than the other can process, data will be lost as there is no means of stopping the communication.

read up on software flow control here: https://en.wikipedia.org/wiki/Software_flow_control  (be sure to read the comparisons)


RS232 EXAMPLE

 Here is an example of a data being transmitted using RS232 standard.



> If this data was sent using ASCII code, the sent data would be letter K

> LSB bit of data is sent first

UART EXAMPLE?
Well, its easy. you know that -12v means logic high and +12v means logic low. So redraw the above graph as graph with logic 1 and 0 and you get your UART waveform.

CONCLUSION
> Comparatively longer transmission is possible (12m-15m), because of high voltage
> Used for low speed communications
> The higher voltage levels of RS232 needs to be converted to TTL levels for use with common circuits (by using a MAX232 voltage converter IC)
> Higher speed requires other transmission formats like RS423
> One of the cheap and widely available communication methods
> 8-bit data and 9-bit data can be send using RS232
> It can have more than 1 stop bit (1.5, 2 stop bits)
> Parity bit provides as a source for error check, it can be Odd, Even

BONUS
There are a lot of MAX232 designs out there on the internet but few of them don't work. Well, I have tested this, so feel free to use it.
PS: you can find this in application circuit described in MAX232 datasheet



Comments

Popular posts from this blog

Robotics and Image processing!

 Back in 2012, we participated in an image processing robotics event at BITS pilani, Goa. The objective was simple: build a robot which would use video cameras mounted above the area to figure out height of 3 cylinders placed randomly and visit them one by one in descending order. We had our go at it with some basic matlab programming we learned over the course of 2-3 weeks. Please find the actual problem description, our approach and matlab scripts below. Problem description : click here Our solution :  click here for description click here for matlab code Lessons learned: - Matlab is too slow for real time navigation; we would have had better chances if we were able to modify our robot's firmware to accept a preset route and follow it. Open CV would have worked out much better here. - We would have discovered the frame-rate issue had we had developed a basic model and tried a test run. Keyword being 'test' here. More you test your system, more robust it becomes! Two aweso...

The first post & why Joy of Engineering?

Its my theory that all the knowledge we acquire becomes our toolbox & even the modest of things have an engineering aspect to it. I am a student of engineering and by extension a student of physics, chemistry and maths. I have often realised that even the silly stuff can be made better with engineering.  May it be a simple life hack to a very complex system that simplifies our day to day life, engineering is all around us. Have you ever enjoyed the joy of engineering something useful or something wonderful, or both? I hope that my later posts will be helpful and that it will help you find that joy of engineering.