Mouser Left Banner
Mouser Left Banner
Mouser Left Banner
Mouser Right Banner
Mouser Right Banner
Mouser Right Banner

    Comparing common MCU interface protocols

    Microcontrollers (MCUs) continue to dominate embedded systems development and with good reason. They have a flexible architecture, are easy to program and exhibit low-power characteristics.

    Now over 40 years old, the MCU continues evolving to meet changing market demands. Example: Using MCUs for edge-based Artificial Intelligence (AI) is trending in Internet of Things (IoT) and Industrial Internet of Things (IIoT) applications.

    MCUs perform essential computational functions. They also communicate with and coordinate peripheral functions, such as sensors and wired/wireless transceiver ICs or modules. Some application requirements are more straightforward, like reading a switch to determine whether it is on or off or controlling an LED. Others require a more sophisticated interface allowing multiple peripherals to be serviced from a single port.

    Achieving this requires some standardization. MUCs are typically equipped with two types of interfaces: industry-standard serial buses and more generic pin-based input and output pins, or general purpose I/O (GPIO). While smaller devices may only offer limited I/O, many high-pin-count MCUs can integrate six or more serial peripherals and tens of GPIO.

    Serial bus communication interfaces

    The most popular MCU serial connections are inter-integrated circuit (I2C), serial peripheral interface (SPI) and universal asynchronous receiver transmitter/universal synchronous asynchronous receiver transmitter (UART/USART). These standard technologies enable data transfer between peripheral components in and between embedded systems using well defined communication protocols and physical interfaces.

    It has become common to integrate a serial interface into micro-electromechanical system (MEMS) sensors. A MEMS accelerometer may be equipped with an I2C or SPI bus interface so it can easily interface with a host controller. The sensor may include a deeply embedded MCU or application-specific IC (ASIC) that manages the digital domain. This digital element will interact with the physical MEMS element, transform the raw data into recognized formats, and manage communication with the embedded host MCU. Usually, all the connected devices are mounted on a single PCB, but most serial buses accommodate short-distance interconnect via suitable connections.

    The I2C bus

    The I2C bus is a widely used synchronous half-duplex open-drain serial communication interface developed by Philips (now NXP) Semiconductors in the early 1980s. It can support multiple controllers, such as MCUs, and multiple targets, such as sensors, wireless modules, and DC/DC converters, over relatively short distances of up to 30 cm. The I2C interface requires two wires–serial data (SDA) for data communication between the controller and target(s) and serial clock (SCL) for a shared clock signal to synchronize controller/target communication. The two-pin topology makes it simple and convenient to implement I2C and many applications use it in imaginative ways.

    The controller always initiates communication with a single target device, identified by a 7-bit address, permitting a maximum of 128 slave addresses on a single I2C bus. It is less common but possible to use 10-bit addresses. This allows more devices to be accessed and may be required in larger systems. The I2C protocol uses a standard data packet format, including start and stop bits, target address, a read/write bit, 8-bit data frames, and acknowledge/no acknowledge (ACK/NACK) bits.

    The I2C protocol standard supports multiple communication speeds, including standard mode (100 kilobits per second), fast mode (400 kilobits per second), high-speed mode (3.4 megabits per second), and ultra-fast mode (5 megabits per second).

    The SPI bus

    The SPI bus is also a multi-target synchronous serial interface, but unlike I2C, it operates in full-duplex mode and permits only a single controller. The target address selection occurs through a dedicated pin, sometimes termed Chip Select (CS). Each target device requires a unique select signal and accommodating full-duplex operation requires separate transmit and receive lines, making SPI slightly more complex to implement than I2C.

    The SPI bus has four defined signals with defined names. However, some products use non-standard names. The signal names are:

    • SCK: the clock used to synchronize communication; sometimes written as SCLK, SCL or CLK
    • MOSI (master out slave input): data from master to slave; sometimes SDO on controllers, SDI on target devices
    • MISO (master in slave output): data from slave to master; sometimes SDI on controllers, SDO on target devices
    • SS, CS or CE: the target (chip) select line; one required for each connected target

    There are no defined transfer rates; with data transferred in 8-bit blocks bit by bit, the maximum speed is more determined by the distance, with 50 MHz speeds possible over short IC-to-IC distances. Unlike I2C, the SPI protocol does not feature ACK/NACK or flow control start/stop bits.

    The UART interface

    The UART interface is one of the simplest standardized communication protocols to implement in an embedded system. It requires just two connections (transmit and receive) to achieve a full-duplex link. Unlike SPI and I2C, UART does not use a clock signal to synchronize communication. The UART protocol frames eight data bits with a start bit, a stop bit, and a parity bit. The parity bit, either odd or even, provides error checking while the start and stop bits coordinate packet framing.

    The most significant disadvantage to the UART interface is that it can only support communication between two devices. There is no hierarchy. The maximum UART data rate, termed the baud rate, is similar to I2C, but in practice, speeds of 115,200 baud (similar to bits per second) are popular. A UART interface can transfer data much further than I2C or SPI at these slower speeds and is extremely simple to implement.

    Programming and debug support of serial interfaces

    Configuring an MCU serial bus interface is typically achieved through an integrated development environment (IDE). Vendor tools or third-part IDEs can manage the pin assignments, data rates and other protocol framing parameters. Most toolchains provide a high-level abstraction of the interface’s low-level functionality, significantly easing the programming burden for the developer.

    When debugging an embedded design, a logic analyzer or a mixed signal oscilloscope equipped with a protocol decoding function can be a great asset.

    MCU interfaces take many forms

    Designers shouldn’t underestimate the importance of GPIO. Although GPIO are normally treated as individual ports, some MCUs can be configured to treat them as software-defined serial buses. This can avoid the need for external bus expanders. GPIO could also be used to drive other types of transceivers, such as communicating over an infrared optical link using a standard or proprietary protocol.

    As the name suggests, GPIO is highly versatile and the primary method for connecting simple peripherals that don’t have the benefit of a formal serial bus interface. This includes LEDs, single switches or switch matrices. Individual MCU pins can be used to create simple user interfaces by toggling an LED or reading the status of a switch. They can also be configured to drive more complex user interfaces through dedicated controllers.

    ELE Times Report
    ELE Times Report
    ELE Times provides extensive global coverage of Electronics, Technology and the Market. In addition to providing in-depth articles, ELE Times attracts the industry’s largest, qualified and highly engaged audiences, who appreciate our timely, relevant content and popular formats. ELE Times helps you build experience, drive traffic, communicate your contributions to the right audience, generate leads and market your products favourably.

    Technology Articles

    Popular Posts

    Latest News

    Must Read

    ELE Times Top 10