PV198 Study Materials

Preliminaries

Theory

- Introduction

- GPIO

- Interrupts

- Timer

- PWM

- ADC

- Communication buses

- SPI

- I2C

- UART

Practical

I2C

I2C - Inter-Integrated Circuit is a common bus used for intra-board communication.

Properties

I2C is a bus, half-duplex, synchronous, and master/slave. It works only over two signal wires:

One transfer of data works in transactions in which messages made of bytes are sent over the SDA line. This is clocked by the SCL line.

Each device has its address which has to be unique on the bus. Each message contains the address of the target device.

We can have multiple masters. (Which is rare)

I2C bus

Addressing

I2C supports two addressing modes - 7bit and 10bit. The addresses have to be unique.

In the case of MCUs, it is usually trivial to set up any address. In the case of ICs, the manufacturers tend to give a basic address and some method for changing the last few bits of the address.

For example: the first 5 bits are fixed, and the last 2 can be varied by connecting two specific pins of IC to HIGH or LOW.

Bus

Let’s assume that we have only one master.

Any communication is initiated by the master, which sends at least one message in the transaction.

The first byte of the message contains the address of the slave device and the direction of communication (read/write). Following that, based on the direction of communication:

Apart from the plain sending of data, bytes are confirmed by ACK bit from the other side of the communication.

Message

The logical content of the message looks as follows:

I2C message

What data represents is content specific. In the case of I2C, the common pattern is to have an abstraction of registers. The slave device has a set of registers (usually with a size of 1 byte and at properly defined addresses). Any interaction with the device works in terms of:

This abstraction gives some shared form to the communication process, which translates into the following transactions:

I2C transaction

Notice that the read of a register is made of two messages.

Usage

There are various devices or ICs, that use I2C for communication. Out of all of those, two use cases stand out as curiosity: VGA and HDMI. Both interfaces use I2C to allow control of devices over the cable or to transfer meta-information.