Introduction to Serial Communications

Introduction to Serial Communications (RS-232)

So, you might think serial communications is dead.  A serial port is nowhere to be found on most of today’s motherboards.  After all, you can’t even buy a printer or a modem that works from the serial port of your computer anymore.  Webcams and Hard Drives are best connected through the USB port of a computer, and there’s no need for a serial port.  Its just too slow, too old, and too obsolete….and that is exactly the idea that has to be reconsidered.

Sure, Webcams and Hard Drives are best suited for a USB port, and you aren’t likely to ever find these kinds of devices with a serial port. But that doesn’t make the technology obsolete, stagnate, or dead.

It may surprise to learn that serial communications is far from dead. In fact, its bigger now than it ever has been, and it continues to grow at an exponential rate. Serial communications is actually more alive today than ever. SERIAL IS THE MOST SUPPORTED COMMUNICATIONS FORMAT IN HISTORY….PERIOD.

And while it has lost its home on today’s motherboards, it has gradually found a new home in embedded computers and microprocessors. A home that is firmly seated, with a standard that will NEVER become obsolete.

It is safe to say, there are more serial protocols in daily service than there are Ethernet cards, Routers, Hubs, Wi-Fi networks, and even Cell Phones….COMBINED! While I know this is a bold statement, lets take a look at the technologies where serial communications is still VERY ACTIVE.

Just about every microprocessor produced has a hardware device built in called a UART (Universal Asynchronous Receiver Transmitter)…and you guessed it, the UART is a technical name for a serial port. When coupled with a line driver chip (such as a MAX232 chip), you have the makings of a RS-232 port. So, just about every programmable microprocessor produced has hardware provisions for serial communications….and that is a LOT of chips, and this alone annihilates all the other communication standards in daily service, combined.

Serial communications has made its home in embedded applications for good reason. It is very easy for microprocessors to communicate with each other using serial communications. In addition, many LCD displays are interfaced to a microprocessor using serial communications, so are keypads, embedded GPS modules, touch screens, accelerators, and many of today’s sensors are supporting serial communications. And it may surprise you to learn that USB, Bluetooth, ZigBee, Wifi, and Ethernet also support serial communications.

It would be inappropriate to think of serial communications as a competitor to other communication technologies, such as USB, Bluetooth, ZigBee, WiFi 802.11 and Ethernet. Instead, think of serial communications as the glue between these interface technologies and embedded microprocessors. Serial communications actually makes it easy to interface to these other technologies, and is best viewed as a companion to other connectivity options, rather than a competitor.

The Virtues of Virtual COM

If you are a software developer, there is no kind of device that is easier to write programs for than a serial device. Try writing a program that talks directly to the USB port, or even through a network port. You have to have extensive training to understand how to talk to these kinds of devices. And even with such knowledge, you will spend many hours writing error free software. That’s where Virtual COM is going to save you a lot of time. Again, serial communications is the glue that ties these kinds of technologies together, making these technologies very easy to implement, and very accessible for the casual programmer. So today’s serial communication technologies have found a home in making your peripheral devices easier to program, and here is a backdoor view of how an old standard has blossomed into today’s world of embedded control:

USB and Virtual COM: The USB Serial Port

When you plug in USB to Serial adapter, a COM port is mounted on your computer. If you look inside your device manager, you will see the new COM port listed. You can then plug in any serial device into the COM port, open the COM port, and talk to the device as though it were directly plugged into a REAL RS-232 Serial Port connected to the motherboard of your computer. You will spend about 5 minutes installing USB Virtual COM drivers. If you are a proficient programmer, you will spend 5-10 minutes building an application that communicates to the new Virtual COM port. And there you have it, a serial device is easily programmed using the convenience of the USB port using a Virtual COM port.

Many of the devices we currently manufacture offer a USB to Serial Converter chip directly on-board. The programs you write will talk to our device at 115.2K baud. Using the USB Virtual COM drivers, you are also able to configure the COM port assigned by the operating system to the device. You can control multiple devices by communicating to multiple COM ports.

Ethernet, WiFi, and Virtual COM: The WiFi and Ethernet Serial Port

It may surprise you to learn that it is very easy to communicate to any of our network devices using WiFi or Ethernet connectivity in conjunction with Virtual COM software. In fact, its surprisingly easy. NCD devices use WiFi and Ethernet interface modules manufactured by www.digi.com. Digi has a free program on their web site called “RealPort”. When you plug in and power up one of our network devices, the device automatically determines the IP address using ADHOC. If you don’t know what that means, then don’t worry about it. Just install RealPort. RealPort will locate the network device on your network and assign it a virtual COM port. Once assigned, you guessed it, just spend about 5 minutes writing a program that opens the virtual COM port and start sending commands to talk to our device. It takes about 5 minutes to install RealPort. It will take you 5-10 minutes to write a simple program to talk to our device. And there you have it, a serial device easily programmed using the convenience of Ethernet and WiFi connectivity.

ZigBee Wireless and Virtual COM: The Wireless Serial Port

Of all the wireless technologies ever produced, few seem to be more at home with serial communications than the ZigBee wireless protocol. In fact, ZigBee should be thought of as wireless serial device…but you really don’t have a clue that its wireless, and you don’t have to do anything special to implement this incredible new wireless standard.

Since ZigBee is a wireless standard for embedded control applications, you are going to need a device called a ZigBee Modem. A ZigBee modem plugs into your computer and allows your computer to transmit and receive wireless data to many ZigBee devices within radio range…in some cases, this can be up to a mile! ZigBee modems are typically available as RS-232 Serial Zigbee Modems or USB ZigBee Modems. We only offer the USB variety, since we can take advantage of the USB port to power the ZigBee transceiver. Our ZigBee modems plug into the USB port and mount as a COM port on your computer. All you have to do is open the COM port and send a few bytes of data to control the remote device.

If there are many ZigBee devices in the area, you can send AT (terminal style) commands to tell the ZigBee modem which device you want to communicate with. Each device has a fixed serial number, printed on the bottom side of the removable ZigBee module. These AT commands do not interfere with communications to other remote devices.

Technically, ZigBee has two forms of communications. It has a serial interface used to talk to your computer, and it also uses serial data for wireless transmission. The user even has the ability to program the Wireless Data Rate as well as the data rate for communications to the computer (both are standard baud rates).

Bluetooth and Virtual COM: The Bluetooth Serial Port

You’ve seen it everywhere. Bluetooth Headphone, Bluetooth Keyboards, Bluetooth Mice, Bluetooth Phones, Bluetooth PDAs, Bluetooth, this, that and the other thing. You even see people walking around with these funny little things sticking out the side of their head with a flashing blue light (you know who you are), and they all say Bluetooth.

So what’s all the hype about Bluetooth? Well, for starters, Bluetooth is a great way for small computers to talk to small devices within a short range. The communications rate is surprisingly fast, very reliable, and provisions have been made to correct data communication errors. Oh, and let me repeat myself on this one, Bluetooth is one of the fastest wireless protocols you are going to find. And you guessed it, its virtually everywhere, supporting virtual COM ports, on virtually every programmable Bluetooth device ever made.

What this means for you is that you can use your PDA and Laptop (or other programmable Bluetooth devices) to talk to our device as though it were plugged into a serial port on the computer. But in reality, its all wireless, and it is just as easy to use as a real serial port.

Once you have paired a NCD device to the Bluetooth adapter of your favorite laptop or PDA, you are immediately ready to begin talking to the device as though it were physically connected. No drivers required (your computer or PDA already have COM port drivers built in for Bluetooth serial devices…guaranteed).

Serial Communications: A Growing Technology

So now that you have seen just how prominent Serial Communications really are, I think you will agree, Serial is supported as a communications protocol across all major connectivity options. It it weren’t still needed, it would not be so widely supported by every new communication technology ever invented. Its safe to say, serial isn’t going anywhere, and it can be relied on for many years to come with a growing fan base for embedded applications.

Learning to Use Serial Communications

While this is not the place to get into an elaborate discussion of the technicalities of serial communications, this is a place to introduce the basic concepts as they pertain to the use of our products. You can clearly see why it would be prudent to learn how to implement serial communications, and we will offer tutorials on the specifics as it becomes appropriate. But here, I want to elaborate on the highlights of serial communications, specifically as it applies to the use of our products. There are a few concepts you need to know about before you go too much further, saving the tutorials for another article.

What is a COM Port?

A COM port is a communications port. Any serial device must be assigned a COM port. If your motherboard happens to have a built in serial port, it usually has COM 1 available. If the motherboard of your computer has two built in serial ports, it usually has COM 1 and COM 2 available for communications. When you plug in a USB to Serial Adapter into your computer, another COM port is mapped into your computers list of available COM ports. Depending on the USB driver, it may be possible to change the COM port that is assigned to the USB to Serial Adapter. Many USB to Serial Adapters are assigned COM 3 through COM 255. Basically, a COM port is a physical or virtual serial port, available for serial communications. You can see the list of available COM ports in Windows XP by Clicking the Start Menu : Control Panel : System : Hardware (tab) : Device Manager (button) : + Ports (COM & LPT). In this box, a list of available COM ports will be displayed. If the COM port is not shown, it is NOT available for communications.

What is a Baud Rate?

Baud Rate is the speed of communications between the computer and the NCD device. Some NCD serial devices support 9600 baud or 38.4K baud as the default data rate. WiFi, Ethernet, Bluetooth, and ZigBee devices benefit from higher speeds, and are operated from a default baud rate of 115.2K Baud.

Physical Serial Ports vs. USB to Serial Adapters

RS-232 Serial is what I would call a relatively loose standard. By that I mean, the electrical implementation of the RS-232 specification is can be different between different types of computers. For instance, not many people know this, but desktop computers tend to put out a higher voltage RS-232 serial signal than Laptop computers, USB to Serial Adapters, and Embedded computers. In fact, it is this difference that has forced us to implement a PC/MAC jumper on many of our early optoisolated devices. But for the most part, there is no other difference between these devices. They all work the same way, they support the same baud rates, and they all do the same thing…make it easy to control embedded devices.

What is Serial Communications (with regard to NCD devices)?

Serial communications is described all over the internet in great detail. I will not rehash the specifics of serial communications, but I will explain what it is and how it is used with regard to NCD devices. There are books written on this subject, and far better reference guides that expose all the nuances of this popular standard. But for our purposes, there are 3 wires that are used to handle serial communications. There is a ground wire, a transmit wire, and a receive wire. If you are using a device with a USB interface, these 3 wires are connected between the USB interface chip and the microprocessor we use on our products. The same is true for Bluetooth, Wifi, Ethernet, and ZigBee devices. The RS-232 versions of our controllers require these same three wires to be connected to a computer for proper communications. So physically, you are using these three wires to communicate data to and from a microprocessor. I call this the physical layer, meaning the physical hardware implementation of the serial protocol. Lastly, there is the software layer. The programming that communicates these data to and from the microprocessor. We support 8-bit serial communications. This means our controller can accept the numbers 0 to 255 as commands. The speed at which these numbers are transferred is called the baud rate. The baud rate of the computer MUST MATCH the baud rate of the Microprocessor. The COM port determines where the serial device is physically connected to your computer. The only thing left for your program is to send the numbers 0-255 in a structure that matches the various commands of our device. For instance, sending the numbers 254, 108, 1 turns on the first relay in bank one of any of our ProXR series relay controllers. Different number combinations do different things. These number combinations are shown extensively throughout our product manuals.

Electrically, serial communications is a series of 10 pulses. A start pulse (called a start bit), 8 data bit pulses (8 data bits), and a “Break” pulse (called a stop bit). Every time you send a number from your program to our device, the number is formatted with a start bit, 8 data bits that represent a number, and 1 stop bit (which allows the controller time to accept the incoming data). Again, there are far more elaborate explanations of serial communications, but that’s all the basic information you need before you start getting into some actual applications.

Advantages of RS-232 Communications Disadvantages of RS-232 Communications
Extremely Easy to Develop Software Applications Distance is Impacted by Baud Rate
Capable of 1000′ Communication Range at Low Baud Rates Limited Data Rate
Supported by virtually all Hardware/Software Platforms 8-Bit Data Path (mostly)
Only 2-Wires Required for 1-Way Communications. Only 3-Wires Required for 2-Way Communications. Not the most ideal solution for multi-drop networking.
Resistant to EMI and Other External Interference
Very Reliable, Ideal for Low-Speed Control Applications
Lowest Cost of All Hardware Communication Methods