Bird
Raised Fist0
Embedded Cprogramming~10 mins

I2C vs SPI decision matrix in Embedded C - Interactive Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize an I2C communication with the correct clock speed.

Embedded C
I2C_Init([1]);
Drag options to blanks, or click blank then click option'
A100000
B500000
C1000000
D2000000
Attempts:
3 left
💡 Hint
Common Mistakes
Using SPI clock speeds instead of I2C speeds.
2fill in blank
medium

Complete the code to select the SPI mode that supports full-duplex communication.

Embedded C
SPI_SetMode([1]);
Drag options to blanks, or click blank then click option'
ASPI_MODE_0
BSPI_MODE_1
CSPI_MODE_2
DSPI_MODE_3
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing SPI modes with half-duplex modes.
3fill in blank
hard

Fix the error in the code to correctly read a byte from an I2C device.

Embedded C
uint8_t data = I2C_ReadByte([1]);
Drag options to blanks, or click blank then click option'
Agpio_pin
Bspi_channel
Cdevice_address
Dbaud_rate
Attempts:
3 left
💡 Hint
Common Mistakes
Passing SPI channel or GPIO pin instead of device address.
4fill in blank
hard

Fill both blanks to create a decision matrix entry for choosing SPI over I2C.

Embedded C
if (speed > [1] && devices > [2]) {
    use_spi = true;
}
Drag options to blanks, or click blank then click option'
A400000
B5
C10
D100000
Attempts:
3 left
💡 Hint
Common Mistakes
Using I2C speed values or wrong device count.
5fill in blank
hard

Fill all three blanks to complete the function that decides between I2C and SPI based on speed, device count, and wiring complexity.

Embedded C
bool choose_spi(int speed, int devices, int wiring_complexity) {
    if (speed > [1] && devices > [2] && wiring_complexity < [3]) {
        return true;
    } else {
        return false;
    }
}
Drag options to blanks, or click blank then click option'
A400000
B3
C10
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing device count and wiring complexity values.

Practice

(1/5)
1. Which communication protocol uses only 2 wires and is suitable for connecting many devices with simple wiring?
easy
A. UART
B. SPI
C. CAN
D. I2C

Solution

  1. Step 1: Recall wire count for I2C

    I2C uses 2 wires: SDA (data) and SCL (clock).
  2. Step 2: Compare with SPI wiring

    SPI uses 4 wires, so it is not the protocol with only 2 wires.
  3. Final Answer:

    I2C -> Option D
  4. Quick Check:

    2 wires = I2C [OK]
Hint: I2C always uses 2 wires, SPI uses 4 wires [OK]
Common Mistakes:
  • Confusing SPI as 2-wire protocol
  • Thinking UART or CAN use 2 wires for multi-device
  • Mixing up data and clock lines
2. Which of the following is the correct way to describe SPI wiring in embedded C context?
easy
A. SPI uses 3 wires: TX, RX, and CLK
B. SPI uses 2 wires: SDA and SCL
C. SPI uses 4 wires: MOSI, MISO, SCLK, and SS
D. SPI uses 1 wire for data

Solution

  1. Step 1: Identify SPI signal lines

    SPI uses 4 wires: MOSI (Master Out Slave In), MISO (Master In Slave Out), SCLK (clock), and SS (slave select).
  2. Step 2: Eliminate incorrect options

    Options B, C, and D do not list the correct 4 SPI wires.
  3. Final Answer:

    SPI uses 4 wires: MOSI, MISO, SCLK, and SS -> Option C
  4. Quick Check:

    SPI = 4 wires (MOSI, MISO, SCLK, SS) [OK]
Hint: SPI always has MOSI, MISO, SCLK, and SS wires [OK]
Common Mistakes:
  • Confusing SPI with I2C wire names
  • Forgetting slave select (SS) wire
  • Assuming SPI uses only 2 or 3 wires
3. Given the following scenario: You need to connect 8 sensors to a microcontroller and require moderate speed communication. Which protocol is best suited?
medium
A. I2C, because it supports multiple devices with simple wiring
B. SPI, because it supports many devices easily
C. SPI, because it uses only 2 wires
D. I2C, because it is faster than SPI

Solution

  1. Step 1: Analyze device count and wiring complexity

    Connecting 8 sensors means many devices; I2C supports multiple devices on 2 wires easily.
  2. Step 2: Consider speed and wiring

    I2C is moderate speed but simpler wiring; SPI is faster but wiring gets complex with many devices.
  3. Final Answer:

    I2C, because it supports multiple devices with simple wiring -> Option A
  4. Quick Check:

    Many devices + simple wiring = I2C [OK]
Hint: Many devices + simple wiring = I2C [OK]
Common Mistakes:
  • Choosing SPI for many devices ignoring wiring complexity
  • Assuming SPI uses 2 wires
  • Thinking I2C is faster than SPI
4. You wrote code to communicate with a sensor using SPI but the data is corrupted. Which of these is a likely cause?
medium
A. Using only 2 wires instead of 4 for SPI
B. Connecting multiple devices on I2C bus
C. Using I2C speed settings for SPI communication
D. Using pull-up resistors on SPI lines

Solution

  1. Step 1: Check wiring requirements for SPI

    SPI requires 4 wires; using only 2 wires can cause data corruption.
  2. Step 2: Evaluate other options

    Options A and C relate to I2C or speed mismatch, less likely cause of SPI data corruption; pull-ups on SPI lines are usually not needed.
  3. Final Answer:

    Using only 2 wires instead of 4 for SPI -> Option A
  4. Quick Check:

    SPI needs 4 wires, missing wires cause errors [OK]
Hint: SPI needs all 4 wires connected for reliable data [OK]
Common Mistakes:
  • Using I2C settings for SPI communication
  • Ignoring missing wires in SPI
  • Adding pull-up resistors unnecessarily on SPI
5. You want to design a system with 3 devices requiring very fast data transfer and minimal wiring complexity. Which protocol should you choose and why?
hard
A. I2C, because it uses fewer wires and supports fast speed
B. SPI, because it supports fast data transfer with fewer devices
C. I2C, because it supports many devices even if slower
D. SPI, because it uses only 2 wires and is simple

Solution

  1. Step 1: Analyze device count and speed needs

    3 devices is a small number; SPI is better for fast data transfer with fewer devices.
  2. Step 2: Consider wiring complexity

    SPI uses 4 wires but with fewer devices wiring is manageable; I2C is slower though uses 2 wires.
  3. Final Answer:

    SPI, because it supports fast data transfer with fewer devices -> Option B
  4. Quick Check:

    Few devices + fast speed = SPI [OK]
Hint: Few devices + fast speed = SPI [OK]
Common Mistakes:
  • Choosing I2C for fast speed needs
  • Assuming SPI uses only 2 wires
  • Ignoring device count impact on wiring
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