I2C Interview Questions, You should know

i2c protocol questions

In this article, I have tried to collect I2C Interview questions which can ask by your Interviewer. I have already written an article on I2C protocol if you have not seen this article, you should read this article before starting this Q&A.



What is I2C communication?

I2C is a serial communication protocol. It provides good support to the slow devices, for example, EEPROM, ADC, I2C LCD, and RTC etc. It is not only used with the single board but also used with the other external components which have connected with boards through the cables.

I2C is basically a two-wire communication protocol. It uses only two wire for communication. In which one wire is used for the data (SDA) and other wire is used for the clock (SCL).

In I2C, both buses are bidirectional, which means master able to send and receive the data from the slave. The clock bus is controlled by the master but in some situations slave is also able to suppress the clock signal, but we will discuss it later.

Additionally, an I2C bus is used in the various control architecture, for example, SMBus (System Management Bus), PMBus (Power Management Bus), IPMI (Intelligent Platform Management Interface) etc.

 

What does I2C stand for?

Inter-Integrated Circuit

 

How many wires are required for I2C communication?

In I2C only two buses are required for the communication, the serial data bus (SDA) and serial clock bus (SCL).

 

I2C is half-duplex or full-duplex?

half-duplex

 

I2C is Synchronous or Asynchronous Communication?

I2C is Synchronous Communication

 

Explain the physical layer of the I2C protocol

I2C is pure master and slave communication protocol, it can be the multi-master or multi-slave but we generally see a single master in I2C communication. In I2C only two-wire are used for communication, one is data bus (SDA) and the second one is the clock bus (CLK).

All slave and master are connected with same data and clock bus, here important thing is to remember these buses are connected to each other using the WIRE-AND configuration which is done by to putting both pins is open drain. The wire-AND configuration allows in I2C to connect multiple nodes to the bus without any short circuits from signal contention.

The open-drain allows the master and slave to drive the line low and release to high impedance state. So In that situation, when master and slave release the bus, need a pull resistor to pull the line high. The value of the pull-up resistor is very important as per the perspective of the design of the I2C system because the incorrect value of the pull-up resistor can lead to signal loss.

Note: We know that I2c communication protocol supports multiple masters and multiple slaves, but most system designs include only one master.

 

If you want to learn STM32 from scratch, you should follow this course “Mastering Microcontroller with Embedded Driver Development“. The course contains video lectures of 18.5-hours length covering all topics like, Microcontroller & Peripheral Driver Development for STM32 GPIO, I2C, SPI, USART using Embedded C.

 

Enroll In Course

 

Explain the operation and frame of I2C protocol

I2C is a  chip to chip communication protocol. In I2C, communication is always started by the master. When the master wants to communicate with slave then he asserts a start bit followed by the slave address with read/write bit.

After asserting the start bit, all slave comes in the attentive mode. If the transmitted address match with any of the slave on the bus then an ACKNOWLEDGEMENT (ACK) bit is sent by the slave to the master.

After getting the ACK bit, master starts the communication. If there is no slave whose address match with the transmitted address then master received a NOT-ACKNOWLEDGEMENT (NACK) bit, in that situation either master assert the stop bit to stop the communication or assert a repeated start bit on the line for new communication.

When we send or receive the bytes in i2c, we always get a NACK bit or ACK bit after each byte of the data is transferred during the communication.

In I2C, one bit is always transmitted on every clock. A byte which is transmitted in I2C could be an address of the device, the address of register or data which is written to or read from the slave.

In I2C, SDA line is always stable during the high clock phase except for the start condition, stop condition and repeated start condition. The SDA line only changes their state during the low clock phase.

See the below image,

i2c frame

Start Bit: Start the communication

Stop bit: Stop communication.



What is START bit and STOP bit?

Start Condition:

The default state of SDA and SCL line is high. A master asserts the start condition on the line to start the communication. A high to low transition of the SDA line while the SCL line is high called the START condition. The START condition is always asserted by the master. The I2C bus is considered busy after the assertion of the START bit.

i2c start bit

Stop Condition:

The STOP condition is asserted by the master to stop the communication. A Low to high transition of SDA line while the SCL line is high called the STOP condition. The STOP condition is always asserted by the master. The I2C bus is considered free after the assertion of the STOP bit.

I2c stop

Note: A START and STOP condition always asserted by the master.

 

Note: You can also see, Embedded c interview questions

 

What is the repeated start condition?

The repeated start condition similar to the START condition but both are different from each other. The repeated start is asserted by the master before the stop condition (When the bus is not in an idle state).

A Repeated Start condition is asserted by the master when he does not want to lose their control from the bus. The repeated start is beneficial for the master when it wants to start a new communication without asserting the stop condition.

Note: Repeated start is beneficial when more than one master connected with the I2c Bus.

 

 

What is the standard bus speed in I2C?

There are following speed mode in I2C

                      MODE                          SPEED
                      Standard-mode                       100 kbit/s
                        Fast-mode                       400 kbit/s
                     Fast-mode Plus                       1 Mbit/s
                     High-speed mode                       3.4 Mbit/s

 

What is the limiting factor as to how many devices can go on the I²C bus?

It depends on the total capacitance.

 

Who sends the start bit?

In I2C master sends the start bit.

 

What is the maximum bus length of the I2C bus?

It depends on the bus load (capacitance) and the speed. Basically, I2C is not designed for long-distance. It is limited to a few meters. For fast mode and resistor pullup, capacitance should be less than 200pF, according to the “UM10204.pdf” NXP document. So If your wire is 20pF/25cm and you have another 80pF of stray and input capacitance, you’re limited to 1.5m of cable length. But it is only a rough assumption. It can vary in real scenarios.

 

How many kinds of addressing structures are there in I2C?

Right now two addressing support by I2C, 7-bit, and 10 -bit.

 

Is it possible to have multiple masters in I2C?

Yes I2C support multiple master and multiple slaves.




What is a bus arbitration?

The arbitration is required in the case of a multi-master, where more than one master is tried to communicate with a slave simultaneously. In I2C arbitration is achieved by the SDA line.

For Example,
Suppose two masters in the I2C bus is tried to communicate with a slave simultaneously then they will assert a start condition on the bus. The SCL clock of the I2c bus would be already synchronized by the wired and logic.

arbitration in i2c

In the above case, everything will be good till the state of SDA line will same what is the masters driving on the bus. If any master sees that the state of SDA line differs, what is it driving then they will exit from the communication and lose their arbitration.

Note: Master which is losing their arbitration will wait till the bus become free.

 

 

What is I2C clock stretching?

In I2c, communication can be paused by the clock stretching to holding the SCL line low and it cannot continue until the SCL line released high again.

clock stretching in i2c

In I2C, slave able to receive a byte of data on the fast rate but sometimes slave takes more time in processing the received bytes in that situation slave pull the SCL line to pause the transaction and after the processing of the received bytes, it again released the SCL line high again to resume the communication.

The clock stretching is the way in which slave drive the SCL line but it is the fact, most of the slave does not drive the SCL line

Note: In the I2c communication protocol, most of the I2C slave devices do not use the clock stretching feature, but every master should support the clock stretching.

 

What is I2C clock synchronization?

Unlike Rs232, I2c is synchronous communication, in which the clock is always generated by the master and this clock is shared by both master and slave. In the case of multi-master, all master generate their own SCL clock, hence it is necessary that the clock of all master should be synchronized. In the i2C, this clock synchronization is done by wired and logic.

For a better understanding, I am taking an example, where two masters try to communicate with a slave. In that situation, both masters generate their own clock, master M1 generate clk1 and master M2 generate clk2 and clock which observed on the bus is SCL.

The SCL clock would be the Anding (clk1 & clk2) of clk1 and clk2 and most interesting thing is that highest logic 1 of SCL line defines by the CLK which has lowest logic 1.



When must data be stable for a correct I²C bus transaction?

When the clock is high

 

Is Hot swapping possible in I2C protocol?

Yes, hot swapping is possible in I2C.

 

Can devices be added and removed while the system is running in I2C?

Yes because Hot swapping is possible in I2C protocol.

 

Which is better to use I2C or SPI?

Each communication protocol has own advantage and disadvantage. You can not say blindly which one is better SPI and I2C. SPI has its own benefits and I2C has its own benefits. We select the protocol as per the project requirement. You can check the article to SPI vs I2C for more detail.

 

What is the application of the I2C protocol?

It is connected with serial RAM, LCD, EEPROM, and its use within the television sets.

 

If a slave is servicing an internal interrupt, what will it do to avoid losing data?

The slave will stretch the clock until the interrupt servicing is complete.

 

Can we monitor the I2C bus?

Yes, we can. There are many analyzers available, you can check this analyzer “Siglent SDS1104X-E “.

 

Advantages of I2C communication?

There is a lot of advantage of I2C protocol which makes the user helpless to use the I2C protocol in many applications.

  • It is the synchronous communication protocol, so there is no need of a precise oscillator for the master and slave.
  • It requires only two-wire, one wire for the data (SDA) and other wire for the clock (SCL).
  • It provides the flexibility to the user to select the transmission rate as per the requirements.
  • In I2C bus, each device on the bus is independently addressable.
  • It follows the master and slave relationships.
  • It has the capability to handle multiple masters and multiple slaves on the I2C Bus.
  • I2C has some important features like arbitration, clock synchronization, and clock stretching.
  • I2C provides ACK/NACK (acknowledgment/ Not-acknowledgement) features that provide help in error handling.

 

What are the limitations of I2C interface?

  • Half-duplex communication, so data is transmitted only in one direction (because of the single data bus) at a time.
  • Since the bus is shared by many devices, debugging an I2C bus (detecting which device is misbehaving) for issues is pretty difficult.
  • The I2C bus is shared by multiple slave devices if anyone of these slaves misbehaves (pull either SCL or SDA low for an indefinite time) the bus will be stalled. No further communication will take place.
  • I2C uses resistive pull-up for its bus. Limiting the bus speed.
  • Bus speed is directly dependent on the bus capacitance, meaning longer I2C bus traces will limit the bus speed.

What is the difference between SPI and I2C (I2C vs SPI)?

You can see this article, Difference between I2c and SPI

Questions for you:

  • What is locking(or waiting) and unlocking the I2c protocol? How you could design the unlocking I2c protocol for your system.
  • What happens if two devices have the same priority in I2C bus arbitration?
  • I2C is Edge Triggering or Level Triggering?
  • What is the maximum number of devices that can be connected to an I2C bus?
  • Is in I2c two slaves have the same address?
  • How will the master indicate that it is either address/data? How will it intimate to the slave that it is going to either read/write?
  • What is the voltage level for 0 and 1 in I2C?
  • How do I2C devices handle errors and retries during communication?
  • How could a slave send the data to the Master in I2C while the master is communicating with another slave?
  • How does I2C bus arbitration work?
  • What is I2C Multiplexing?
  • What is the priority in I2C bus arbitration?
  • Why I2C Protocol is Designed?

Recommended Post

 



8 comments

    1. When the master sends data to the slave successfully then get ACK bit. But ACK doesn’t mean a byte was received correctly. Other than the address byte, it only means that the clock was received correctly. If your design is proper then your slave will receive correct data. If a slave does not receive the correct data then you should check your hardware first. Another hand if your intent is to guarantee the integrity of the I2C line and your slave is microcontroller so you can also use CRC for bulk data to verify the integrity of the data.

  1. Thanks to you bro for doing such a great work. I have a request for you, Kindly post interview ques based on UART and if possible SPI also.

  2. I have got an issue where we are passing Queued-SPI data frames by .Master Micro-controller is configured at speed 1MHz. Here we are trying for Full-Duplex communication. Where Mosi line has 20Bytes to transfer and MISO line has 18 Bytes to transfer. just to synchronize can we add 2 dummy bytes in MISO line or how do we achieve this synchronization?

Leave a Reply

Your email address will not be published. Required fields are marked *