Serial Communication Protocols

A microcontroller exchanges measurements, commands, and stored data with other devices by sending bits in an agreed order. A serial communication protocol defines how those bits are timed and organized so a receiver can interpret them. UART, SPI, and I²C are common choices. Understanding their framing and connections helps you select a suitable interface and estimate whether a transfer can meet a deadline.

Bits, clocks, and transfer time

Serial communication sends bits sequentially along a data line. A byte contains eight bits, but transferring one useful byte can require additional bits for synchronization, addressing, or checking reception.


For a constant bit rate RR, the transmission time is


t=Ntransmitted bitsR.t = \frac{N_{\text{transmitted bits}}}{R}.


Here, tt is in seconds when RR is in bits per second. For a synchronous interface transferring one bit per clock cycle on each data line, count clock cycles instead:


tclocked=Nclock cyclesfclock.t_{\text{clocked}} = \frac{N_{\text{clock cycles}}}{f_{\text{clock}}}.


Add any separately specified pauses or setup intervals. These equations describe communication time; they do not include sensor conversion time or software processing unless explicitly stated.


The payload efficiency is the fraction of transmitted bits that carry the useful data you intend to deliver:


η=Npayload bitsNtransmitted bits.\eta = \frac{N_{\text{payload bits}}}{N_{\text{transmitted bits}}}.


Define the payload before calculating efficiency: a command might be useful information for one application but overhead relative to a measurement stream.

UART: timing without a clock wire

A UART, or universal asynchronous receiver/transmitter, uses agreed timing rather than a shared clock signal. In a typical two-device connection, each device's transmit output, TX, connects to the other's receive input, RX. Both ends need compatible signal voltages, a shared reference, and matching baud rate and frame settings.


For ordinary binary UART signaling, one symbol carries one bit, so the numerical baud rate equals the bit rate. The configuration 8N1 means eight data bits, no parity, and one stop bit. Including its start bit, each byte occupies ten bit periods. This framing gives a maximum byte rate of R/10R/10 for contiguous frames.


A UART frame contains a start bit, eight ordered data bits, and a stop bit.


Using the usual non-inverted logic convention, the line idles high, the start bit is low, and the stop bit is high. Data normally travels least significant bit first. A parity bit, when enabled, makes the total number of one-bits in the data and parity positions even or odd. Parity detects an odd number of flipped protected bits, but an even number can pass unnoticed. It does not correct errors.

SPI and I²C: clocked transfers

SPI, the serial peripheral interface, commonly uses SCK, two directional data lines, and a chip-select signal. A controller supplies the clock and selects a peripheral. Conventional full-duplex SPI can send and receive one bit simultaneously per clock cycle; meaningful received data may require transmitting dummy bits. Both devices must agree on clock polarity, sampling phase, and bit order. Commands, addresses, and dummy cycles depend on the peripheral.


Ordinary bidirectional I²C uses shared SDA data and SCL clock lines with pull-up resistors. Devices pull these lines low or release them. A controller addresses a target, commonly using a seven-bit address followed by a read/write bit. Each eight-bit address or data byte is followed by a ninth clock for acknowledgement, ACK, or non-acknowledgement, NACK. A controller receiving data normally sends NACK after the final byte to end the read. START and STOP are bus conditions, not additional bytes.



Choosing a link

The following signal counts exclude power and ground and describe common configurations.


Interface

Typical signals

Selection and timing considerations

UART

TX and RX

Typically connects two devices; match baud rate and framing.

SPI

SCK, two data lines, chip select

Typically needs a separate select per peripheral; count all transaction phases.

I²C

SDA and SCL

Shares two signals among addressed devices; check address conflicts and acknowledgement overhead.


A shared I²C bus generally needs distinct target addresses for independent access. SPI peripherals sharing a return line need compatible behavior when deselected. Check the device specifications rather than assuming every peripheral implements the same transaction format.



What to remember

  • Count framing, addressing, and acknowledgement overhead as well as payload.
  • UART needs matching timing; SPI and I²C use a shared clock.
  • Simultaneous SPI transmission and reception share clock cycles.
  • Choose an interface using connection requirements, timing, and device compatibility.

Example: Timing three links in a sensor logger

A sensor logger uses UART to send records to a host, SPI to read memory, and I²C to configure a sensor. Analyze each transfer independently. All bytes contain eight bits, and all stated rates remain constant during their transfers.


For UART and SPI, ignore gaps and setup or hold intervals. For I²C, calculate only the clocked duration: exclude START and STOP timing intervals, and assume no clock stretching or software gaps. Report UART time in milliseconds to three decimal places and SPI and I²C times in microseconds to one decimal place.


a) The logger sends an 18-byte UART record at 38,400 bit/s using 8N1: one start bit, eight data bits, no parity, and one stop bit per byte. Find the transmission time and the payload efficiency, treating all record bytes as payload.


Each byte requires a separate frame. Count its start and stop positions as well as its ________ data positions:


Nframe=1+8+0+1=10 bits.N_{\text{frame}} = 1+8+0+1 = 10\ \text{bits}.


The complete record therefore contains


Nrecord=18 bytes×10 bits/byte=180 bits.N_{\text{record}} = 18\ \text{bytes}\times10\ \text{bits/byte} = 180\ \text{bits}.


Divide by the line bit rate:


tUART=180 bits38400 bits/s=0.0046875 s=4.688 ms.\begin{aligned} t_{\text{UART}} &= \frac{180\ \text{bits}}{38400\ \text{bits/s}} \\ &= 0.0046875\ \text{s} \\ &= 4.688\ \text{ms}. \end{aligned}


The payload contains 18(8)=14418(8)=144 bits. Its efficiency is


η=144180=0.800=80.0%.\eta = \frac{144}{180} = 0.800 = 80.0\%.


The record takes 4.688 ms, with 80.0% payload efficiency. Counting only the 144 data bits would omit framing that occupies real transmission time.


b) A conventional single-bit SPI memory read consists of an eight-bit command, a 16-bit address, and then 12 returned data bytes. There is no separate dummy-clock phase. The controller sends dummy bits while receiving the data. SCK is 2.00 MHz, and chip select stays active throughout. Find the clocked duration.


The command and address occur before the returned data. During reception, outgoing dummy bits use the same clocks as incoming data, so they do not require a second transfer interval.


Convert the returned bytes to bits:


Ndata=12 bytes×8 bits/byte=96 bits.N_{\text{data}} = 12\ \text{bytes}\times8\ \text{bits/byte} = 96\ \text{bits}.


With one bit per clock cycle in each direction, count


Ncycles=8+16+96=120.N_{\text{cycles}} = 8+16+96 = 120.


Then


tSPI=120 cycles2.00×106 cycles/s=0.0000600 s=60.0 μs.\begin{aligned} t_{\text{SPI}} &= \frac{120\ \text{cycles}}{2.00\times10^6\ \text{cycles/s}} \\ &= 0.0000600\ \text{s} \\ &= 60.0\ \mu\text{s}. \end{aligned}


The clocked read takes 60.0 microseconds. Full duplex allows simultaneous traffic; it does not remove the command and address phases required by this memory.


c) To configure the I²C sensor, the controller sends START, a seven-bit target address plus a write bit, one eight-bit register number, three eight-bit data bytes, and STOP. The target acknowledges every address or data byte. SCL is 100 kHz. Find the clocked duration.


An I²C write sends an address, a register number, and three data bytes with acknowledgements.


The seven address bits and the write bit form ________ eight-bit address byte. Include the register number as a transmitted byte even though it is not one of the three configuration data bytes.


The number of eight-bit bytes is


Nbytes=1address+1register+3data=5.N_{\text{bytes}} = 1_{\text{address}} + 1_{\text{register}} + 3_{\text{data}} = 5.


Every byte requires eight data clocks and ________ ACK clock:


Ncycles=5(8+1)=45.N_{\text{cycles}} = 5(8+1) = 45.


At 100 kHz=100×103 cycles/s100\ \text{kHz} = 100\times10^3\ \text{cycles/s},


tI²C, clocked=45100×103 s=0.000450 s=450.0 μs.\begin{aligned} t_{\text{I²C, clocked}} &= \frac{45}{100\times10^3}\ \text{s} \\ &= 0.000450\ \text{s} \\ &= 450.0\ \mu\text{s}. \end{aligned}


The clocked duration is 450.0 microseconds. START and STOP are not extra bytes. Their timing intervals are excluded here as stated; an elapsed bus-occupancy calculation would include them.

A laboratory instrument sends contiguous UART frames using 8E1: one start bit, eight data bits, one even-parity bit, and one stop bit. Treat all eight data bits as payload. What percentage of transmitted bit periods carries payload, rounded to one decimal place?


UART frame fields appear in transmission order from start through data and parity to stop.


Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A controller must read two I²C temperature sensors independently. Both sensors have the fixed seven-bit address 0x48, with no address-changing feature. Only SDA and SCL are available as controller communication signals. A compatible I²C multiplexer with a different control address is available. Which modification provides independent sensor access?


Two sensors with the same address connect to shared SDA and SCL lines.


Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A controller reads 16 bytes from an SPI memory using one data bit per clock cycle in each direction. The transaction consists of an eight-bit command, a 24-bit address, eight additional dummy clock cycles, and then the 16 returned data bytes. During the returned-data phase, the controller simultaneously transmits dummy bits. SCK is 4.00 MHz throughout. Ignore chip-select setup and hold time and all gaps. Calculate the total clocked transaction duration in microseconds, to one decimal place.


An SPI read proceeds through command, address, dummy clocks, and returned data phases.


Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice