Bird
Raised Fist0
Embedded Cprogramming~20 mins

SPI vs UART trade-offs in Embedded C - Practice Questions

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
SPI vs UART Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Data Transfer Speed Comparison

Which statement correctly compares the maximum data transfer speeds of SPI and UART?

ANeither SPI nor UART supports high-speed data transfer.
BUART generally supports higher data transfer speeds than SPI.
CSPI generally supports higher data transfer speeds than UART.
DSPI and UART have the same maximum data transfer speeds.
Attempts:
2 left
💡 Hint

Think about clocked vs asynchronous communication.

❓ Predict Output
intermediate
1:30remaining
UART Data Frame Size

Given the UART configuration below, what is the total number of bits transmitted per data frame (including start, data, parity, and stop bits)?

Embedded C
/* UART config: 1 start bit, 8 data bits, no parity, 1 stop bit */
// Calculate total bits per frame
A8 bits
B9 bits
C11 bits
D10 bits
Attempts:
2 left
💡 Hint

Count all bits including start and stop bits.

❓ Predict Output
advanced
2:00remaining
SPI Chip Select Behavior

Consider this SPI master code snippet controlling two devices. What will be the output on the chip select (CS) pins if the master communicates with device 2?

Embedded C
/*
SPI Master controls two devices:
CS1 = GPIO pin for device 1
CS2 = GPIO pin for device 2
*/

void select_device(int device) {
    if (device == 1) {
        CS1 = 0; // active low
        CS2 = 1;
    } else if (device == 2) {
        CS1 = 1;
        CS2 = 0;
    }
}

select_device(2);
ACS1 = 0, CS2 = 0
BCS1 = 1, CS2 = 0
CCS1 = 0, CS2 = 1
DCS1 = 1, CS2 = 1
Attempts:
2 left
💡 Hint

Remember chip select is active low.

🧠 Conceptual
advanced
1:30remaining
UART vs SPI: Full Duplex Communication

Which statement best describes the full duplex communication capability of UART and SPI?

ASPI supports full duplex communication; UART does not.
BUART supports full duplex communication; SPI does not.
CBoth SPI and UART support full duplex communication.
DNeither SPI nor UART supports full duplex communication.
Attempts:
2 left
💡 Hint

Consider how data lines are used in each protocol.

❓ Predict Output
expert
2:30remaining
UART Baud Rate Error Calculation

Given a UART configured for 9600 baud with a clock frequency of 16 MHz, what is the approximate baud rate error percentage if the UART baud rate register is set to 103?

Embedded C
/*
Baud rate = Clock / (16 * (UBRR + 1))
Clock = 16,000,000 Hz
UBRR = 103
*/

// Calculate actual baud rate and error percentage
AError ≈ 0.06%
BError ≈ 1.2%
CError ≈ 0.5%
DError ≈ 2.0%
Attempts:
2 left
💡 Hint

Calculate actual baud rate then compare to 9600.

Practice

(1/5)
1. Which of the following is a key advantage of SPI over UART?
easy
A. Simpler hardware design
B. Uses fewer wires
C. Better for long-distance communication
D. Faster data transfer speed

Solution

  1. Step 1: Understand SPI characteristics

    SPI is known for high-speed data transfer and supports multiple devices with separate select lines.
  2. Step 2: Compare with UART features

    UART uses fewer wires and is simpler but slower than SPI.
  3. Final Answer:

    Faster data transfer speed -> Option D
  4. Quick Check:

    SPI speed > UART speed [OK]
Hint: SPI is fast and complex; UART is simple and slow [OK]
Common Mistakes:
  • Confusing wire count advantage
  • Mixing speed with simplicity
  • Assuming UART is faster
2. Which of the following is the correct way to describe UART wiring?
easy
A. Uses four wires including separate clock line
B. Uses two wires: TX and RX
C. Uses three wires: MOSI, MISO, and SCLK
D. Uses one wire for data and clock combined

Solution

  1. Step 1: Recall UART wiring basics

    UART typically uses two wires: one for transmitting (TX) and one for receiving (RX).
  2. Step 2: Eliminate other options

    SPI uses MOSI, MISO, and SCLK (3 wires), and UART does not use a separate clock line.
  3. Final Answer:

    Uses two wires: TX and RX -> Option B
  4. Quick Check:

    UART wires = TX + RX [OK]
Hint: UART always uses TX and RX wires only [OK]
Common Mistakes:
  • Confusing SPI wires with UART
  • Thinking UART needs clock wire
  • Assuming UART uses more than two wires
3. Given the following scenario: You need to communicate with three sensors quickly on the same bus. Which interface is best and why? Sensor1, Sensor2, Sensor3 connected to MCU
medium
A. SPI, because it supports multiple devices with separate select lines
B. SPI, because it uses fewer wires than UART
C. UART, because it is faster than SPI
D. UART, because it supports multiple devices easily

Solution

  1. Step 1: Analyze device count and speed needs

    Communicating with multiple sensors quickly requires an interface that supports multiple devices and high speed.
  2. Step 2: Match interface features

    SPI supports multiple devices using separate chip select lines and is faster than UART, which is simpler but slower and not ideal for multiple devices on one bus.
  3. Final Answer:

    SPI, because it supports multiple devices with separate select lines -> Option A
  4. Quick Check:

    Multiple devices + speed = SPI [OK]
Hint: Multiple devices + speed = SPI choice [OK]
Common Mistakes:
  • Choosing UART for multiple devices
  • Confusing speed advantage
  • Ignoring chip select lines in SPI
4. Identify the error in this SPI communication setup code snippet:
spi_init();
spi_select_device(1);
spi_send_byte(0xA5);
spi_deselect_device(1);
spi_send_byte(0x5A);
medium
A. No error, code is correct
B. Missing UART initialization
C. Sending data after deselecting device causes error
D. spi_select_device should be called twice before sending data

Solution

  1. Step 1: Review SPI device selection logic

    Data should be sent only when the device is selected; sending after deselecting is invalid.
  2. Step 2: Check code sequence

    After deselecting device 1, sending another byte without selecting a device is an error.
  3. Final Answer:

    Sending data after deselecting device causes error -> Option C
  4. Quick Check:

    Send data only when device selected [OK]
Hint: Always select device before sending data [OK]
Common Mistakes:
  • Ignoring device select/deselect order
  • Confusing UART with SPI code
  • Assuming multiple sends allowed without select
5. You want to design a communication system for a device that is 10 meters away and requires minimal wiring. Which interface should you choose and why?
hard
A. UART, because it uses fewer wires and works better over longer distances
B. SPI, because it is faster and supports multiple devices
C. SPI, because it uses fewer wires than UART
D. UART, because it supports multiple devices easily

Solution

  1. Step 1: Consider distance and wiring needs

    For 10 meters distance, simpler wiring and signal integrity are important.
  2. Step 2: Match interface to requirements

    UART uses fewer wires (TX, RX) and is better suited for longer distances than SPI, which requires more wires and is better for short distances.
  3. Final Answer:

    UART, because it uses fewer wires and works better over longer distances -> Option A
  4. Quick Check:

    Long distance + fewer wires = UART [OK]
Hint: Long distance + minimal wires = UART [OK]
Common Mistakes:
  • Choosing SPI for long distance
  • Confusing wire count
  • Ignoring distance limits of SPI
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard