I2C means Inter-Integrated Circuit Communication Method
This is one of the communication methods used by the sensors to transmit their data to Microcontrollers
you must have heard about I2C or you might have seen some such sensors which have SCL and SDA pins
so these SCL and SDA pins uses the I2C communication method to communicate with the Microcontroller
So, what exactly are these SDA and SCL pins?
What are it's working?
How does I2C communication works?
What is its flow?
I am going to explain you all these things
I2C is a very important topic to understand, because a lot of sensors communicates there data by using this communication
so, I request you all to read properly. so that you understand everything about I2C
so guys before going to I2C we'll consider an example
fig (a)
where we are having a Microcontroller which is Arduino and a device which is 7 segment display
so now If I want to control this device, than I'll have to send some data from Arduino to this device
so let's consider that the data which I want to send is 10101010
this 8 bit we have to send from Arduino to this device
so in order to send this data, What I'll do?, I'll use 8 digital pins
and to that 8 digital pins I'll connect the 7 segment display
and after that I'll send the data from each and every pin as shown in fig (a).
So what's going over here? fig (a).
over here for sending 8 bit data I am using 8 digital pins. so I am consuming a lot of digital pins and because of that, if I want to connect more devices to my microcontroller that's also not possible over here because for just 1 device I am using 8 digital pins so that's a huge disadvantage and to solve this issue I2C is designed
What happens in I2C?
over here first of all the microcontroller is called as a "Master" and the device from which we have to read the data or send the data is called as "Slave".
fig (B)
now over here in order to communicate we just require 2 pins which is SCL
and SDA
SCL means "Serial Clock"
and SDA means "Serial Data"
with the help of resistor boith the pins are pulled up to vcc, that vcc depeneds upon your microcontroller which can be 5v or it can also be 3.3v.
so that means SCL and SDA pins will always remain high initially, because both the pins are pulled up with the help of resistor and by using this SCL and SDA pins, not only one device in fact you can connect multiples devices over here as shown fig (c)
fig (c)
and that multiple devices can have multiple master or multiple slaves, over here to differentiate between the devices, device address are used, every device have its own unique device address. which we used in order to send or receive data from that device.
so guys, you can see over here that I2C has a huge importance, before this we where discussing about the 7 segment display as shown in fig(a). over there just for one 7 segment display we were using 8 digital pins and over here fig (c) i can connect so many devices to just 2 pins and can communicate. and not only this much devices in fact you can connect total 128 devices to the same SCL and SDA pins and you can control all that 128 devices from a single microcontroller, so this a huge feature of I2C.
now let's see that how such things are possible? how can we communicate with all these (fig(c)) devices using same SCL and SDA pins?
so let's see about SCL and SDA pins that how these pins communicates the data?
so for that we have to consider an example as shown in fig(d).
fig(d)
here we having a master and slave, this master wants to send a data to the slave that is 10101010 now, how that data is going to be send in I2C communication? let's see how it work!
first of all, what this master would do?
it will send a START bit to our slave whenever our master wants to communicate with slave every time it will send a START bit vaklue toi the slave and the value of that START bit is "0". as shown in fig (d.1)
fig(d.1)
so i already told you that SCL and SDA will always be pulled up so that means their values will always remain HIGH that is "1". and whenever our master wants to communicate with the slave than it will send a START bit which will be "0". so over here in fig (d.1) you can see it has sent "0" on wavefrom an as soon as this "0" gets sent after that our SCL pi that is serial clock will get start and after this it will start acting as a pulse, so this is the first process, that it will send a START Bit to the slave.
after that comes the Device address
to which device our master wants to send the data? we have to find that!
now over here as an example i have considered OLED display as shown in fig(d.2)
fig(d.2)
so the device Address of OLED display is "3C", which is HEX code and if it gets converted into Binary than it will be "111100".
in I2C communication method we can have a device address of 7 bit, so because of having this 7 bit address over here, we can connect 128 devices to master. because the maximum number of device addresses which can be possible will be 2^7=128. so that's why we can connect 128 devices to one single master.
now after sending the START Bit, it will send the Device Address and in this device address, first it will send this "0" than "1"and "1" and "1" and "1" and "0" and "0". so in this way it will send the device address to the slave.
now one more thing which is very important is that whenever our serial clock the SCL pin, whenever its HIGH at that time only it will send the data and because of that all the data are in synchronous and alligned and do not get mixed. so here fig(d.2) wavefrom you can see at first our serial clock became HIGH, than it sends "0" on next time when serial clock was HIGH it sends "1" than again next time when serial clock was HIGH again it sends "1", so similarly whenever this serial clock will get HIGH at that time only SDA pin will send the data. so this is how the transmission will take place from master to slave, now after sending the device address the next data which it sends is read/write data as shown in fig (d.3).
fig(d.3)
now here we have to tell the slave that, whether we want to read the data? or want to send the data? and if you want to read the data than our master will send "1" and if you want to write the data that means you want to send data to the slave at that time it will send "0".
now, over here its an OLED display that means we have to print the data on it, we have to send the data to the slave. so what we will do here is write, so for that the next data which ou master send that will be "0". so now, after sending the address it will send "0" that is read/write data. now, after sending read/write data the slave knows that, yes! master wants to communicate with me and the master wants to send me the data, than what this slave will do?
it will send an acknowledgement to the master as shown in fig (d.4)
fig(d.4)
and the value of this Acknowledgement is "0" and suppose if the slave is busy, slave is communicating with another master or else some other reasons are there because of which slave cannot communicate the data at that time, it will send "1". and if everything is proper our slave is ready to communicate at that time, it will send "0".
so over here the next data which sent after read/write data will be "0" in ACK, as shown in fig(d.4) wavefrom.
now as, this ACK is "0" gets received by the master, now the master is fully sure that it can send the data to the slave.
so now it will send the data to the slave as shown in fig(d.5)
fig(d.5)
and in this data first of all it will send "1" which will be stored in D7 after that it will send "0" which will be stored over D6 and after that it will send "1" that stored in D5 and similarly it will send all the data one by one into the slave.
fig(d.5) waveform, so you can see after acknowledgement it has sent "1" than "0" than again "1" and "0" and "1" and "0" and "1" and "0" so in this way it has sent the data to slave.
now, after receiving data from the slave now what slave will do?
again it will send an acknowledgement to the master as shown in fig(d.6)
fig(d.6)
from which the master is sure now that the data which master wanted to send have been now received by the slave and slave also have responded to that data.
now after sending Acknowledgement, what master will do?
it will stop the communication, it has sent the data now no more communication is needed so that's wjy let's stop the communication.
so, in order to stop the communication master will send a STOP Bit as shown in fig(d.7)
fig(d.7)
in fig(d.7) waveform which again will be "0" and after sending this STOP BIT the SCL and SDA pins again it will get HIGH now both the values will become "1" untill again a START BIT doesn't comes,m so this is how data transmission is done in I2C communication method. now, this transmission was to write the data on slave that means to send the data to the slave. if i have to receive a data from the slave at that time.
how this communication will take place let's see that!
so over here we are having another sensor as shown in fig (e)
fig(e)
who will send a data "10101010" to the master, now this data how will be sent?
over here first of all the master will initiate by sending a START BIT after that similarly it will send a Address bit. now after that what it will send? it will send the read/write data over here we have to read the data, so i have told you previously that in order to read the data it have to send "1" and to write the data we have to send "0".
so over here we have to read the data from the sensor so it will send "1" after that our sensor will respond in terms of Acknowledgment that will be "0". now, after this Acknowledgment our sensor will send all its data to the master.
so over here, the sensor have to send "101010101" to the master. so, that data have been sent now. now, when this data gets received on the master, the master in terms of Acknowledgment will send "1" to the slave
before this we have seen that if everything is proper than the slave sends "0" to the master, but over here if the data have been received by the master than master will send "1" as an Acknowledgment to the slave and after sending this Acknowledgment it will send a stop bit to stop the communication.
so this is how the process to read the data will happen in I2C communication method
Key Features of I2C Communication:
Half-duplex Communication: Bi-directional but not simultaneous communication.
Synchronous Transmission: Data is transferred in frames or blocks.
Multi-Master Configuration: Supports multiple masters in the system.
Clock Stretching: Slave can hold the clock low, preventing the master from raising it until ready.
Arbitration: Supports multi-master but only one active master at a time.
Serial Transmission: Utilizes serial transmission for data exchange.
Low-Speed Communication: Primarily designed for low-speedcommunication
I2C Specifications and Configurations
Maximum Speed:
Standard Mode (100 kbps)
Fast Mode (400 kbps)
High-Speed Mode (3.4 Mbps)
Ultra-Fast Mode (5 Mbps)
Wires Used:
Two wires
Have questions or need more information?
📞 Contact Mohammed shafwan at 6360322698
🌐 Visit us at https://sites.google.com/view/electromentor/project?authuser=0 for exciting updates and resources!