Skip to content
Tech Interview Prep
Technical interview guide

Communication Protocols: SPI, I2C, UART

The three workhorse serial buses for talking to peripherals and other boards: how each is wired and clocked, and when to reach for which.

Minutes to read
4
Practice MCQs
25
Interview Q&A
25
Edition
v4
Editorial status
Reviewed

Scope: NXP UM10204 revision 7; CMSIS-Driver 6 SPI/I2C/USART interfaces; current Zephyr peripheral APIs reviewed 2026-09-04.

Overview

Curated: · Written: · Reviewed:

Communication Protocols: SPI, I2C, UART

In one line

SPI, I2C and UART are electrical and framing mechanisms for talking to nearby peripherals and other boards. Reach for SPI for fast full-duplex links to a few devices, I2C for many low-speed devices on two shared wires, and UART for a point-to-point link with no shared clock.

Key definitions

  • Push-pull: both ends actively drive the line, so two enabled drivers on one line is contention, not a logic level.
  • Open-drain: devices only pull low and the pull-up sets the high level, which makes the bus a wired-AND.
  • CPOL and CPHA: CPOL sets the SCLK idle level, CPHA sets which edge samples. Together they give modes 0 to 3.
  • Repeated START: a START issued without a STOP, beginning the next address phase.
  • Framing error versus overrun: framing means a bad start, stop or sample position; overrun means a received byte was lost because the previous one was not read in time.
  • STOP: SDA rising while SCL is high.

Formulas and complexity

UART divisor: divisor=fclk16×baud\text{divisor} = \frac{f_{clk}}{16 \times \text{baud}} At 16 MHz for 115200 baud the divisor is 8.68, rounded to 9, giving an actual rate of 111111 baud, an error of -3.55%. I2C Fast-mode limits: Cb≤400 pF,tr≤300 nsC_b \le 400\ \text{pF}, \qquad t_r \le 300\ \text{ns}

How it works

  • SPI: the master asserts CS and drives SCLK. Each bit is shifted out on one edge and sampled on the other, as set by the mode. A wrong mode gives no clean error; the bits simply land in the wrong positions.
  • I2C: START, then the 7-bit address plus R/W, ACK on the ninth clock, then data bytes, then STOP. The master NACKs the last byte it wants to read.
  • UART: idle is high. A start bit (low), 5 to 9 data bits LSB-first, optional parity, then 1, 1.5 or 2 stop bits. The receiver oversamples 16 times and samples mid-bit.
START addr+W, ACK register pointer, ACK repeated START addr+R, ACK data byte, NACK on last STOP

When to use and when not to

ChoiceReach for it whenAvoid it when
SPIFast full-duplex link to a few devices; one CS per slaveMany peripherals on the pin budget; slow sensors
I2CMany low-speed devices on two shared wires, addressed by 7 or 10 bitsBus capacitance is high and rise time cannot meet 300 ns
UARTPoint-to-point link to a console, board or modem with no shared clockBoth ends cannot hold baud error to a few percent

SPI has a clock line and no addressing; I2C is open-drain and multi-drop; UART has no clock and both ends must agree on baud, data bits, parity, stop bits and polarity.

Traps interviewers probe

  1. Wrong SPI mode. Sampling one edge off turns 0xA5 into 0x4B with an idle-high clock. Fix: match CPOL and CPHA to the datasheet and confirm the edges on a logic analyzer.
  2. Connecting mismatched logic levels directly. A 5 V push-pull output into a 3.3 V part, or powering it from the 5 V rail, can damage the device. Fix: use a level shifter or a 3.3 V supply and check the absolute maximum ratings.
  3. Treating every NACK as device absent. An address NACK means nothing answered, a data-byte NACK means the device rejected that byte, and a final read NACK is normal. Fix: classify the NACK by stage before retrying.
  4. Retrying a non-idempotent write. A write that NACKs after the data byte may already have taken effect. Fix: guard the retry with a transaction id or write an absolute value.
  5. Ignoring I2C rise time. The rising edge is the pull-up charging the bus capacitance, and it must reach 0.7 VDD before the master samples. Fix: check the RC against 300 ns and reduce the pull-up or the capacitance.

Interview tips

Open by naming the bus, the number of devices, and what the link must guarantee. For example: 'I2C, three low-speed sensors, so the link must give addressing, ACK checking and a bus timeout.'

Expect these follow-ups: the rise-time budget at temperature and voltage corners, arbitration-loss handling, DMA cache maintenance, the baud-error budget, 9-bit multidrop framing, and NACK classification.

30-second answer outline:

  1. Name the bus and its wiring: SPI with CS per slave, I2C on SCL and SDA with pull-ups, or UART TX and RX with a common ground.
  2. State the mode, baud or speed, and framing that both ends must match.
  3. Name the failure you guard against: a wrong mode, a NACK misread as absent, a timeout, or a retry that applies twice.
  4. State how you prove it on the wire: a logic-analyzer capture of START, address, ACK and STOP, or the baud error calculation.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.