Electronics Guide

Communication Interfaces

Communication interfaces enable microcontrollers to exchange data with sensors, actuators, displays, memory devices, and other processors. These interfaces form the nervous system of embedded systems, allowing individual components to work together as cohesive systems. From the simple serial connections that link a microcontroller to a debug terminal to the complex network protocols that enable distributed industrial control systems, communication interfaces determine how effectively a microcontroller can interact with its environment.

Each communication protocol represents a specific set of trade-offs between data rate, distance, complexity, power consumption, and cost. Understanding these trade-offs enables engineers to select the appropriate interface for each application. A sensor that reports temperature once per second has vastly different requirements than a high-speed camera streaming video data. By mastering the range of available communication interfaces, designers can create systems that communicate efficiently, reliably, and economically.

Serial Communication Fundamentals

Serial communication transmits data one bit at a time over a communication channel, in contrast to parallel communication which sends multiple bits simultaneously. While parallel interfaces can achieve higher instantaneous data rates, serial communication requires fewer physical connections, reduces crosstalk between signals, and simplifies PCB routing. Modern high-speed serial protocols often exceed the practical bandwidth of parallel interfaces by using sophisticated signaling techniques and clock recovery mechanisms.

Synchronous Versus Asynchronous Communication

The fundamental distinction in serial communication lies in how the transmitter and receiver coordinate their timing:

  • Synchronous communication: A dedicated clock signal accompanies the data, explicitly indicating when to sample each bit. The receiver uses this clock directly, eliminating timing ambiguity. SPI and I2C are synchronous protocols.
  • Asynchronous communication: No separate clock signal exists. Instead, both devices agree on a baud rate in advance, and special start and stop bits frame each data byte. The receiver uses its own clock to sample the data at predetermined intervals. UART is the classic asynchronous protocol.

Synchronous protocols achieve higher data rates and better noise immunity because the clock signal provides explicit timing information. However, they require additional signal lines and more complex hardware. Asynchronous protocols minimize pin count but require accurate baud rate matching between devices.

Data Framing and Encoding

Serial data must be organized into recognizable units that receivers can identify and process:

  • Start and stop bits: In asynchronous protocols, a start bit (logic low) signals the beginning of a byte, and one or more stop bits (logic high) mark its end
  • Parity bits: Optional error detection bit computed from the data bits, allowing detection of single-bit errors
  • Frame synchronization: Special patterns that mark the beginning of data packets in synchronous protocols
  • Bit stuffing: Insertion of extra bits to prevent data patterns from being confused with control sequences

The overhead of framing bits reduces the effective data rate. A typical UART configuration with 8 data bits, 1 start bit, and 1 stop bit achieves only 80% efficiency, as 2 of every 10 bits carry no user data.

Error Detection and Handling

Communication channels introduce errors through noise, interference, and timing variations. Robust protocols incorporate error detection mechanisms:

  • Parity checking: Simple odd or even parity detects single-bit errors but misses many multi-bit errors
  • Checksums: Arithmetic sum of data bytes catches more errors than parity alone
  • CRC (Cyclic Redundancy Check): Polynomial-based error detection providing strong protection against burst errors
  • Acknowledgment protocols: Receivers confirm successful reception, allowing retransmission of corrupted data

Higher-level protocols build upon these basic mechanisms to provide reliable data transfer even over noisy channels.

UART and USART

The Universal Asynchronous Receiver-Transmitter (UART) is the oldest and most fundamental serial communication interface, dating back to the earliest days of computing. Despite its age, UART remains ubiquitous due to its simplicity, minimal pin requirements, and ease of implementation. The Universal Synchronous/Asynchronous Receiver-Transmitter (USART) extends UART with optional synchronous operation modes.

UART Operation

UART communication requires only two signal lines: transmit (TX) and receive (RX). Each device's TX connects to the other's RX, creating a full-duplex communication channel:

  • Idle state: The line remains high (logic 1) when no data is being transmitted
  • Start bit: Transmission begins with a low bit, alerting the receiver that data follows
  • Data bits: Typically 7 or 8 bits, transmitted least significant bit first
  • Parity bit: Optional error detection bit (even, odd, or none)
  • Stop bits: One or two high bits mark the end of the frame

Both devices must agree on identical parameters: baud rate, data bits, parity, and stop bits. Common configurations include 9600-8-N-1 (9600 baud, 8 data bits, no parity, 1 stop bit) and 115200-8-N-1 for higher-speed communication.

Baud Rate and Timing

The baud rate specifies the number of signal changes per second, which equals the bit rate for binary signaling:

  • Standard rates: 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600 baud
  • Clock derivation: UART hardware divides the system clock to generate the baud rate, with divider values limiting available rates
  • Tolerance: Baud rate mismatch up to approximately 3% is typically tolerable, as the receiver samples near the center of each bit
  • Oversampling: Most UART implementations sample at 16x the baud rate to improve noise immunity and bit-center detection

Higher baud rates enable faster data transfer but require more accurate clock sources and shorter cable lengths due to signal integrity constraints.

Hardware Flow Control

When the receiver cannot process data as fast as it arrives, flow control prevents buffer overflow:

  • RTS/CTS (Request to Send/Clear to Send): Hardware handshaking signals where the receiver asserts CTS when ready to accept data
  • DTR/DSR (Data Terminal Ready/Data Set Ready): Additional control signals originally for modem communication
  • XON/XOFF: Software flow control using special characters (DC1 and DC3) to pause and resume transmission

Hardware flow control is preferred for high-speed or critical applications because it provides faster response than software flow control and does not restrict the data that can be transmitted.

USART Synchronous Mode

USART extends UART with synchronous operation, adding a clock line that the transmitter drives:

  • External clock: Data transitions are synchronized to an explicit clock signal
  • Higher speeds: Synchronous mode can achieve higher data rates than asynchronous UART
  • SPI compatibility: Many USART peripherals can operate as SPI masters or slaves
  • Infrared mode: Some USARTs include IrDA-compatible modulation for infrared communication

Applications and Limitations

UART remains widely used for numerous applications:

  • Debug consoles: Printf-style debugging and command-line interfaces
  • GPS modules: NMEA sentence output at 9600 or higher baud rates
  • Bluetooth modules: AT command interfaces and data streaming
  • RS-232/RS-485: Industrial serial communication using UART protocol with level conversion

Limitations include the point-to-point topology (only two devices without additional hardware), the need for pre-agreed configuration, and relatively low maximum data rates compared to modern protocols.

SPI (Serial Peripheral Interface)

The Serial Peripheral Interface (SPI) is a synchronous, full-duplex communication protocol developed by Motorola in the 1980s. SPI achieves high data rates with minimal protocol overhead, making it ideal for communication between microcontrollers and peripherals such as sensors, displays, flash memory, and data converters. Its simplicity and flexibility have made it one of the most widely used embedded communication interfaces.

SPI Signal Lines

A basic SPI bus consists of four signals:

  • SCLK (Serial Clock): Clock signal generated by the master, defining data transfer timing
  • MOSI (Master Out Slave In): Data line from master to slave, also called SDO (Serial Data Out) or COPI (Controller Out Peripheral In)
  • MISO (Master In Slave Out): Data line from slave to master, also called SDI (Serial Data In) or CIPO (Controller In Peripheral Out)
  • SS/CS (Slave Select/Chip Select): Active-low signal that enables a specific slave device

The master always generates the clock and controls slave selection. Data transfers bidirectionally during each clock cycle, with the master sending a bit on MOSI while simultaneously receiving a bit on MISO.

Clock Polarity and Phase

SPI defines four operating modes based on clock polarity (CPOL) and clock phase (CPHA):

  • Mode 0 (CPOL=0, CPHA=0): Clock idles low, data sampled on rising edge, shifted on falling edge
  • Mode 1 (CPOL=0, CPHA=1): Clock idles low, data shifted on rising edge, sampled on falling edge
  • Mode 2 (CPOL=1, CPHA=0): Clock idles high, data sampled on falling edge, shifted on rising edge
  • Mode 3 (CPOL=1, CPHA=1): Clock idles high, data shifted on falling edge, sampled on rising edge

The master must configure its SPI peripheral to match the mode required by each slave device. Mode 0 and Mode 3 are most common in practice.

Multi-Slave Configurations

SPI supports multiple slave devices through various topologies:

  • Independent slave select: Each slave has a dedicated CS line; only one slave is active at a time. This is the most common configuration, requiring N CS pins for N slaves.
  • Daisy chain: Slaves are connected in series, with MISO of one slave feeding MOSI of the next. Data shifts through all slaves, reducing pin count but increasing latency.
  • Parallel output: All slaves share MOSI but have individual CS lines; useful when only writing to slaves.

The independent slave select topology provides the best performance and simplest programming but requires the most GPIO pins.

Data Transfer

SPI operates as a circular shift register:

  • Full duplex: Each clock cycle exchanges one bit in each direction simultaneously
  • No addressing: The CS line selects the target device; no address bytes are needed in the protocol
  • Variable word size: Transfers can be 8, 16, or other bit widths depending on hardware support
  • Continuous transfer: Multiple bytes can be transferred while CS remains asserted

When reading data from a slave, the master often sends dummy bytes to generate the clocks needed for the slave to respond. The slave's response may be delayed by one or more bytes depending on the device.

Performance and Considerations

SPI offers several advantages and considerations:

  • High speed: Clock rates of 10 MHz to 100 MHz are common, with some devices supporting even higher rates
  • Low overhead: No address bytes, acknowledgments, or start/stop conditions reduce protocol overhead
  • Simple hardware: Just shift registers and basic control logic
  • Pin count: Requires four or more pins, which may be excessive for pin-limited designs
  • Cable length: Single-ended signaling limits practical cable length to tens of centimeters at high speeds
  • No standard: Many variations exist; always consult device datasheets for specific requirements

Common SPI Devices

SPI interfaces with a wide variety of peripherals:

  • Flash memory: Serial NOR and NAND flash for program and data storage
  • Displays: LCD and OLED displays with SPI interfaces
  • ADCs and DACs: Analog-to-digital and digital-to-analog converters
  • Sensors: Accelerometers, gyroscopes, pressure sensors, and more
  • Wireless modules: Many RF transceivers use SPI for configuration and data transfer
  • SD cards: Memory cards support an SPI mode for simple interfacing

I2C (Inter-Integrated Circuit)

I2C (Inter-Integrated Circuit), developed by Philips (now NXP) in 1982, is a synchronous, multi-master, multi-slave serial communication protocol using only two wires. Its ability to connect many devices on a shared bus with minimal wiring makes I2C invaluable for sensor networks, configuration interfaces, and low-speed peripheral communication. The protocol includes addressing, acknowledgment, and arbitration mechanisms that enable reliable multi-device communication.

I2C Bus Structure

The I2C bus uses two bidirectional lines:

  • SDA (Serial Data): Bidirectional data line for address and data transfer
  • SCL (Serial Clock): Clock line driven by the master, though slaves can hold it low for clock stretching

Both lines are open-drain (or open-collector), requiring external pull-up resistors to the supply voltage. Devices release the line to allow it to be pulled high, or actively pull it low. This wired-AND configuration enables multi-master operation and clock stretching.

Addressing

Each slave device has a unique address on the bus:

  • 7-bit addressing: The original addressing mode supporting up to 112 devices (some addresses are reserved)
  • 10-bit addressing: Extended mode for applications requiring more devices
  • Fixed addresses: Many devices have manufacturer-assigned addresses with configurable low bits
  • Address conflicts: Devices with the same address cannot coexist on the same bus without multiplexing

The address byte includes a read/write bit indicating the direction of the subsequent data transfer.

I2C Protocol

I2C communication follows a defined sequence:

  • Start condition: SDA transitions low while SCL is high, signaling the beginning of a transfer
  • Address byte: 7-bit slave address plus R/W bit, followed by acknowledgment from the addressed slave
  • Data bytes: One or more bytes transferred, each followed by an acknowledgment
  • Stop condition: SDA transitions high while SCL is high, releasing the bus
  • Repeated start: A start condition without an intervening stop, used to change direction or address

The acknowledge (ACK) bit is crucial: a slave pulls SDA low to acknowledge receipt, while a high SDA (NACK) indicates the slave is not responding or cannot accept more data.

Clock Speeds

I2C defines several speed modes:

  • Standard mode: Up to 100 kHz
  • Fast mode: Up to 400 kHz
  • Fast mode plus: Up to 1 MHz
  • High-speed mode: Up to 3.4 MHz
  • Ultra-fast mode: Up to 5 MHz (unidirectional, push-pull)

All devices on a bus must support the selected speed. Clock stretching, where a slave holds SCL low to pause the master, allows slow devices to request additional processing time.

Multi-Master Operation

I2C supports multiple masters on the same bus through arbitration:

  • Arbitration: If two masters start simultaneously, the one sending a high bit while reading a low bit loses arbitration and must wait
  • Clock synchronization: Masters synchronize their clocks by monitoring SCL, with the slowest master determining the speed
  • Bus busy detection: Masters detect ongoing transactions and wait for stop conditions before starting

Multi-master operation enables distributed systems where any processor can initiate communication.

I2C Considerations

Practical I2C implementation requires attention to several factors:

  • Pull-up resistor selection: Values typically range from 1k to 10k ohms, balancing rise time against power consumption
  • Bus capacitance: Maximum 400 pF limits cable length and number of devices
  • Level shifting: Different voltage domains require level translators
  • Address management: Careful planning prevents conflicts when combining devices
  • Bus recovery: Stuck buses can occur if a device holds SDA low; recovery procedures involve clock pulses to synchronize

SMBus and PMBus

Related protocols build upon I2C:

  • SMBus (System Management Bus): Stricter timing requirements, packet error checking, and defined timeouts for computer system management
  • PMBus (Power Management Bus): Extension of SMBus for digital power supply control and monitoring

These protocols maintain electrical compatibility with I2C while adding features for their specific application domains.

CAN (Controller Area Network)

The Controller Area Network (CAN) is a robust, message-based protocol developed by Bosch in the 1980s for automotive applications. CAN provides reliable communication in electrically noisy environments without requiring a bus master. Its built-in error detection, fault confinement, and priority-based arbitration make it the dominant protocol for automotive, industrial, and medical applications where reliability is paramount.

CAN Physical Layer

CAN uses differential signaling for noise immunity:

  • CAN_H and CAN_L: Two complementary signal lines carrying the differential signal
  • Dominant and recessive states: Dominant (logic 0) occurs when CAN_H is higher than CAN_L; recessive (logic 1) when both lines are at the same voltage
  • Termination: 120-ohm resistors at each end of the bus prevent reflections
  • Bit rates: Up to 1 Mbps for Classical CAN; up to 5 Mbps for CAN FD data phase

The wired-AND nature of the bus (any node can assert dominant) enables non-destructive arbitration.

Message-Based Protocol

Unlike address-based protocols, CAN uses message identifiers:

  • Standard frame: 11-bit identifier supporting 2048 unique message types
  • Extended frame: 29-bit identifier for applications requiring more message types
  • Content-based addressing: Receivers filter messages by identifier, not by source address
  • Broadcast nature: All nodes receive all messages and filter locally

This approach decouples message producers from consumers, simplifying system design and enabling flexible network topologies.

Arbitration and Priority

CAN handles simultaneous transmission attempts through bitwise arbitration:

  • Non-destructive arbitration: Nodes transmit identifiers bit by bit; a node sending recessive while reading dominant loses and becomes a receiver
  • Lower identifier = higher priority: Messages with numerically lower identifiers win arbitration
  • Guaranteed latency: Critical messages can be assigned low identifiers to ensure timely delivery
  • Fair access: After winning arbitration and transmitting, a node must wait before competing again

Arbitration occurs without message loss or corruption, maintaining bus efficiency even under heavy load.

Error Detection and Handling

CAN provides comprehensive error detection:

  • CRC check: 15-bit CRC detects transmission errors
  • Acknowledgment: Receivers acknowledge valid frames by driving dominant during the ACK slot
  • Bit monitoring: Transmitters verify that the bus reflects what they sent
  • Bit stuffing: After five consecutive identical bits, an opposite bit is inserted; violations indicate errors
  • Form checking: Certain bit fields must contain specific values

Detected errors trigger retransmission and update error counters. Nodes exceeding error thresholds transition to error-passive or bus-off states, preventing faulty nodes from disrupting the network.

CAN FD (Flexible Data-Rate)

CAN FD extends Classical CAN with higher performance:

  • Larger payloads: Up to 64 bytes per frame versus 8 bytes in Classical CAN
  • Faster data phase: After arbitration at the nominal bit rate, data can be transmitted at up to 5 Mbps
  • Improved CRC: Stronger CRC for larger payloads
  • Backward compatibility: CAN FD frames are rejected by Classical CAN nodes, requiring network-wide upgrade

CAN FD significantly increases effective bandwidth, enabling new applications in automotive and industrial domains.

Higher-Layer Protocols

Application-layer protocols standardize CAN usage:

  • CANopen: Industrial automation protocol defining device profiles and communication objects
  • SAE J1939: Heavy-duty vehicle protocol for trucks, buses, and construction equipment
  • OBD-II: Automotive diagnostics using CAN as the physical layer
  • DeviceNet: Industrial automation network built on CAN

These protocols provide standardized ways to configure devices, exchange data, and handle errors across multi-vendor systems.

LIN (Local Interconnect Network)

The Local Interconnect Network (LIN) is a low-cost, single-wire serial protocol developed as a complement to CAN for automotive applications where CAN's capabilities exceed requirements. LIN provides a cost-effective solution for connecting sensors, actuators, and switches in applications like seat controls, mirrors, rain sensors, and interior lighting. Its single-master architecture simplifies implementation while maintaining deterministic communication timing.

LIN Characteristics

LIN occupies a specific niche in automotive networking:

  • Single wire: One signal line plus ground, reducing wiring cost and weight
  • Low speed: Maximum 20 kbps, sufficient for non-critical applications
  • Single master: One master node controls all communication timing; slaves respond when addressed
  • Self-synchronization: Slaves synchronize to the master's clock from the sync field, eliminating the need for crystal oscillators in slave nodes

The cost savings from simpler transceivers and slave hardware make LIN attractive for distributed switch panels and sensor networks.

LIN Frame Structure

LIN communication uses a header-response model:

  • Break field: At least 13 dominant bits signal the start of a frame
  • Sync field: Fixed 0x55 pattern for slave clock synchronization
  • Identifier: 6-bit frame identifier plus 2 parity bits specifying the message and which slave responds
  • Response: 2, 4, or 8 data bytes plus checksum, transmitted by the designated slave (or master in some cases)

The master initiates all communication by sending headers; slaves never transmit unsolicited data.

LIN Schedule

The master follows a schedule table defining when to send each frame:

  • Time slots: Each frame is assigned a time slot in the schedule
  • Deterministic timing: Messages arrive at predictable intervals
  • Event-triggered frames: Special frames that slaves use only when they have new data
  • Sporadic frames: Optional frames the master sends only when needed

Schedule tables ensure that all slaves receive the polling they need while managing bus bandwidth efficiently.

Applications

LIN networks appear throughout modern vehicles:

  • Door modules: Window controls, mirror adjustment, lock/unlock
  • Seat controls: Position adjustment, heating, ventilation
  • Climate control: Fan speed, vent position, temperature sensors
  • Lighting: Interior lights, ambient lighting, rain/light sensors

LIN networks typically connect to the main vehicle CAN network through a gateway in the master node, enabling integration with body control modules and diagnostics.

USB (Universal Serial Bus)

The Universal Serial Bus (USB) has become the dominant interface for connecting peripherals to computers and embedded systems. Originally designed to simplify the connection of keyboards, mice, and printers, USB has evolved to support high-speed data transfer, power delivery, and diverse device classes. Microcontrollers with USB interfaces can appear as any standard device type or implement custom protocols for application-specific communication.

USB Versions and Speeds

USB has evolved through several generations:

  • USB 1.0/1.1: Low Speed (1.5 Mbps) and Full Speed (12 Mbps)
  • USB 2.0: High Speed (480 Mbps) while maintaining backward compatibility
  • USB 3.0/3.1/3.2: SuperSpeed (5 Gbps, 10 Gbps, 20 Gbps) using additional differential pairs
  • USB4: Up to 40 Gbps using Thunderbolt technology

Most microcontrollers implement USB 2.0 Full Speed or High Speed, providing sufficient bandwidth for most embedded applications while keeping costs manageable.

USB Architecture

USB uses a tiered star topology with defined roles:

  • Host: Controls all bus traffic, initiates all transactions, provides power
  • Device: Responds to host requests, cannot initiate communication
  • Hub: Expands connectivity, translates between port speeds
  • On-The-Go (OTG): Devices that can switch between host and device roles

The strict host-device relationship simplifies protocol design but requires mechanisms like polling for device-initiated communication.

Endpoints and Transfers

USB communication uses endpoints, logical data sources or sinks within a device:

  • Endpoint 0: Mandatory control endpoint for device enumeration and configuration
  • Control transfers: Request-response communication for configuration and commands
  • Bulk transfers: Large, reliable data transfers without guaranteed timing (storage, printing)
  • Interrupt transfers: Small, periodic transfers with guaranteed latency (keyboards, mice)
  • Isochronous transfers: Guaranteed bandwidth with no error recovery (audio, video streaming)

Device designers select transfer types based on application requirements for bandwidth, latency, and reliability.

Device Classes

USB defines standard device classes with common drivers:

  • CDC (Communications Device Class): Virtual serial ports for simple data communication
  • HID (Human Interface Device): Keyboards, mice, game controllers, custom control panels
  • MSC (Mass Storage Class): Flash drives, card readers, portable storage
  • Audio: Microphones, speakers, audio interfaces
  • Video: Webcams, video capture devices

Implementing a standard class allows devices to work with built-in operating system drivers, eliminating the need for custom driver development.

Microcontroller USB Implementation

USB-capable microcontrollers typically include:

  • USB transceiver: Physical layer handling signal levels and impedance
  • Serial Interface Engine (SIE): Hardware for packet processing, CRC, and bit stuffing
  • Endpoint buffers: RAM for storing incoming and outgoing data
  • DMA support: Direct memory access for efficient data transfer

USB stacks (software libraries) handle the protocol complexity, allowing developers to focus on application-specific functionality.

Ethernet Controllers

Ethernet provides high-speed network connectivity for microcontrollers requiring TCP/IP communication, web interfaces, or integration with enterprise networks. Industrial Ethernet variants add deterministic timing for real-time control applications. While more complex than point-to-point protocols, Ethernet enables standardized networking, remote access, and integration with IT infrastructure.

Ethernet Basics

Ethernet standards define the physical and data link layers:

  • 10BASE-T: 10 Mbps over twisted pair cabling
  • 100BASE-TX (Fast Ethernet): 100 Mbps, the most common speed for microcontrollers
  • 1000BASE-T (Gigabit Ethernet): 1 Gbps for higher-performance applications
  • MAC addresses: 48-bit hardware addresses uniquely identifying each interface
  • Frames: Data packets with source/destination addresses, type/length, payload, and CRC

Ethernet's ubiquity ensures compatibility with existing network infrastructure and wide availability of switches, cables, and test equipment.

PHY and MAC

Ethernet interfaces consist of two components:

  • MAC (Media Access Controller): Handles frame formatting, addressing, and collision detection; often integrated into the microcontroller
  • PHY (Physical Layer Transceiver): Handles electrical signaling, encoding, and physical medium interface; typically an external chip
  • MII/RMII/RGMII: Interfaces between MAC and PHY with varying pin counts and speeds
  • Magnetics: Transformers for isolation and common-mode rejection

Some microcontrollers integrate both MAC and PHY, while others require external PHY chips for flexibility in connector placement and isolation.

TCP/IP Stack

Network communication requires a protocol stack:

  • IP (Internet Protocol): Addressing and routing of packets
  • TCP (Transmission Control Protocol): Reliable, ordered delivery with flow control
  • UDP (User Datagram Protocol): Lightweight, connectionless messaging
  • DHCP: Automatic IP address configuration
  • DNS: Domain name resolution

Lightweight TCP/IP stacks like lwIP provide the necessary protocols for resource-constrained microcontrollers, while full-featured stacks support complete network functionality.

Industrial Ethernet

Real-time applications use specialized Ethernet variants:

  • EtherCAT: High-speed, low-latency protocol for motion control and I/O
  • PROFINET: Industrial automation protocol supporting real-time and isochronous communication
  • EtherNet/IP: Industrial protocol using standard TCP/IP with CIP application layer
  • TSN (Time-Sensitive Networking): IEEE standards for deterministic Ethernet with guaranteed latency

Industrial Ethernet enables convergence of control and information networks, simplifying factory infrastructure while maintaining real-time performance.

Wireless Interfaces

Wireless communication eliminates cables for applications requiring mobility, difficult physical access, or large numbers of distributed sensors. Microcontrollers interface with wireless transceivers through protocols like SPI or UART, or integrate radio hardware directly. Each wireless technology offers different trade-offs in range, data rate, power consumption, and network topology.

Bluetooth and BLE

Bluetooth provides short-range wireless communication:

  • Bluetooth Classic: Higher data rates (up to 3 Mbps) for audio streaming and file transfer
  • Bluetooth Low Energy (BLE): Optimized for low power, small data payloads, and battery-operated sensors
  • Profiles: Standardized use cases like HID, audio, and health devices
  • GATT: Generic Attribute Profile defining services and characteristics for BLE data exchange

BLE has become the dominant protocol for wearables, beacons, and IoT sensors due to its low power consumption and smartphone compatibility.

WiFi

WiFi enables integration with standard wireless networks:

  • 802.11 standards: Various generations offering different speeds and frequencies
  • Infrastructure mode: Devices connect through access points to the network
  • SoftAP: Microcontroller acts as an access point for direct device connection
  • WiFi modules: SoCs like ESP32 provide integrated WiFi with TCP/IP stack

WiFi suits applications requiring internet connectivity, web interfaces, or integration with home and office networks.

Zigbee and Thread

Mesh networking protocols for IoT applications:

  • Zigbee: Low-power mesh protocol for home automation and industrial sensing
  • Thread: IPv6-based mesh protocol designed for reliable home automation
  • Matter: Application layer working over Thread, WiFi, and Ethernet for smart home interoperability
  • Mesh topology: Devices relay messages, extending range and providing redundancy

Mesh networks excel for distributed sensor systems where direct connection to every node is impractical.

LoRa and LPWAN

Long-range, low-power wide-area networks for IoT:

  • LoRa: Spread spectrum modulation achieving kilometer-range with low power
  • LoRaWAN: Network protocol for LoRa including security and network management
  • Sigfox: Ultra-narrowband protocol for simple, long-range sensor reporting
  • NB-IoT: Cellular-based IoT using licensed spectrum

LPWAN technologies enable battery-operated sensors to communicate over kilometers for years without battery replacement.

Cellular

Cellular modems provide wide-area connectivity:

  • 2G/3G/4G: Traditional cellular for mobile broadband
  • LTE-M: Low-power LTE variant for IoT applications
  • 5G: High bandwidth and low latency for demanding applications
  • eSIM: Embedded SIM for flexible carrier selection

Cellular is essential for mobile assets, remote locations, and applications requiring reliable wide-area coverage.

IrDA (Infrared Data Association)

IrDA defines standards for short-range infrared communication, once common in mobile devices and remote controls. While largely superseded by wireless protocols for data transfer, infrared remains important for remote controls, optoisolated communication, and applications where radio interference is unacceptable.

IrDA Standards

IrDA encompasses several speed ranges:

  • SIR (Serial Infrared): 9.6 kbps to 115.2 kbps, compatible with UART timing
  • MIR (Medium Infrared): 0.576 to 1.152 Mbps
  • FIR (Fast Infrared): Up to 4 Mbps
  • VFIR (Very Fast Infrared): Up to 16 Mbps

Most microcontroller implementations support SIR, using standard UART hardware with infrared modulation/demodulation.

Physical Layer

IrDA communication uses infrared light:

  • Wavelength: 850-900 nm, invisible to humans
  • Range: Typically 1 meter for data transfer
  • Cone angle: 30-degree half-angle for point-to-point communication
  • Modulation: Pulse position modulation or pulse duration modulation

Line-of-sight operation and limited range make IrDA secure against casual eavesdropping but require careful device alignment.

Consumer IR

Remote control protocols differ from IrDA data standards:

  • NEC protocol: Common format using 38 kHz carrier
  • RC5/RC6: Philips protocols for consumer electronics
  • SIRC: Sony's remote control protocol
  • Carrier modulation: Infrared is modulated onto 30-60 kHz carrier for noise immunity

Microcontrollers can easily transmit and receive these protocols using timer/capture hardware and infrared LED/detector pairs.

Proprietary Protocols

Many applications use custom or proprietary communication protocols tailored to specific requirements. These protocols may offer advantages in performance, simplicity, or intellectual property protection that standard protocols cannot match. Understanding when and how to design proprietary protocols is valuable for embedded system development.

Reasons for Proprietary Protocols

Custom protocols serve specific needs:

  • Performance optimization: Minimizing overhead for specific data patterns
  • Legacy compatibility: Interfacing with existing non-standard equipment
  • Resource constraints: Protocols lighter than standards for tiny microcontrollers
  • Security through obscurity: Making reverse engineering more difficult (not a sole security measure)
  • Licensing: Avoiding patent or licensing issues with standard protocols

Before designing a custom protocol, carefully evaluate whether existing standards might meet requirements with less development effort.

Protocol Design Considerations

Effective protocol design addresses several aspects:

  • Framing: How message boundaries are identified (length prefix, delimiters, or fixed frames)
  • Addressing: How multiple devices share a bus or network
  • Error detection: Checksums or CRC to verify data integrity
  • Flow control: Preventing buffer overflows in receivers
  • Timeouts: Handling communication failures gracefully
  • Versioning: Allowing protocol evolution while maintaining compatibility

Examples of Proprietary Interfaces

Various industries use specialized protocols:

  • 1-Wire: Dallas/Maxim protocol for sensors and identification using a single data line
  • SDI-12: Serial protocol for environmental sensors
  • SENT: Single Edge Nibble Transmission for automotive sensors
  • DALI: Digital Addressable Lighting Interface for building automation
  • BACnet: Building automation and control networks

These protocols, while not universally standard, have become de facto standards within their domains.

Interface Selection Guidelines

Selecting the appropriate communication interface requires balancing multiple factors. No single protocol excels in all dimensions; each represents specific trade-offs suited to particular applications.

Key Selection Criteria

Consider these factors when choosing a communication interface:

  • Data rate requirements: How much data must be transferred and how quickly?
  • Distance: How far apart are the communicating devices?
  • Number of devices: How many devices must communicate?
  • Topology: Point-to-point, bus, or network?
  • Power consumption: Is battery operation required?
  • Cost: Transceiver, connector, and cable costs?
  • Environmental conditions: Noise, temperature, moisture?
  • Existing infrastructure: What interfaces are already available?

Quick Reference

General guidance for common scenarios:

  • Debug console: UART at 115200 baud or higher
  • High-speed peripheral (flash, display): SPI at maximum supported speed
  • Multiple low-speed sensors: I2C for minimal wiring
  • Automotive or industrial: CAN for robustness and reliability
  • Automotive low-cost: LIN for simple switches and sensors
  • Computer connection: USB for plug-and-play operation
  • Network connectivity: Ethernet or WiFi for TCP/IP
  • Battery-operated sensors: BLE or LoRa depending on range

Conclusion

Communication interfaces form the essential links that connect microcontrollers to the broader world of sensors, actuators, displays, and networks. From the simplicity of UART to the sophistication of USB and Ethernet, each protocol serves specific needs in the embedded systems ecosystem. Mastering these interfaces enables engineers to create systems that effectively gather, process, and share information.

The choice of communication interface profoundly impacts system cost, complexity, reliability, and performance. Simple point-to-point protocols like SPI and I2C efficiently connect nearby peripherals, while CAN and industrial Ethernet provide robust communication for demanding environments. Wireless protocols extend reach and enable mobility, opening new application possibilities. Understanding the strengths and limitations of each interface allows designers to select the optimal combination for their specific requirements.

As embedded systems become more connected and intelligent, communication interfaces continue to evolve. New protocols emerge to meet the demands of automotive electrification, industrial automation, and the Internet of Things. By building a strong foundation in communication fundamentals and staying current with emerging technologies, engineers can confidently design systems that communicate effectively today and adapt to tomorrow's requirements.

Further Reading

  • Study microcontroller peripheral configuration and initialization
  • Explore real-time operating systems and their communication support
  • Learn about protocol analyzers and debugging techniques
  • Investigate electromagnetic compatibility considerations for communication interfaces
  • Research security considerations for networked embedded systems
  • Examine specific protocol specifications and application notes from device manufacturers