I2C Protocol
IIC: Inter Integrated Circuit
-Inter ICs: External to ICs.
-Intra ICs: Internal to ICs.(This is not a thing, kept here, just to explain the meaning of the word Inter )
-Communication between ICs.
-Its a 2 wire protocol.
-SDA Line and SCL Line.
SDA: Data Line , SCL: Clock Line
1) Why do you even need a clock?
-Let me give you a perspective. When we humans talk, you may assume that the most important thing in the communication is the content that we speak, the words.
-I believe, this is wrong.
-I believe, the most important aspect of our verbal communication is the voids that we unintentionally keep in our sentences.(Ever wondered why it is tough to understand the person stating the risks of mutual fund investing in TV commercials? That's because he is not maintaining any voids in his statement while speaking his lines.)
-The voids between the words are the content that gives meaning to independent words. For eg: aparentlythislinewontmakemuchsensetoyoubecausethereisnogapinbetween. ;)
-A clock in the digital world provides exactly this.
-It provides a gap, a void to let the other entity derive meaningful conclusions from the change in the information.
-If I keep constant 5V on the Data Line for a second, it won't be much understandable, because it could be a series of 10 1s each of 100 ms, it could be 1000 1s each of 1ms. It could be your rommate demanding a Pizza at 1AM, It could be anything.
-But, when I keep constant 5V on the Data Line, validated by a parallel clock signal, I'm making it clear that the data is supposed to be read, only and only when the clock line is high. So the number of 1s, is exactly equal to the number of valid highs on the clock line based on the frequency of the clock, this will be very much deterministic.
2) Interviewers' fantasy for Start / Stop Condition.
-In the normal data transfer phase, there is no transition (either high to low, or low to high) of the data line when a clock is stable high.
-Start condition and stop condition are an exception to this.
-Start condition is when the SDA line is intentionally pulled down, when a clock is stable high.
-Stop Condition is when a SDA line is intentionally released high, when a clock is stable high.
-Remember the sole purpose of the clock line? Yup, thats why there are transitions when the SCL line is high. To indicate start/stop of the communication.
3) NACK: Not ACKnowledged
There are five conditions that lead to the generation of a NACK:
a) No receiver is present on the bus with the transmitted address so there is no device to respond with an acknowledge.(No one to physically pull the SDA low.)
b)The receiver is unable to receive or transmit because it is performing some real-time function and is not ready to start communication with the master.
c) During the transfer, the receiver gets data or commands that it does not understand.
d) During the transfer, the receiver cannot receive any more data bytes.
e) A master-receiver must signal the end of the transfer to the slave transmitter.
4) Why do we pull SDA LOW when we need to convey something?
-We pull SDA low as Start condition, we pull SDA low for ACK bit. Why?
-Pulling down a line is much easier than to push a line high, due to the natural design of the electricity and electrons in general.
-Electricity tends to take the least opposing route, which is usually approaching the ground via a pull down resistor.
-Any Entity trying to Pull UP a line, while it is being actively pulled down by another, will always fail to pull the Line UP, because the electricity would prefer to flow directly to the ground with much less opposition.
-This proves to be very strong mode of communication. Hence, conveying important situations like Start bit and ACK etc. needs a PULL DOWN of the SDA, which is validated by a parallel HIGH SCL line.
-This is a very strong indication, that someone more powerful is present on the line and we are not supposed to write on it. Better off reading from it.
-This is how multiple master ICs detect if there are any more masters present on the line.(Arbitration)
For more Information: Consider refering this guide.