0

I can't find any good documentation for the python-smbus package recommended to communicate over I2C on Raspberry Pi. I see there are several write commands including write_byte_data and write_block_data. Is write_block_data practically different from several write_byte_data?

Eg, are these equivalent?

bus.write_block_data(ADDRESS, REGISTER, (0x05, 0x12, 0xff))

bus.write_byte_data(ADDRESS, REGISTER, 0x05)
bus.write_byte_data(ADDRESS, REGISTER, 0x12)
bus.write_byte_data(ADDRESS, REGISTER, 0xff)
2
bus.write_block_data(ADDRESS, REGISTER, (0x05, 0x12, 0xff))

The above is a single bus transaction.

bus.write_byte_data(ADDRESS, REGISTER, 0x05)
bus.write_byte_data(ADDRESS, REGISTER, 0x12)
bus.write_byte_data(ADDRESS, REGISTER, 0xff)

The above is three distinct bus transactions.

As well as the overhead of three separate transactions you need to take into account how the I2C device defines its protocol. Depending on the device those two examples might have the same or different results. There is no one rule, you have to check each device datasheet.

  • In general, one had also take care of not creating unneccessary stop conditions as another bus master may take over after a stop. That's something missing in most I²C libraries as multimaster setups aren't common. – Janka Jan 28 '18 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.