Low Speed Digital Interface Basics
Introduction
Inter-IC communication (IC-IC) has been established and evolved since the early days of electronic design. Several of these basic interfaces have stood the test of time and have been widely adopted across the electronics industry. We will examine a few basic and popular interfaces, such as I2C, SPI, and UART, that are used in almost any embedded system today.
Background
Digital communication largely fulfills two goals: sending instructions (i.e., control commands) and transferring data.
Control commands initialize and configure devices for operation.
Transferring data between on-board memory and peripheral devices is necessary for keeping an embedded system running as intended.
I/O Output Type
Open-drain: An I/O output design that uses an external resistor to pull the interface to logic high and the internal NMOS transistor to drive the interface low.
Push-pull: An I/O output design that uses a complementary pair of PMOS and NMOS transistors to drive the interface to logic level high or low.
Data Transfer Structure
Serial: Data is sent and received one bit at a time in a sequential manner.
Minimal communication interface and logic are needed, but at the expense of lower data rate.
Parallel: Data is sent and received in multiple bits at a time in a parallel manner.
Higher data rates can be achieved, but at the expense of a more complex communication interface and logic.
Data Transfer Technique
Synchronous: Data is transmitted and received with a clock signal in a fixed time interval.
Source synchronous clocking: The transmitter device generates the clock needed for synchronous communication. This clocking technique is widely used in practice.
Asynchronous: Data is transmitted and received without a clock in a random time interval.
Detailed Interface Descriptions
I2C
Main Purpose
I2C (Inter-Integrated Circuit) is a synchronous, half-duplex, serial communication bus that is commonly used for issuing instructions and establishing handshakes. It can also be used to transfer data, but it is typically used for slow output data devices such as sensors.
Main Features
Supports multiple master and slave devices on one I2C bus.
Half-duplex: Data can be transmitted or received, but not both at the same time.
Slow data rate: Typical data rates are 100 kHz to 400 kHz.
Open-drain output: The output drivers of I2C devices are open-drain, which means that they can only pull the bus line low. This allows multiple devices to share the same bus without conflict.
BUS Pins
SDA (Serial Data): This pin is used to transmit and receive data.
SCL (Serial Clock): This pin is used to synchronize the data transfer.
Protocol Basics
I2C communication is based on a simple protocol that consists of four types of messages:
Start bit: This bit signals the beginning of a message.
Slave address: This bit indicates the address of the slave device that the message is intended for.
Command/data: This bit indicates whether the message is a command or data.
Stop bit: This bit signals the end of a message.
7-bit slave addressing
I2C devices are addressed using a 7-bit address. This allows for 128 (2^7) unique slave addresses. However, in practice, it is not practical to have all 128 addresses on one bus due to limited bus bandwidth.
8-bit packet frame
Each I2C message consists of an 8-bit packet frame. The packet frame is structured as follows:
Start bit (1 bit)
Slave address (7 bits)
R/W bit (1 bit)
Data byte (8 bits)
Stop bit (1 bit)
Arbitration
If two master devices attempt to access the bus at the same time, a process called arbitration is used to determine which device will have control of the bus. Arbitration is based on the principle of "first come, first served."
Slave clock stretching
If a slave device needs more time to process the current data before the next data frame is transferred, it can stretch the clock. Clock stretching is done by the slave device holding the clock line low until it is ready to continue.
Helpful Software Debug Tools
There are a number of software tools that can be used to debug I2C communication. One popular tool is the i2c-tools package, which is available for Linux. This package provides a number of commands that can be used to read and write data on the I2C bus, as well as to query the status of the bus.
Debug Hardware Tools
A I2C logic analyzer can be used to sniff, read, and write on I2C bus. Two popular logic analyzers are the Salae logic analyzer and the Aardvark I2C/SPI Host Adapter. These logic analyzers come with their own analysis software that can be used to view and analyze I2C traffic.
SPI
Main Purpose
SPI (Serial Peripheral Interface) is a synchronous, full-duplex, serial communication bus that is commonly used for transferring data. It is typically used for high-speed data transfer applications, such as connecting memory chips and flash drives.
Main Features
Full-duplex: Data can be transmitted and received simultaneously.
High data rate: Typical data rates are 20 MHz to 50 MHz.
Push-pull output: The output drivers of SPI devices are push-pull, which means that they can both pull the bus line low and push it high. This allows only one driver per data line, which avoids bus contention.
BUS Pins
MOSI (Master Out Slave In): This pin is used to transmit data from the master device to the slave device.
MISO (Master In Slave Out): This pin is used to receive data from the slave device to the master device.
CLK (Clock): This pin is used to synchronize the data transfer.
CS (Chip Select): This pin is used to select the slave device that the master device is communicating with.
Debug Hardware Tool
A SPI logic analyzer can be used to sniff, read, and write on the SPI bus. Two popular logic analyzers are the Salae logic analyzer and the Aardvark I2C/SPI Host Adapter. These logic analyzers come with their own analysis software that can be used to view and analyze SPI traffic.
UART
Main Purpose
UART (Universal Asynchronous Receiver/Transmitter) is a simple, asynchronous, serial communication protocol that is commonly used for sending control commands and loading small firmware to devices. It is typically used for debugging purposes, such as connecting a PC to a microcontroller to send commands and view the output.
Main Features
Asynchronous: The data transfer is not synchronized with a clock signal. This means that the sender and receiver must agree on the data rate, packet length, and stop bits.
Slow data rate: Typical data rates are 9600 baud to 115200 baud.
No clock interface: The clock signal is not provided by the UART protocol. This means that the sender and receiver must generate their own clock signals.
BUS Pins
TX (Transmit): This pin is used to transmit data from the host to the device.
RX (Receive): This pin is used to receive data from the device to the host.
Helpful Serial Terminal Application
Coolterm: This is a free serial terminal application that can be used to view and send data on a UART port.
Debug External Hardware Interface
UART to USB Bridge: This device can be used to connect a UART port to a PC via USB. This allows you to read and write data on the UART port from a PC.
Example Cable: A 3.3V logic level FTDI UART to USB cable is a popular option for connecting a UART port to a PC.
Q&A
Q What affects the length of interconnects?
A: The length of interconnects is affected by two factors: line capacitance and signal reflection. Line capacitance is the capacitance between the signal line and ground. Signal reflection is the phenomenon where the signal bounces back from the end of the interconnect.
A: For I2C and UART, the trace can be long (multiple 10s of cm range) due to the lower clock speed in the kHz range. The line capacitance and signal reflection are not as significant at these lower frequencies.
A: For SPI, the trace needs to be shorter (in the cm range) due to the higher frequency clock speed in the 10s of MHz. The line capacitance and signal reflection become more significant at these higher frequencies, and can cause errors in the data transmission.
Q How do I adjust drive strength to improve signal integrity?
A: Drive strength is the ability of a driver to push current onto a line. The higher the drive strength, the shaper the rising edge, however, too strong of a drive strength can introduce ringing to due high edge rate. Care must be taking in configuring the drive strength of an I/O.
A: For I2C, using a stronger pull resistor (i.e., a small resistor value in the kohms range) improves rising and falling times. This helps to reduce signal reflection and improve the accuracy of the data transmission.
A: For UART and SPI, an additional re-driver chip can be used. A re-driver chip is a device that amplifies the signal and re-times it to improve signal integrity.
Summary
Source synchronous clocking is widely seen in inter-circuit digital communication.
Asynchronous communication involves not using a clock as the data sync signal but rather on a predefined data rate, format, and starting and stop mechanism between two devices.
I2C and UART interface are used for control commands and slow data transfer.
SPI is used for higher data transfer.
Both I2C and UART are asynchronous communication protocols, while SPI is a synchronous communication protocol.
Conclusion
Slow digital interfaces are essential for all subsystems to initialize, handshake, and provide essential data for the entire system to work with each other.