What is I2C:A No-Nonsense Explanation for You in this page. A Beginner-Friendly Breakdown of I2C; where just two connections can transmit limitless information between devices...


Introduction to what is I2C

What is I2c? - Well, I2C, also known as Inter-Integrated Circuit, is a serial communication protocol used to connect microcontrollers, sensors, and other devices together in electronics projects.

The key point is that you can connect multiple devices to the same 2-wire I2C bus and control any of them on command.

Note: I2C should be written as I2C - I squared C, that reflects the name Inter-Integrated Circuit; but no one bothers cos it's so hard to write (sarcasm!).

As well as control, you can request and send data. This means you can connect complex devices and even devices that need data such as displays e.g. SSD1306. You can gather data from devices such as ADCs e.g. ADS1115.

There are many, many more and you can find a lot of pages about them on this site.

The reason the I2C protocol is so popular is that it reduces all wiring to just 2 wires. You can have a 16 bit ADC (ADS1115) that, if you did not have the I2C interface, you would need 16 wires to connect it to your microcontroller!

What can you use I2C for?

One way of understanding what is I2C is to ask what is it used for, and the answer is :

    A lot!

I2C is commonly used for connecting peripherals like sensors, LCD displays, real-time clocks (RTCs), and other microcontrollers together in an embedded system. Its bidirectional two-wire interface makes it an efficient way to exchange data between multiple slave devices and a master controller. Some common applications of I2C include:

  • Reading sensor data from temperature, light, pressure, motion, and other analog or digital sensors.
  • Displaying output on LCD or character displays.
  • Synchronizing time on an RTC chip.
  • Communicating between a microcontroller and secondary microcontrollers acting as slaves.
  • Expanding memory using an external EEPROM or flash memory chip.

You might have missed it but in the paragraph above I said "connecting...microcontrollers together". You can actually send data between controllers - it is not just from a microcontroller to a slave device.

More detail on What is I2C

As an embedded system interface, I2C allows for easy communication between integrated circuits using just two bidirectional open-drain lines - SDA (data) and SCL (clock).

One device on the I2C bus acts as a master controller while other devices are slave nodes. Communication is initiated by the master which controls the SCL clock signal.

During data transmission, the master sends addresses and data to specific slave devices over the SDA line while clocking the SCL line. Slave devices listen for addresses on the bus. If a slave's address is detected, it responds by receiving or transmitting data.

I2C addresses


This brings up your next question :
Where is the address and how does a slave device even have an address?
The address uniquely identifies a device on the I2C bus so that a master controller can communicate with it.

The answer is that device manufacturers are given a range of addresses that they can use - they then hard code that address into a device.

Now your follow up question:
What if two devices have the same address?
It's not common but it could happen. The answer is that usually you can slightly change the "real" address by one or two values, avoiding bus conflicts (or allowing multiple identical devices on the same bus).

If you really have two devices with the same address (from different manufacturers) then you can use an I2C bus splitter e.g. TA9548A - but that is getting a bit advanced. In general devices are separated in address space by the manufacturer allocated address range, so there won't usually be a problem.

How the Master device works


The master controls the communication by driving the SCL clock line high or low. When the clock is low, data on the SDA line can be changed. When it goes high, the value on SDA is locked in. This synchronous serial clocking ensures stable data transfers.

So the clock sent by the master device determines the signal frequency used on the bus (100kHz, 400kHz, 3.4MHz) and it clocks data into a receiving slave device but also clock data out of a transmitting slave device.

During the acknowledge bit, the master device releases the data line (so it is passively pulled high by the pull-up resistor). The receiving device pulls the open drain SDA line low to indicate a successful data transfer i.e. an acknowledgement (or ACK).

Typical I2C data transfers involve:
  • The master device selects a slave address and initiates a transfer,
  • Acknowledge (ACK) or non-acknowledge (NACK) control bits sent by slave,
  • Data is transmitted most significant bit first over SDA,
I2C supports both 7-bit and 10-bit addressing modes allowing up to 112 or 1024 unique slave addresses respectively. It operates at standard speeds of up to 100 kHz and fast mode up to 400 kHz (there is an ultra fast mode of 3.4MHz - but that is for special case devices and requires more work to make it work).

In addition, for advanced use you can have multiple master devices. Where the protocol allows multiple master devices to communicate with slaves. If two master devices start at the same time there is an arbitration process to determine which one will win.

What are the limitations of I2C?

What is I2C Throughput?

Now, of course there is a down side and that is throughput (I2C is a serial interface) - but the I2C interface goes fast 400kHz and the some devices can adopt an even faster rate : 3.4MHz.

For example, if you have an 16 bit ADC, then the protocol will serialise the data to 16 periods of 400kHz (approx). In addition there is more data to allow the protocol to work. It means you don't get a through put of 400kHz - always less.

The way to guesstumate the through put is to divide the max I2C clock rate by the number of bits transmitted plus add the packet that is needed for the address.

Since packets are usually divided into 8 bit blocks and the payload of an I2C packet is 8 bits plus 1 (acknowledge). The number of I2C bits for the ADDS1115 is 3 packets of 9 bits, with additional start and stop bits.

So an estimated through put (with a 100kHz master clock) is

    100e3/(3*9+2) = 3448kHz or 3.5kHz

and (for a 400kHz master clock)

    400e3/(3*9+2) = 13793 or 13.7kHz

So you could take a reading from the ADS1115 at a maximum rate of 3.5kHz for a 100kHz I2C clock and 13.7kHz for a 400kHz clock. Note this does not take into account how fast the ADC (see this ADS1115 page) is capable of operating, but illustrates the principle of maximum through put or data rate.

The point is that for high speed operation you may need to use either a higher speed clock or a different device - depending on your design requirements. An alternative to the I2C interface is the simpler but faster SPI interface (some chips come in I2C or SPI flavours e.g. MCP23017).  

Note the above does not account for the processor which will need time between bursts of data to actually process the data!

What is I2C max Distance

Well...the answer is...it depends!

There have been cases of inexperienced designers using I2C as a LAN network and this is absolutely how it should not be used. I2C is designed for local board (a printed circuit board) operation only.  (if you want high speed LAN operation then use something like RS485 - these days IOT is easier -  no cables).

Each of the two I2C signals SCK and SDA are open drain connections. These are pulled high by a single resistor on each line 1kOhm~ 10kOhm.

The main problem here is capacitance. The signal can only rise as fast as the current flowing into the "total capacitance on each I2C signal line" will allow.

The longer the I2C signal lines, and the more devices attached to those signal lines, the more capacitance you will have. Hence, the slower the signals will rise and hence the more errors you get - or reduce the operating speed to accommodate the slow rise times.

Conclusions


The I2C interface is the most popular serial bus interface, saving you tons of wiring by allowing you to communicate with multiple chips on the same two wire interface.

Its a pretty fast interface and is widely adopted by chip manufacturers giving you easy control and access to all types of chips.

This has been a high level introduction, to find out more this page gives you a more detailed I2c-tutorial.


Written by John Main who has a degree in Electronic Engineering.

Note: Parts of this page were written using poe as a research assistant.




Comments

Have your say about what you just read! Leave me a comment in the box below.

Don’t see the comments box? Log in to your Facebook account, give Facebook consent, then return to this page and refresh it.



Privacy Policy | Contact | About Me

Site Map | Terms of Use