Bird
0
0

You want to send the bytes [0x10, 0x20, 0x30] to an SPI device on bus 1, device 0, at 500000 Hz speed, and receive the response. Which code snippet correctly does this using spidev?

hard🚀 Application Q15 of 15
Raspberry Pi - SPI Communication
You want to send the bytes [0x10, 0x20, 0x30] to an SPI device on bus 1, device 0, at 500000 Hz speed, and receive the response. Which code snippet correctly does this using spidev?
Aspi = spidev.SpiDev() spi.open(1, 0) spi.max_speed_hz = 500000 response = spi.xfer2([0x10, 0x20, 0x30]) spi.close() print(response)
Bspi = spidev.SpiDev() spi.open(0, 1) spi.speed = 500000 response = spi.xfer([0x10, 0x20, 0x30]) spi.close() print(response)
Cspi = spidev.SpiDev() spi.open(1, 0) spi.max_speed = 500000 response = spi.xfer2([0x10, 0x20, 0x30]) spi.close() print(response)
Dspi = spidev.SpiDev() spi.open(1, 0) spi.max_speed_hz = 500000 response = spi.transfer([0x10, 0x20, 0x30]) spi.close() print(response)
Step-by-Step Solution
Solution:
  1. Step 1: Check SPI open parameters and speed setting

    Bus 1, device 0 is opened with spi.open(1, 0). Speed is set with spi.max_speed_hz = 500000.
  2. Step 2: Verify transfer method and closing

    xfer2() is the correct method to send and receive bytes. The device is closed after communication.
  3. Final Answer:

    Correct code snippet with spi.open(1, 0), max_speed_hz, xfer2(), and close() -> Option A
  4. Quick Check:

    Use open(1,0), max_speed_hz, xfer2(), close() [OK]
Quick Trick: Set max_speed_hz and use xfer2() after open() [OK]
Common Mistakes:
MISTAKES
  • Using wrong bus/device numbers
  • Setting speed with wrong attribute name
  • Using incorrect transfer method name
  • Not closing SPI device

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes