The Celtic Engineer is a weekly newsletter produced by Celtic Engineering Solutions. We hope you enjoy it. If you have any suggestions for topics, would like to give feedback or want your email added to the distribution list please send an email to[email protected].
A string and two cans
If you have been around for a while I am sure you are intrigued about how I am going to cover all of serial communications in two pages. I want to identify the broad area known as serial communications and point out some of the architectures and then narrow to what most people think of a as serial communication, using a UART.
Doing a brief search I was able to identify over 30 protocols that claim to be serial. I have no doubt there are many more. Some of these include CAN, Ethernet, FireWire, I2C, MIDI, Morse code, RS-232, RS-422, RS-485 SPI and 1-wire. What all of these protocols have in common, and why they are called serial, is that the data is transferred one bit at a time. If it is not serial it would be parallel where multiple bits would be transferred simultaneously.
For many people who grew up as the PC was maturing the distinction is between a seral port and a parallel port. The serial port was originally RS-232. In today’s world microprocessors and microcontrollers are everywhere and a majority of them have a UART (Universal Asynchronous Receiver/Transmitter). These UARTs can drive a variety of devices including RS-232, RS-422 and RS-485.
Getting Hooked up
From the MCU point of view the signals are RX (receive) and TX (transmit). You also must share a common ground. That may be obvious but when you talk about 1 wire or two wire communication people often forget that there is a physical extra ground wire when you are running the cable. This can cause confusion.
The MCU connects to a driver chip that handles the electrical levels associated with the type of communication you will be doing (e.g. RS232 vs. RS485). But from the MCU side it is all the same. To send information you load an 8-bit character to the transmit register and away it goes. When you receive a byte, it arrives and the UART will put it into the receive register and set a bit so you know it has data. The devil, of course, is in the details. Setting up a UART, polling or enabling interrupts can take a good deal of time and planning. But once the upfront, hard, work is done, it really is as easy as passing data a byte at a time. The data that is most often passed is encoded as asci characters, but how you interpret the 8-bit data is really up to you.
The old version was called RS232. And it came with a host of other pins (on a 25 pin connector) to make sure the data flow was smooth and orderly. Today most people ignore those pins and just transmit and receive. The main problem with this protocol is its slow speed. The original drivers were +/-15 or +/-12. As technology progressed some manufacturers used lower voltages and labeled the devices as “RS232 compatible.” These devices generated +/-5V on the chip. The standard intended for the communication to be point to point. Multi-drop connections between more than two devices are not defined.
RS422 uses a maximum voltage of +/- 6V and transmits a differential signal. It can communicate with up to 10 receivers at a distance of 4900 feet. The cables are twisted pairs and the speed is greatly improved over the previous protocol, between 100kb/s and 10Mb/s. This is not true multipoint communication because there can only be a single driver on the twisted pair, but up to 10 receivers are possible.
RS485 is also a differential transmission with transmit distances and speeds similar to RS422 but while the RS422 transmitter cannot be turned off, the RS485 defines three states, one of which being high impedance. This allows individual transmitters to be turned off. Because of the high data rate and the ability to not drive the bus, the bus is typically terminated with a 120-ohm resistor (to minimize reflections) and a pull up resistor is placed on the positive line and a pull-down resistor placed on the negative line. If this were not done and no device were driving the line, connected receivers would interpret the resulting noise as a signal.
Help, I can’t find my serial port
Most laptops do not come with serial ports. To connect to a UART device you need to have a USB to Serial converter. They can be cheap and you get what you pay for, but for the most part they work. Silicon labs now has a serial to USB driver chip that can be placed on you PCB. With a driver on your PC you can connect to a “virtual comm port.” It acts like you are connected to a serial port but uses the USB port and protocol to get the data between the PC and the silicon labs chip. I have used them and they work great. The only complaint is the QFN package makes it very difficult for hand placement. It would be nice if they had a SOIC-8 package available.
This newsletter is sponsored by Celtic Engineering Solutions LLC, a design engineering firm based out of West Jordan, Utah, which can be found on the web at:www.celticengineeringsolutions.com. You can find the newsletter on the company blog, LinkedIn or by subscribing. Send your emails to The Celtic Engineer at: [email protected].