Bird
0
0

Which code correctly sends the command first, then the data, assuming spi is already opened?

hard🚀 Application Q15 of 15
Raspberry Pi - SPI Communication
You want to send a command byte 0xA5 followed by data bytes [0x01, 0x02, 0x03] to an SPI display using spidev. Which code correctly sends the command first, then the data, assuming spi is already opened?
Aspi.writebytes([0xA5, 0x01, 0x02, 0x03])
Bspi.xfer2([0xA5, 0x01, 0x02, 0x03])
Cspi.xfer2([0xA5]); spi.xfer2([0x01, 0x02, 0x03])
Dspi.writebytes([0xA5]); spi.writebytes([0x01, 0x02, 0x03])
Step-by-Step Solution
Solution:
  1. Step 1: Understand command and data separation

    Many SPI displays require sending command and data separately to distinguish them.
  2. Step 2: Check code options

    spi.xfer2([0xA5]); spi.xfer2([0x01, 0x02, 0x03]) sends command byte first, then data bytes in separate calls, matching typical display protocol.
  3. Final Answer:

    spi.xfer2([0xA5]); spi.xfer2([0x01, 0x02, 0x03]) -> Option C
  4. Quick Check:

    Separate command and data transfers [OK]
Quick Trick: Send command and data in separate SPI transfers [OK]
Common Mistakes:
MISTAKES
  • Sending command and data in one transfer
  • Using writebytes() which may not return response
  • Not separating command from data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes