Challenge - 5 Problems
I2C vs SPI Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
I2C vs SPI: Which bus speed is faster?
Consider the following code snippets initializing I2C and SPI buses with typical speeds. What is the output when comparing their speeds?
Embedded C
#include <stdio.h> int main() { int i2c_speed = 400000; // 400 kHz int spi_speed = 10000000; // 10 MHz if (spi_speed > i2c_speed) { printf("SPI is faster\n"); } else { printf("I2C is faster\n"); } return 0; }
Attempts:
2 left
💡 Hint
Compare the numeric values of spi_speed and i2c_speed.
✗ Incorrect
SPI typically runs at higher clock speeds than I2C. Here, 10 MHz (SPI) is greater than 400 kHz (I2C), so SPI is faster.
🧠 Conceptual
intermediate1:00remaining
I2C vs SPI: Number of wires used
Which option correctly states the number of wires used by I2C and SPI respectively?
Attempts:
2 left
💡 Hint
Recall that I2C uses SDA and SCL lines.
✗ Incorrect
I2C uses two wires: SDA (data) and SCL (clock). SPI uses at least four wires: MOSI, MISO, SCLK, and SS (slave select).
❓ Predict Output
advanced2:00remaining
SPI data transfer behavior
What is the output of this SPI data transfer simulation code?
Embedded C
#include <stdio.h> int main() { unsigned char master_tx = 0xA5; // Master sends 0xA5 unsigned char slave_tx = 0x3C; // Slave sends 0x3C unsigned char master_rx = slave_tx; // Master receives slave data unsigned char slave_rx = master_tx; // Slave receives master data printf("Master received: 0x%X\n", master_rx); printf("Slave received: 0x%X\n", slave_rx); return 0; }
Attempts:
2 left
💡 Hint
SPI is full-duplex: master and slave exchange data simultaneously.
✗ Incorrect
In SPI, the master sends data to the slave while simultaneously receiving data from the slave. Here, master receives 0x3C from slave, and slave receives 0xA5 from master.
🧠 Conceptual
advanced1:30remaining
I2C addressing modes
Which statement correctly describes I2C addressing modes?
Attempts:
2 left
💡 Hint
Think about how many bits are used to identify devices on the bus.
✗ Incorrect
I2C devices can be addressed using either 7-bit or extended 10-bit addresses, allowing more devices on the bus.
🚀 Application
expert3:00remaining
Choosing between I2C and SPI for a sensor array
You have a sensor array with 8 identical sensors that need to send data to a microcontroller. The sensors require moderate speed and minimal wiring complexity. Which bus would be the best choice and why?
Attempts:
2 left
💡 Hint
Consider wiring complexity and device addressing for multiple sensors.
✗ Incorrect
I2C uses only two wires regardless of the number of devices and supports addressing each sensor uniquely, making it ideal for multiple sensors with minimal wiring.