Taillieu.Info

More Than a Hobby..

RS232 Communication – The Basics

RS232 is a asynchronous serial communication protocol widely used in computers and digital systems. It is called asynchronous because there is no separate synchronizing clock signal as there are in other serial protocols like SPI and I2C. The protocol is such that it automatically synchronize itself. We can use RS232 to easily create a data link between our MCU based projects and standard PC. Excellent example is a commercial Serial PC mouse (not popular these days, I had got one with my old PC which I bought in year 2000 in those days these were famous). You can make a data loggers that reads analog value(such as temperatures or light using proper sensors) using the ADC and send them to PC where a special program written by you shows the data using nice graphs and charts etc.. actually your imagination is the limit!

Basics of Serial Communication.

In serial communication the whole data unit, say a byte is transmitted one bit at a time. While in parallel transmission the whole data unit, say a byte (8bits) are transmitted at once. Obviously serial transmission requires a single wire while parallel transfer requires as many wires as there are in our data unit. So parallel transfer is used to transfer data within short range (e.g. inside the computer between graphic card and CPU) while serial transfer is preferable in long range.

As in serial transmission only one wire is used for data transfer. Its logic level changes according to bit being transmitted (0 or 1). But a serial communication need some way of synchronization. If you don't understand what I mean by "synchronization" then don't worry just read on it will become clear.

The animation below shows you how a serial transmission would look like (if you can see electricity).

rs232 communication  using USART of AVR MCU

Fig- A Serial Line.(HIGH=RED & LOW=WHITE)

 

Can you make out what data is coming? No because you are not synchronized. You need a way to know when a new byte start and when a bit ends and new bit start. Suppose the line is low for some time that means a '0' but how many zeros? If we send data like 00001111 then line is first low for some time and high after that. Then how we know it is four '0's and four '1's?

Now if we add another line called the clock line to synchronize you then it will become very easy. You need to note down the value of data line only when you see the "clock line" high. Lets understand this with help of an animation.

rs232 communication  using USART of AVR MCU

Fig- A Serial Line.(HIGH=RED & LOW=WHITE)

 

Now you can see how the "clock" line helps you in "synchronizing" the incoming data. In this way many serial busses like SPI and I2C works. But USART is different in USART there is no clock line. So it is called UART - Universal Asynchronous Receiver Transmitter. In USART a start bit and stop bits are used to synchronize the incoming data the.

RS232

In RS232 there are two data lines RX and TX. TX is the wire in which data is sent out to other device. RX is the line in which other device put the data it need to sent to the device.

rs232 communication  using USART of AVR MCU

Fig- RS232 transmission. The arrows indicates the direction of data transfer. In addition to RX/TX lines there is a third line i.e. Ground (GND) or Common.

 

One more thing about RS232. We know that a HIGH =+5v and LOW=0v in TTL / MCU circuits but in RS232 a HIGH=-12V and LOW=+12V. Ya this is bit weird but it increases the range and reliability of data transfer. Now you must be wondering how to interface this to MCUs who understand only 0 and 5v? But you will be very happy to know that there is a very popular IC which can do this for you! It is MAX232 from Maxim Semiconductors. I will show you how to make a level converter using MAX232 in next tutorial.

As there is no "clock" line so for synchronization accurate timing is required so transmissions are carried out with certain standard speeds. The speeds are measured in bits per second. Number of bits transmitted is also known as baud rate. Some standard baud rates are

  • 1200
  • 2400
  • 4800
  • 9600
  • 19200
  • 38400
  • 57600
  • 115200
  • ... etc

For our example for discussion of protocol we chose the speed as 9600bps(bits per second). As we are sending 9600 bits per second one bits takes 1/9600 seconds or 0.000104 sec or 104 uS (microsecond= 10^-6 sec).

To transmit a single byte we need to extra bits they are START BIT AND STOP BIT(more about them latter)Thus to send a byte a total of ten bits are required so we are sending 960 bytes per second.

Note: The number of stop bits can be one or two (for simplicity we will be using single stop bit)

There is one more bit the parity bit but again for simplicity we would not be using it)

RS232 Data Transmission.

The data transfer is done in following ways

Transmission

  1. When there is no transmission the TX line sits HIGH (-12V See above para) ( STOP CONDITION )
  2. When the device needs to send data it pulls the TX line low for 104uS (This is the start bit which is always 0)
  3. then it send each bits with duration = 104uS
  4. Finally it sets TX lines to HIGH for at least 104uS (This is stop bits and is always 1). I said "at least" because after you send the stop bit you can either start new transmission by sending a start bit or you let the TX line remain HIGH till next transmission begin in this case the last bit is more than 104uS.
rs232 transmission and reception  basics

Fig- Data Transmission on RS232 line.

 

 

Reception

  1. The receiving device is waiting for the start bit i.e. the RX line to go LOW (+12V see above para).
  2. When it gets start bit it waits for half bit time i.e. 104/2 = 51uS now it is in middle of start bit it reads it again to make sure it is a valid start bit not a spike.
  3. Then it waits for 104uS and now it is in middle of first bit it now reads the value of RX line.
  4. In same way it reads all 8 bits
  5. Now the receiver has the data.
rs232 transmission and reception  basics

Fig- How the Receiver receives the data on RS232 RX line

 

 

CARDS - WHAT ARE THE DIFFERENCES BETWEEN FAT16, FAT32 AND EXFAT FILE SYSTEMS?

The default formatting for cards up to 2GB is FAT16.

In recent years, memory cards have gained more storage capacity; 4GB and above. The file format FAT32 is now commonly used in memory cards between 4GB and 32GB.

If a digital device supports only the FAT16 file system you cannot use a memory card bigger than 2GB (i.e. SDHC/microSDHC or SDXC/microSDXC memory cards).

Integral memory cards of 4GB or more such as those in the CompactFlash i-Pro, UltimaPro and SDHC ranges are only supported by FAT32 devices and must be formatted to FAT32.

It is best practice to format the card in your device before use, CAUTION formatting a card will delete all data, please see your device manual.

 

 

  FAT 16 (FAT) FAT 32 exFAT (FAT 64)
Maximum file size 2GB* 4GB 2TB (limited by card)
SD Card type SD SDHC, microSDHC SDXC, microSDXC
PC Compatible OS Windows ME/2000/XP/7/8 Windows ME/2000/XP/7/8

Windows XP/Vista/7/8

Notes      Windows OS may require updates, please see Table 2 below
Mac Compatible OS  Mac OS 8/9/X  Mac OS 8/9/X Mac OS X 10.6.5 and above

 

*Recommended limit by Microsoft for compatibility but can be up to 4GB

Table 2

 

Windows XP Windows Vista Windows 7 and Windows 8
Update to SP2 or later, then apply Microsoft update (KB955704). Use with SDXC/microSDXC compatible card reader. Update to SP1 or later. Use with SDXC/microSDXC compatible card reader. Supported - no update required, use with SDXC/microSDXC compatible card reader.