USB vs. RS-232

By Erich Styger

USB (Universal Serial Bus) has been developed in the mid-1990s and is everywhere, at least in the ‘desktop’ world. Still many embedded designs are using RS-232/Serial connectivity to communicate with the outside world. So what is better? USB or RS-232?

RS-232

RS-232 has been introduced in the 1960′s for teletypers. The standard defines the pin numbering, meaning of signals and the connectors (9-pin or 25-pin connector). For a minimal unidirectional communication, only 2 wires are needed (TX/RX and GND). For a bidirectional connection, at least 3 wires are needed (TX, RX and GND). RS-232 has been available on many computer system and is commonly known as ‘serial port’. Because of the simplicity of the protocol, many embedded devices have an UART integrated. As the microcontroller typically does not provide the higher voltage levels as defined in the standard, an additional line driver as the MAX232 is needed to communicate with devices over a larger distance.

Implementing a communication between two devices with an UART and RS-232 is simple, typically a few hundred bytes of code are needed. But except for very few applications (e.g. modem AT commands), the communication protocol is not defined, and the user needs to know details like low level communication details (baud, start/stop/data bit) and even the physical port wiring (DTE or DCE device). RS-232 has the option of handshaking, but this is not implemented in every device. This makes interoperability of RS-232 devices a challenge.

Because new host machines do not have a serial port any more (they have USB), there are many ‘Serial-to-USB’ bridges available, either as ‘dongle cables’ or as chip sets which can be used with microcontrollers which do not implement USB on the device.

USB

The Universal Serial Bus (USB) was meant to replace serial and parallel ports used by computers, among other devices. The standard defines the physical connections, cables, connectors and the communication protocol. In its common implementation, it needs four wires: Ground, 5V, D+ and D-. With this, the USB cable can provide power to the target, within the specification which is typically 500 mA. That makes it ideal to power small embedded devices. With the standardization on the connector, USB is a viable way to power and charge small devices, even if the device is not using USB for communication. The industrialization of USB allows low prices for power supplies, cables and connectors.

To operate USB on a microcontroller, a USB stack is needed. Because of the universal design and flexibility, such a USB stack is rather complex, and a typical implementation is in the range of 10-30 KBytes of code, making it a non-trivial implementation. Additionally the variances on the host side despite the standard definition makes it challenging. But once USB is working for an embedded device, it is very versatile and powerful. And there is one dedicated USB class which is intended to replace normal serial communication (as found in RS-232): the USB CDC (Communication Device Class). Beyond this, USB provides the ability to implement multiple device classes in a single device, and to connect to multiple devices the same time (USB Hub Class).

Comparison Table

USB RS-232
Wires
4
2-10
Communication Protocol
standard
only low level defined
Connector footprint
small
large
Power
yes
no
Software stack size
large
small
Handshaking
built-in
only with CTS/RTS wires
Interoperability
yes
no
Multi-Device connections
yes (hub)
not defined

 Conclusion

USB is very versatile and powerful: it defines many different communication classes (both as device or as host), is able to power a device through the cable, and provides different speed options. But that versatility makes it more complex too, and the implementation in an embedded device depends on the quality of the software stack used.

Despite the fact that new PC machines today do not have a serial port implemented, using the RS-232 for an embedded device still makes sense. It is simple and very low cost to implement.

As an alternative, a dedicated device as ‘RS-232-to-USB bridge’ can be considered, see this post. While both RS-232 and USB provides connectivity to a device, an alternative connection method like Ethernet should be considered today as an option. But that would be a different topic for a post in this blog :-) .

Sources

Happy Delting :-)

Erich Styger is an embedded systems professional that splits his time between the Lucerne University of Applied Sciences and Arts and Freescale. You can follow his experiments by following his own blog, mcuoneclipse.com.

    Leave a Reply