last updated: 2020-10-09
Song of this chapter: Interface > Angels in Disguise > Angels in Disguise
The word "interface" can refer to many things. One definition in the dictionary is:
The place at which independent and often unrelated systems meet and act on or communicate with each other.
We will look here at hardware interfaces mostly used by microcontrollers (or computers) to interact with internal or external devices, buses or networks. So we use here more the electrical and physical definition of interface. In the real world the word "port" is used interchangeably for interface (e.g. USB interface or port). If we look from the networking side it is better to distinguish both. A port resides at layer 1 of the OSI model (physical layer) and the interface resides more at layer 2 of the OSI model (data link layer).
Most interfaces need beside the physical definitions a communication protocol to be able to transmit data. A protocol (e.g. TCP or SMTP) is a set of rules and procedures needed for the communication and can be implemented in hardware or software. Protocols need to be standardised, so that devices from different manufacturers can communicate.
An interface is an endpoint, and endpoints are connected together via a bus. The bus carries the signals (data).
Electrical connectors are often a part of the physical interface and they often help to identify the interface.
Interfaces can be categorised using the following characteristics:
The continuously improvements of electronic components (e.g. accuracy, speed) and data processing leaded in the past decades to digital and serial interfaces.
Analog interfaces are seldom used today. Parallel interfaces are used when very high speed is needed (internal buses in microcontroller or computer) but also seldom as external interface.
Serial means that the data is sent spread over time (time-division multiplex), most often one single bit after another.
The mechanical properties are important and can determine if an interface will be accepted an spread. As an example for USB, the standard connectors were designed to be more robust than many past connectors. USB would not be so successful if the connectors would be less robust.
The benefit of digital signals is that they can be processed and transmitted without introducing significant additional noise or distortion. Degradation can even be detected and corrected.
In a serial transmission the data is transferred bit by bit from the sender
Tx to the receiver
Rx over one data line. With the help of shift register (see MICSY) the parallel data is converted to a serial stream. The data clock is normally generated by the sender. The receiver will re-transform the serial data stream to the parallel data, also with the help of a shift register.
The clock generated by the sender will define the bit rate (number of bits send per unit of time) in bit/s (bits per second). Normal rates begin at 9600 bit/s to Gbit/s (normally here the metric prefixes are used so G for one billion bits/s).
The big benefit of serial interfaces is the low wire respectively pin counts (cheaper and better handling). Serial communications can be performed with just two wires or one I/O pin. Serial communication can reach long distances, and we get less crosstalk and no clock skew (for asynchronous communication)).
Some examples of digital serial hardware interfaces:
USB, Firewire, TIA-232 (formerly RS-232, EIA-232 oder V24), TIA-485 (formerly RS‑485, EIA-485), I2C, SPI, S-ATA, PCI-Express, HDMI, DisplayPort, IrDA, Bluetooth, CAN (automotive), S0 (ISDN), MIDI, S/P-DIF, , Ethernet, WLAN, A2DP via Bluetooth, AC'97, ADAT Lightpipe, AES3, AES47, I²S (Inter-IC sound), MADI (Multichannel Audio Digital Interface)
In serial communication the receiver must sample the signal at the same time intervals used by the transmitter. This can be achieved asynchronously or synchronously, so we distinguish the asynchronous and the synchronous serial communication:
In asynchronous serial communication the sender and receiver are not continuously synchronized by a common timing clock signal. So the synchronization information has to be contained in the data stream. This is done normally with start information (e.g. start bit) at the beginning and stop information (e.g. stop bit) at the end of the stream.
A good example of asynchronous serial communication is the keyboard of a PC. Data is only sent if the user hits a key.
Asynchronous synchronisation will only work when sender and receiver use the same signalling parameters like the number of bits per character (including parity info), the number of stop bits, the bit rate ....
In synchronous serial communication, often a second wire is used to add a clock signal (sometimes named strobe) that helps the receiver to stay synchronised with the sender (same bit rate) and so sample the signal at the same time intervals used by the sender.
The synchronisation can also be maintained with the help of extra information in the data stream used to synchronize both clocks. This can be a predefined sequence of bits or bytes at the beginning of a block or a coded data stream containing clock information. In synchronous synchronisation it is possible to adapt the bit rate. Normally a buffer is needed because a certain amount of data is used to built a block.
The advantages of asynchronous communication are that it is simple, cheap (simple hardware) and optimal for a communication that pauses a lot. The disadvantage over synchronous communication is the overhead (e.g 10 bit for 8 bit pf data) which makes the communication slightly less fast.
In simplex communication is only in one direction: one device transmits and the others listen (e.g. radio and television broadcast).
In point to point duplex communication two connected devices can communicate with one another in both directions. We distinguish full-duplex (FDX) and half-duplex (HDX). In full-duplex both devices can communicate with each other simultaneously (e.g. telephone). In a half-duplex both devices can communicate with each other only alternately in time (e.g. push-to-talk walkie-talky).
In point-to-multipoint networks (e.g. cellular networks (UMTS, DECT, VDSL)) the forward and reverse communication channels have to be divided on the same physical communications medium. Time-division duplexing (TDD) and frequency-division duplexing (FDD), also named time-division multiplexing (TDM) and frequency-division multiplexing (DDM) can be used.
In TDM synchronized switches at each end of the channel make appear each signal a fraction of time in an alternating pattern (e.g. used in digital telephony). In FDM the total bandwidth of the channel is divided into non-overlapping frequency bands which are used to carry separate signals (e.g. used in radio and television broadcasting).
If two interfaces are connected directly together we call them point-to-point or peer interfaces. In a peer relation there are no masters or slaves. Peer interfaces are most often asynchronous (e.g. TIA-232).
If more interfaces share the same medium, we call this a bus. The time in communication must be shared. This is normally done by a master. The other devices are called slaves. Each device has an individual address. Master/slave buses (e.g. I2C-Bus, SPI) are often synchronous and it is the the master that supplies the timing clock signal.
There exist also multi-master buses. An arbitration scheme must take care of conflicts (two masters need the bus at the same time).
For reliability and security reasons data communication over wire is always preferable to wireless communication. This is why enterprises stay resolutely wired.
Reliability and speed:
Cable or even glass fiber with enough bandwidth primes over wireless with a bandwidth that must be shared between all devices. Speeds are much higher than with a wireless connection. Radio links are not stable and can be disturbed easily by outside influences, such as walls and floors, moving people as well as other electronic items. The range of a wireless access points fades the further away from it you are. To ensure full, reliable coverage plenty of access points must be installed (costs, electromagnetic pollution).
Control and security:
With a physical connection needed to access a network (over a secured device), the owner or maintainer is in full control of who and what gets online and the network will not be overloaded with useless critical traffic. With wireless devices the threat of malware getting into the network is higher, because your network will extend beyond the physical walls of your building.
We will look at the wireless protocols in a later chapter.
Other criteria could be:
An interesting article about this criteria can be found here.
In IoT devices microcontroller communicate with sensors or other devices. Often in IoT projects the microcontroller is chosen depending on the disposable interfaces. Interfaces integrated in hardware are always preferable to software only solutions (.e.g. Softserial). They are more stable and use less of the microcontroller resources. Here some of the most important hardware interfaces used by sensors and microcontroller:
This interface formerly known as
RS-232 is one of the oldest interfaces (1960!!) in use and its importance doesn't diminish even with its limited speed. In the contrary its simplicity assured the continued existence.
TIA-232 uses today normally only two wires Tx and Rx (duplex, three including GND) and is used for communications between just two devices. In special cases supplementary handshaking wires are used for control of data flow. In modern microcontroller one to six UART or USART (hardware device for serial communication) are implemented for serial communication.
The communication is asynchronous, full duplex and typical speeds range from 9600 bit/s to 115200 bit/s. TIA-232 is often used for long (tens of meters), inter-equipment links with a voltage of ± 12V. For this it needs a level converter like the MAX232.
I²C (Inter-Integrated-Circuit) was developed by Philipps (now NXP) intended for communication between IC's in Audio and Video devices. It is a synchronous, half-duplex interface on a (multi)master/slave bus. Many special IC's can be used directly on this bus. The IC's have an own selectable address. More than one master can be used on the bus (multi-master). I2C is a superset of the Intel's SMBus.
We get two open drain lines: serial clock (SCL) and serial data (SDA) (3 wires including GND). Standard bit rate is 100 kbit/s, but today often the faster 400 kbit/s are used. Higher speeds (1 Mbit/s, 3.4100 Mbit/s) are possible but reduce the length of the connecting wires.
On AVR controller the interface is called TWI (two-wire-interface).
SPI (Serial Peripheral Interface) was developed by Motorola for communication between microcontroller. So high speed (> 10 Mbit/s) with short connections is possible. It is a synchronous, full-duplex interface on a master/slave bus.
Three lines are needed for the communication: serial clock (SCLK/SCK/SCL), serial data in (SDI/MISO master in slave out) and serial data out (SDO/MOSI: master out slave in). SPI has no device addressing, so in addition to the communication lines one or more selection lines (one for each slave) named slave select (SS) are needed. This makes min. 5 lines including ground, with one slave.
TIA-485 is a standard and defines the electrical characteristics of balanced signalling drivers and receivers in serial communications systems. They can cover long distances (typical: 35 Mbit/s at 12 m and 100 kbit/s at 1200 m) even in electrically noisy environments and allow multiple receivers (32 loads per bus) on a linear, multidrop bus. TIA-485 is often used in an industrial environment. TIA-485 does not define a protocol but only the electrical characteristics, so even similar devices from different manufacturers are not compatible due to a proprietary protocols. IC's like the MAX485 make it easy to implement TIA-485. TIA-485 is sometimes combined with the protocol of TIA-232 to get a serial connection with greater distances than TIA-232.
1-Wire is a device communications bus system designed by Dallas Semiconductor. It is similar to I²C but slower and covering bigger distances (up to 750 m). It is possible to use only 1 wire (2 wires including ground) because power can be delivered over the data line. A popular IC using this bus is the DS18B20 temperature sensor.
The Controller Area Network (CAN) bus was developed and launched by Bosch in 1986. CAN 2.0 (1991) is used mostly in cars (automotive) for communication between microcontrollers, sensors and actuators. It is a multi-master protocol where the data is transmitted without a clock signal in an asynchronous format. All devices (called nodes) are synchronized to sample every bit on the CAN network at the same time. CAN uses twisted pair wires with a 120 Ω characteristic impedance.
The CAN protocol is robust (secure), efficient, flexible and low-cost and is standard in all vehicles, ships, planes, but expands to newer fields like EV batteries, industrial machinery, drones, radar systems, autonomous connected vehicles and even to connect IoT devices. The new CAN FD (Flexible Data Rate) will make CAN more flexible with data transmission up to 8 Mbit/s and packets of 64 bytes (instead of 8 bytes). There exist microcontroller with integrated CAN controller, and breakout boards to add CAN to microcontroller.
The Universal Serial Bus (USB) standard is an industry standard and exists since 1996. The bus was improved over the years, increasing its popularity. Even if now the fourth generation USB 4.x is used for computers, on microcontroller, we use the first or second generation. USB can be complicated to implement on microcontroller because of its vast software stack. Controllers like ATmega32u4 (Arduino Leonardo, Teensy 2.0) have hardware USB (device) and can be used because of the existing libraries. USB as host can also be implemented on newer controller.
USB is often used in combination with USB to TIA-232 adapter (often included in cables) using FTDI or Profilic IC's (FT232BM, PL2303).
As USB, Ethernet needs a complex stack (TCP/IP) and is til now not often implemented in microcontroller (e.g. PIC18F97J60 from Microchip). With supplementary IC's like the ENC28J60, W5100 or W5500 (Arduino Ethernet shield) and the corresponding libraries it is possible to connect a microcontroller to a wired Ethernet.
The Chinese firm Espressif made WiFi on microcontroller possible by implementing the stack on cheap microcontroller like the ESP8266 or the ESP32. The porting of the development software to Arduino helped to increase the popularity of these chips.
Another wireless protocol is Bluetooth. Bluetooth is interesting for microcontroller and IoT since Bluetooth 4.0 that includes Bluetooth Low Energy (BLE). The Espressif chip ESP32 includes BLE.
Other wireless protocols like Z-Wave, LoRa or XBEE will be covered in a later chapter.
Here is a rough comparison table for the 5 interfaces. If you want to choose an interface for a project it is important to look at the details!
|wires (no ground/Vcc)||2 (Rx, Tx)||2 (SCL, SDA)||min. 4 (MISO, MOSI, SCL, SS)||2 (D+, D-)||2 (CAN H+, CAN H-)|
|bus||point to point||(multi)master/slave||master/slave||master/slave||(multi)master/slave|
|bit rate [Mbit/s]||slow (0.1152)||limited (0.4)||fast (10)||real fast (480)||limited (1)|
|distance*||20 m (1200 m with TIA-485 )||1 m||less than 1 m||1 m-3 m||100 m|
|costs||lowest cost||low cost||low cost||low cost||expensive|
* the distance heavily depends on the used cables and speed, so the values are only roughly approximate.