Introduction to I2C Protocol

Keywords: Embedded systems, Serial Communication, I2C


I2C (Inter Integrated Circuit) is a two wire Synchronous half-duplex communication bus specifications used to interface low data rate devices. I2C was originally developed by Philips Semiconductor in 1982. is a multi-master, multi-slave, serial communication bus interface. I2C is well suited for for peripherals where simplicity and low manufacturing cost are more important than speed [1].

In contrast to SPI, I2C is address based communication where a device is selected via its alloted address instead of physical selection connection like SS (Slave Select) in SPI. I2C follows Master-Slave architecture where master has full control over the overall bus communication. Unlike SPI where specification doesn’t mention any data rates / speed limitations ( maximum half of frequency), I2C specifications do define upper limits on maximum data rates that can be achieved while meeting specific I2C specification version.

Compared to other bus communication specifications/standards like SPI/UART, I2C is relatively complex yet I2C combines the advantages of both UART and SPI. like SPI, I2C is also intended to be used for short range communication merely on board devices. While SPI doesn’t specify Multi-Master bus interface to slave, the I2C does provide the facility of adding more Masters on bus to exchange data with slaves. Similarly like UART, I2C uses just two wires to data exchanges with the exception that I2C is half-duplex while UART is full-duplex.

One of the major advantages of I2C is that the I2C specifications are more like Connection Oriented protocol i.e. Acknowledge from slave is required (if specified) on successful reception of data. While SPI and UART serial communication don’t specify any such data acknowledgment from Salve/Receiver.

1. I2C Signals:

On hardware level, I2C bus consists of just two wires to exchange data i.e. SCLSDA. The following Figure shows the simplest case of I2C bus interface between a single Master and Single slave.

Figure-1: Simple I2C bus interface.

The I2C bus lines i.e. SCL and SDA follows open-drain technology. The bus lines remain in high impedance state i.e. they can neither be driven high (Logic-1) or drive low (Logic-0). The I2C hardware (peripheral module) can only pull down both line to logic-0 (bit-0)when required and can’t set them to logic-1 (send bit-1). In order to cope with this situation, these lines are pulled up by external appropriate resistors (Figure-2) which keep the bus lines at logic-1. The I2C hardware pulls the SDA line when bit-0 is to be send and release the SDA line (the pull-up resistor automatically pulls the line high) whenever bit-1 is required to be send. The same thing happens with SCL line clock cycles.

Figure-2: I2C Pull-up Resistors

The value of Pull-up resistor (Rp) depends on line voltage, current, capacitance and speed of communication.

2. I2C Frame/Packet:

In I2C protocol, data is synchronously and serially transfered on I2C bus. The serial data is chunked in the form of frames/packets with minimum length of 11-bits. The I2C data frame consists of the following fields, Figure-3.

  1. Start bit (1-bit)
  2. Address bits (7-bits / 10-bits)
  3. Read/Write bit (1-bit)
  4. ACK/NACK Acknowledgment bit (1-bit)
  5. Optional data byte (8-bits) + ACK/NACK bit
  6. Stop bit (1-bit)
Figure-3: I2C frame with 2-bytes of data

2.1. Start bit/ Start Condition:

No transition on SDA line is allowed when SCL line is high (High Clock Cycle) except for start/stop conditions. When The SDA line switches from Logic-1 (high voltage) to a Logic-0 (low voltage) before the SCL line switches from high to low, the condition is considered as Start bit or Start of communication, Figure-4.

Figure-4: I2C Start Condition

2.2. Slave Address:

As mentioned earlier, I2C bus specifications uses device address to uniquely identify a device on bus. I2C address uses 7-bits or 10-bits (depends on I2C version) unique address to each slave that identifies the slave when the master wants to talk to it.

7-bits Addressing: When using 7-bits addressing scheme, maximum number of 128 devices (7^2 = 128 addresses) can be connected on I2C bus. However some addresses are reserved for special purposes. Thus, only 112 addresses are available with the 7 bit address scheme. In 7-bits addressing scheme, the address is sent in first byte right after the start bit condition as shown in Figure-5.

Figure-5: I2C 7-bits addressing scheme

Followings are reserved addresses [1].

  • 0000 xxx
  • 1111 xxx

Table-1 shows reserved addresses in 7-bits addressing scheme.

Table-1: I2C reserved addresses in 7-bits addressing scheme

10-bits Addressing: In order to extend the limited range of devices that can be interfaced on I2C bus, a new 10-bits addressing scheme was introduced. Usually the hardware is backward compatible i.e. I2C supporting 10-bits addresses can also use 7-bits addressing scheme though forward compatibility is not guaranteed.

In order to send 10-bits address, the 10-addressing code (Table-1- Address Index: 8) is sent along with the most two most significant bits (MSB-9,8) of slave address in the first byte right after the start condition, Figure-6. Receiving the 10-bits addressing code (11110xx) causes the slave to switch to 10-bits addressing. If the salve accept the address, it sends an acknowledge (discussed later). Upon receiving acknowledgment bit, the master sends the remaining 8-bits of address as shown in Figure-6.

Figure-6: I2C 10-bits addressing scheme

2.3. Read/ Write Bit:

The LSB (least significant bit) of first byte right after the start condition indicate whether the master wants read from Slave or write to Slave. If the master wants to send data to the slave, the read/write bit is a set to low (0). Similarly if the master is requesting data from the slave, it sets the bit to high (1).

2.4. Acknowledge/No-Acknowledge bit:

As mentioned earlier, I2C is sort of connection oriented bus protocol i.e. a configurable acknowledgment is sent from receiving device to confirm to the sender that the data has been received. In I2C frame, 1-bit is reserved for Acknowledge or No-Acknowledge receiver/slave response. When the slave accepts address/data byte, it sends Acknowledge (ACK) bit in response otherwise it sends back a No-Acknowledge bit (NACK).

If the address/data is accepted, the slave returns an ACK bit by pulling the SDA line low for one bit. On the other hand if the sent address/data is not accepted, the SDA line is left high for 1-bit which is considered as NACK on master side.

2.5. Stop bit/ Stop Condition:

When The SDA line switches from Logic-0 (high voltage) to a Logic-1 (low voltage) before the SCL line switches from high to low, the condition is considered as Stop bit or Stop of communication, Figure-7.

Figure-7: I2C Stop Condition

3. How I2C Works?

So far we have we have discussed the basics of I2C bus internals. Let’s discuss briefly how master communicate with slave nodes on I2C bus. Following are the steps.

  • The master nodes sends start condition (Figure-4) to each connected slave nodes on I2C bus. This makes the slave nodes active for further bus transaction and start listening for the address.
  • Next, the master device broadcasts slave address (7-bits/10-bits) along with Read/Write bit. This is the only data bytes’ to which all the slave devices on the bus listens.
  • All the slave nodes compare their own address with the Master node sent address, if there is a match, the slave node sends back ACK bit by pulling the SDA line low for one clock cycle. Other slave nodes simply ignore further bus activity.
  • The master exchange (read/write) data frames with the selected slave.
  • After each data frame, the receiver node returns an ACK bit as an acknowledge of successful data frame reception.
  • Once the transaction completes, the master node sends a stop condition (Figure-7) to the slave node as an indication of data transfer completion.

The overall transaction cycle is summarized in the following figure.

Figure-8: I2C complete Transaction cycle


4. I2C Modes / Revisions:

I2C bus communication specifications has evolved significantly since 1982-the first release. Following table summarizes I2C major releases.

YearVersion NoReleaseSpeed
1982Standard Mode (Sm)100khz
1992Version 1Fast Mode (Fm)400khz
1988Version 2High Speed Mode (Hm)2.3Mhz
2007Version 3Fast Mode Plus (Fm+)
2012Version 4Ultra Fast Mode (UFm)5Mhz

References:

[1] – I2C Wikipedia



53 thoughts on “Introduction to I2C Protocol”

  • I’m amazed, I must say. Rarely do I encounter a blog that’s both equally educative and
    interesting, and let me tell you, you’ve hit the
    nail on the head. The issue is something which too few folks are speaking
    intelligently about. Now i’m very happy I found this in my search for something relating to this.

    asmr 0mniartist

  • It’s awesome to visit this website and reading
    the views of all mates on the topic of this paragraph, while I am also eager of getting familiarity.
    0mniartist asmr

  • I like the helpful information you provide in your articles.

    I will bookmark your weblog and check again here frequently.
    I am quite sure I’ll learn plenty of new stuff right here!
    Good luck for the next! 0mniartist asmr

  • Hello, There’s no doubt that your site could be having web browser compatibility problems.
    Whenever I look at your site in Safari, it looks fine however, if opening in IE,
    it’s got some overlapping issues. I simply wanted to provide you with a quick
    heads up! Apart from that, wonderful blog!

  • Wow, marvelous blog layout! How long have you been blogging for?
    you make blogging look easy. The overall look of your website is wonderful, let alone the content!

  • My partner and I stumbled over here coming from a
    different website and thought I should check things out.

    I like what I see so now i’m following you. Look forward to looking at your web page repeatedly.

  • The other day, while I was at work, my sister stole my apple ipad and tested
    to see if it can survive a thirty foot drop, just so she can be a youtube sensation. My iPad is
    now destroyed and she has 83 views. I know this is entirely off topic but I had
    to share it with someone!

  • Woah! I’m really digging the template/theme of this site. It’s simple, yet effective.
    A lot of times it’s hard to get that “perfect balance” between user friendliness and visual
    appeal. I must say you’ve done a superb job with this.
    Also, the blog loads very quick for me on Firefox.
    Superb Blog!

  • Do you have a spam issue on this website; I also am a blogger, and I was wanting to know your situation; we
    have developed some nice practices and we are looking to
    exchange strategies with others, please shoot me an email if interested.

  • Hello! I know this is kinda off topic but I was wondering which blog platform
    are you using for this site? I’m getting tired of WordPress because I’ve had problems with hackers and I’m looking at options for another platform.
    I would be fantastic if you could point me in the direction of a good
    platform.

  • scoliosis
    I have been exploring for a bit for any high quality articles or blog posts on this sort of area .
    Exploring in Yahoo I eventually stumbled upon this website.
    Studying this info So i am happy to convey that I’ve an incredibly excellent uncanny feeling
    I found out just what I needed. I so much no doubt will make certain to
    don?t disregard this web site and provides it a glance on a continuing basis.
    scoliosis

  • scoliosis
    Hey there! I’m at work surfing around your blog from my new iphone 3gs!
    Just wanted to say I love reading through your blog and look forward to all your posts!
    Keep up the fantastic work! scoliosis

  • scoliosis
    Thanks for your marvelous posting! I definitely enjoyed reading it, you may
    be a great author.I will make sure to bookmark your blog
    and will eventually come back someday. I want to encourage that you continue your great posts, have
    a nice evening! scoliosis

  • free dating sites
    I am no longer certain where you are getting your information, but
    great topic. I must spend a while studying much more
    or figuring out more. Thank you for great information I used to be searching for this info for my mission. dating sites

  • I think this is one of the most vital information for me.
    And i am glad reading your article. But wanna remark on some
    general things, The website style is ideal, the articles is really
    excellent : D. Good job, cheers

  • Great work! That is the kind of information that are meant to be shared across the net.

    Disgrace on the seek engines for not positioning this put up upper!

    Come on over and consult with my web site .

    Thank you =)

  • Very good site you have here but I was wondering if you knew of any forums that cover the same
    topics discussed in this article? I’d really love to be a part of group where I can get
    responses from other knowledgeable individuals that share the same interest.
    If you have any suggestions, please let me know. Cheers!

  • Thank you for another wonderful article. The place else may anybody get that kind
    of info in such a perfect means of writing? I’ve a presentation subsequent
    week, and I am on the look for such info.

  • obviously like your website however you need to take a
    look at the spelling on several of your posts. Several of
    them are rife with spelling issues and I find it very bothersome to tell the truth then again I’ll certainly come back again.

  • Amazing things here. I’m very glad to peer your article.

    Thank you so much and I am taking a look ahead to contact you.
    Will you kindly drop me a mail?

  • My spouse and I stumbled over here coming from a different web
    address and thought I might as well check things
    out. I like what I see so i am just following you. Look forward to checking out your web page for a second time.

  • Hello would you mind letting me know which hosting company you’re utilizing?

    I’ve loaded your blog in 3 different internet browsers and
    I must say this blog loads a lot quicker then most. Can you suggest a good
    internet hosting provider at a honest price? Thank you, I appreciate it!

  • Excellent post. Keep writing such kind of info on your blog.

    Im really impressed by your site.
    Hey there, You have performed an excellent job. I’ll certainly digg it and in my
    opinion recommend to my friends. I’m sure they will
    be benefited from this web site.

  • I’ve been browsing online more than three hours today, yet I never found
    any interesting article like yours. It is pretty worth
    enough for me. In my opinion, if all site owners and bloggers made good content
    as you did, the net will be much more useful than ever before.

  • I have been surfing on-line greater than three hours today, but
    I by no means found any attention-grabbing article like yours.
    It is pretty price enough for me. Personally, if all webmasters and bloggers made excellent content as
    you did, the internet can be a lot more useful than ever before.

  • Howdy, i read your blog from time to time and i own a
    similar one and i was just wondering if you get a lot of spam comments?
    If so how do you stop it, any plugin or anything you can recommend?
    I get so much lately it’s driving me crazy so any assistance is very much appreciated.

  • Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my
    blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some
    experience with something like this. Please let me
    know if you run into anything. I truly enjoy reading
    your blog and I look forward to your new updates.

  • Having read this I thought it was very informative. I appreciate you taking
    the time and energy to put this information together.
    I once again find myself personally spending a lot of time both reading and commenting.
    But so what, it was still worth it!

  • Howdy! I know this is kinda off topic but I
    was wondering if you knew where I could get a captcha plugin for my comment form?
    I’m using the same blog platform as yours and I’m having difficulty finding one?
    Thanks a lot!

  • Please let me know if you’re looking for a article writer for
    your site. You have some really great articles and I believe I would be a good asset.
    If you ever want to take some of the load off, I’d love to write
    some articles for your blog in exchange for a link back to
    mine. Please blast me an e-mail if interested.
    Thanks!

  • Hey there would you mind sharing which blog platform you’re working with?
    I’m going to start my own blog soon but I’m having a difficult time choosing
    between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your layout seems different then most blogs and I’m looking for something unique.
    P.S Sorry for being off-topic but I had to ask! scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

Leave a Reply

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