Compare UART, SPI and I2C. When would you use each?
What the interviewer wants to hear
- UART: asynchronous, two wires, point-to-point, baud rate
- SPI: synchronous, full duplex, fast, chip select per device
- I2C: synchronous, two wires, multiple devices by address, slower
- Use cases for each
Model answer
UART is asynchronous: there is no shared clock, so both sides agree on a baud rate like 115200. It uses TX and RX lines and connects two devices, which makes it great for debug consoles, GPS modules and modems. SPI is synchronous, with a clock from the controller plus MOSI, MISO and one chip-select line per device. It is full duplex and fast, often tens of MHz, so I use it for displays, SD cards, flash memory and high-speed ADCs. I2C uses only two wires, SDA and SCL, with pull-up resistors, and many devices share the bus, each with an address. It is slower, typically 100 kHz or 400 kHz, and half duplex, but very convenient for sensors, EEPROMs and RTC chips when pins are limited. So: UART for simple point-to-point, SPI for speed, I2C for many low-speed devices on few pins.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Embedded Systems Engineer questions
- What is the difference between a microcontroller and a microprocessor?
- What is an interrupt, and how is it different from polling?
- Explain volatile and const in embedded C. Can a variable be both?
- When would you use bare-metal firmware versus an RTOS?
- What GPIO modes does a typical microcontroller pin support, and when would you use each?
- What is PWM, how is it generated on a microcontroller, and what is it used for?
- What is a bootloader in an embedded device, and why would a product need one?
- What is endianness, and how do you deal with it when exchanging data between devices?
- How do you approach reading a datasheet for a new sensor or microcontroller?