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.
- Master transmit the START condition by pulling the SDA low. Note that SCL is kept high
- Master transmit 7/10 bit address along with R/W (read/write) bit to indicate the operation type
- Slaves start matching the transmitted address along with theirs’s. In case of a match, slave sends the ACK (acknowledgement)
- 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
- 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
- After the completion of transfer, Master sends the stop signal by pulling the SDA high and transmission stops
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)
- 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.
100%
Recent Posts
- WavePlayer using STM32 Discovery January 16, 2021
- How to use SPI in LPC2148 December 26, 2020
- STM32 ADC MULTI CHANNEL WITHOUT DMA December 24, 2020
- Send and Receive data to PC without UART (STM32 USB COM) December 10, 2020
- STM32 GPIO INPUT Configuration December 4, 2020
- STM32 GPIO OUTPUT Config using REGISTERS November 24, 2020