Bird
0
0

What is wrong with this SPI display initialization code?

medium📝 Debug Q7 of 15
Raspberry Pi - SPI Communication
What is wrong with this SPI display initialization code?
import spidev
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = -1000000
spi.xfer2([0x00])
Aspi.xfer2() requires a string, not list
Bmax_speed_hz cannot be negative
Cspi.open() must be called after setting speed
Dspidev.SpiDev() is not the correct class
Step-by-Step Solution
Solution:
  1. Step 1: Check max_speed_hz value validity

    max_speed_hz must be a positive integer representing clock speed.
  2. Step 2: Identify invalid negative speed

    Setting max_speed_hz to -1000000 is invalid and causes error.
  3. Final Answer:

    max_speed_hz cannot be negative -> Option B
  4. Quick Check:

    max_speed_hz must be positive integer [OK]
Quick Trick: SPI clock speed must be positive [OK]
Common Mistakes:
MISTAKES
  • Using negative speed values
  • Passing wrong data types to xfer2()
  • Calling open() after setting speed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes