|
|
This page provides the description of the I2C protocol and his implementation in Boardcore.
|
|
|
|
|
|
# I2C protocol
|
|
|
# I2C introduction
|
|
|
|
|
|
Inter-Integrated Circuit (IIC or, better, I2C) is a synchronous serial communication bus. This is used by some sensors and has the advantage to require only two wires for all the peripherals that want to communicate on the same physical bus, called **SCL** (serial clock line) and **SDA** (serial data line).
|
|
|
|
|
|
However this protocol have also some disadvantages as we will see. One of them is the low speed of the protocol, reaching 100 kHz of clock signal for the standard mode (Sm) and 400 kHz for the fast mode (Fm). Other disadvantages are that the protocol is a master/slave half duplex, meaning that the communication is always initiated by a device (master) that manages the communication generating the clock signal; the slave can only send data after a communication is intiated with him and the master communicates that he wants to read data from him.
|
|
|
|
|
|
## The protocol
|
|
|
In this section the general functioning of the I2C protocol is described, focusing on our parcticular usecase: we will use the I2C bus with a single master (the microcontroller) and multiple slaves (the sensors). Also, the microcontroller will never actively use his slave features.
|
|
|
|
|
|
The master is the only device that can drive the communication generating the clock on the SCL line.
|
|
|
|
|
|
Both SCL and SDA lines have pull-ups in order to drive the signal up by default.
|
|
|
|
|
|
When the master wants to do an operation (a read or a write) on a parcticular slave, it:
|
|
|
1. generates a START condition, that means to drive to the low level the SDA while the SCL is still high;
|
|
|
2. Communicate the address and the operation the master wants to perform (in _7-bit addressing_ the address is sent along with the operation bit, 0 for write and 1 for read. in 10-bit addressing there is also a header involved; for further informations see the reference manual).
|
|
|
3. If a slave recognizes his address, the SDA is pulled down in order to send a slave ACK.
|
|
|
|
|
|

|
|
|
|
|
|
Inter-Integrated Circuit (IIC or, better, I2C) is a serial bus protocol. This is used by some sensors and has the advantage to need only two wires for all the peripherals that want to communicate on the same physical bus, called SCL (serial clock line) and SDA (serial data line). However this protocol have also some disadvantages as we will see. One of them is the low speed of the protocol, reaching 100 kHz of clock signal for the standard mode (Sm) and 400 kHz for the fast mode (Fm). Other disadvantages are that the protocol is a master/slave half duplex, meaning that the communication is always initiated by a device (master) that manages the communication generating the clock signal; the slave can only send data after a communication is intiated with him and only when the master communicates to that slave that he wants to read data from him.
|
|
|
|
|
|
# _Deadlocks are a feature, not a bug!_
|
|
|
|
|
|
Kidding, they are not. Unluckly the I2C bus can get in a locked state in particular conditions. These cases, their origin and the solutions provided in the driver will be explained in the following paragraphs.
|
|
|
|
|
|
- Master peripheral deadlock:
|
|
|
- Slave bus deadlock: |
|
|
- Slave bus deadlock: |
|
|
\ No newline at end of file |