Bird
0
0

You want to write a sequence of bytes [0x10, 0x20, 0x30] to consecutive registers starting at 0x00 on an I2C device at address 0x60 using smbus2. Which approach correctly achieves this?

hard🚀 Application Q15 of 15
Raspberry Pi - I2C Communication
You want to write a sequence of bytes [0x10, 0x20, 0x30] to consecutive registers starting at 0x00 on an I2C device at address 0x60 using smbus2. Which approach correctly achieves this?
AUse a loop calling <code>write_byte_data(0x60, register, value)</code> for each byte, incrementing register from 0x00
BCall <code>write_byte_data(0x60, 0x00, [0x10, 0x20, 0x30])</code> once to write all bytes
CUse <code>write_byte(0x60, 0x00, 0x10, 0x20, 0x30)</code> to send all bytes at once
DWrite only the first byte with <code>write_byte_data(0x60, 0x00, 0x10)</code> and ignore the rest
Step-by-Step Solution
Solution:
  1. Step 1: Understand write_byte_data limitations

    This function writes one byte to one register at a time.
  2. Step 2: Write bytes to consecutive registers

    Use a loop to write each byte to registers 0x00, 0x01, 0x02 respectively.
  3. Final Answer:

    Use a loop calling write_byte_data(0x60, register, value) for each byte, incrementing register from 0x00 -> Option A
  4. Quick Check:

    One byte per register via loop [OK]
Quick Trick: Write bytes one by one in a loop for consecutive registers [OK]
Common Mistakes:
MISTAKES
  • Trying to write multiple bytes in one write_byte_data call
  • Using write_byte incorrectly with multiple bytes
  • Ignoring the need to increment register address

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes