How do you choose between UART, SPI and I2C for a project?
Short answer: Start from the peripheral (many devices only offer one interface), then weigh data rate, number of devices, pins available, distance, and robustness. Use SPI for high data rates (displays, flash, high-rate ADCs, IMUs at kHz rates), I2C for many slow devices on few pins (sensors, EEPROM, PMIC configuration), and UART for communication with another processor or module (GPS, modem, BLE module, debug console), or over long distances with RS-485.
Decision factors
| Factor | Favours |
|---|---|
| > 1 Mbit/s sustained | SPI (or QSPI) |
| Many devices, few GPIOs | I2C |
| Talking to another MCU or a module with its own firmware | UART (or SPI with a protocol) |
| Long cables / noisy environment | RS-485 (UART), CAN |
| Need confirmation that a device is present | I2C (ACK) |
| Deterministic, low-latency streaming | SPI with DMA |
| Hot-plug or off-board connection | UART, USB, CAN |
| Low power (fewer transitions, sleep) | I2C/SPI at low clock, UART with wake-on-RX |
Example answer: "For a wearable with an IMU at 1 kHz, a temperature sensor, a battery fuel gauge and a display: SPI for the IMU and the display (bandwidth, DMA), I2C for the temperature sensor and fuel gauge (low rate, shared bus), UART for the debug console and the BLE module. I would check that no two I2C devices share an address and that the bus capacitance allows 400 kHz."
Follow-ups: what if two I2C sensors have the same fixed address (address pin, I2C multiplexer like TCA9548A, or a second bus); what if you run out of SPI chip selects (GPIO expander, decoder, or daisy chain).