Understanding I2C Protocol
Today we are going to discuss about I2C communication. I2C is a Synchronus Tx and Rx communication. I2C stands for Inter Integrated Circuits. I2C is also known as TWI or Twin Wire Interface because it only requires two wires to communicate between different devices. I2C bus consists of SCL (Clock) and SDA (Data). In order to communicate to a slave, Master first sends the address byte along the data line. All slaves connected to the bus will match their addresses with the address sent by master. In case of a match, the respective slave sends the ACK (acknowledgement) to the master and communication begins.
[vc_message message_box_style=”3d” message_box_color=”mulled_wine”]
1.) Master transmit the START condition by pulling the SDA low. Note that SCL is kept high.
2.) Master transmit 7/10 bit address along with R/W (read/write) bit to indicate the operation type.
3.) Slaves start matching the transmitted address along with their’s. In case of a match, slave sends the ACK (acknowledgement).
4.) If the operation is write, master start transmitting data bytes to the slave. After each byte, slave sends the ACK to confirm the data received.
5.) If the operation is read, slave starts transmitting data to the master and after each byte received, master sends the ACK to the slave to confirm data received.
6.) After the completion of transfer, Master sends the stop signal by pulling the SDA high and transmission stops.[/vc_message]
As you might have noticed above that master is pulling SDA and SCL high and low. To ensure this operation a PULL-UP register (typically 4k7) must be connected to SDA and SCL.
First start (S) is transmitted by microcontroller. Next controller sends the address of the device, on receiving address, device sends the A (ack) signal back to master (controller).
Next, master sends data bits (04, 00, 24, 20).
After receiving each data byte, device sends the A(ack) to master acknowledging that it have received the data successfully .
At last controller sends P( stop) signal to indicate the end of communication.
I2C is very important part of embedded systems. As the address of slave is 7/10 bit long, we can connect 128/1024 slaves with a single master. This means we can control 128(7 bit address) devices with only two pins of our microcontroller. This reduces the need for using excessive wiring and also we have all other pins available for other purposes.
I2C is used in number of communications devices. For eg- RTC (ds1307), Lcd, OLEDs, Accelerometer (ADXL345), temperature sensors, pressure sensors, etc.
I will cover the coding part in upcoming tutorials.