Inter-Integrated Circuit(I2C) protocol is a serial communication protocol. It uses a master-slave paradigm to communicate with devices. I2C requires only two wires
I2C is a half-duplex protocol, meaning at once, only one device can send out data onto the bus. This is unlike SPI which is fully duplex where we are allowed to send and receive at the same time.
The default idle state for both SDA and SCL Is HIGH. When SDA and then SCL go low, the bus is said to have been claimed. The data frame transmitted is -
Some devices come with a fixed address. To use multiple devices with unchangable addresses, we can make use of a multiplexer like (Adafruit TCA9548A). We connect the multiplexer to the I2C bus, and connect the devices to the MUX's output. We then simply activate whatever MUX channel we want and it'll be as if the other devices aren't even there. Until we change the channel that is.
i2cdetect
is part of the i2c-tools
metapackage. It outputs addresses of I2C devices that are connected to the host device.
smbus2
is a Python library that is supposed to be a drop in replacment for its predecessor smbus
. It supports read/write operations on individual bytes, words or blocks of memory. The functions that have block
in them, are operating on a block of data and therefore expect an address, an offset, and the length of the block to operate on. And the ones without block will obviously not require the length argument.
Examples