{"id":25546,"date":"2018-10-01T09:15:59","date_gmt":"2018-10-01T16:15:59","guid":{"rendered":"https:\/\/blog.digilentinc.com\/?p=25546"},"modified":"2025-06-03T06:48:26","modified_gmt":"2025-06-03T13:48:26","slug":"what-is-i2c","status":"publish","type":"post","link":"https:\/\/digilent.com\/blog\/what-is-i2c\/","title":{"rendered":"What Is I2C Communication Protocol?"},"content":{"rendered":"<p>What is I2C? A question I asked myself a couple months ago that I am glad to answer now! I2C (also called IIC and typically pronounced I-squared-C) stands for Inter-IC or Inter-Integrated-Circuit, was developed by Philips Semiconductor in 1982, and is one form of electronics protocol: how electronic devices communicate data with each other. I will discuss the basics to understanding I2C protocol, then show an example of debugging I2C with the <a href=\"https:\/\/digilent.com\/shop\/analog-discovery-2-100msps-usb-oscilloscope-logic-analyzer-and-variable-power-supply\/\">Analog Discovery 2<\/a> and the Logic Analyzer and Protocol Analyzer in <a href=\"https:\/\/digilent.com\/shop\/waveforms-previously-waveforms-2015\/\">WaveForms<\/a>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-25724\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/man-2087782_960_720.jpg\" alt=\"\" width=\"960\" height=\"640\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/man-2087782_960_720.jpg 960w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/man-2087782_960_720-600x400.jpg 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/man-2087782_960_720-768x512.jpg 768w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/man-2087782_960_720-800x533.jpg 800w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/p>\n<p>Get stoked. Photo from <a href=\"https:\/\/pixabay.com\/illustrations\/man-happy-air-jump-laugh-cheerful-2087782\/\">here<\/a>.<\/p>\n<p>The way that I2C works is what makes it a very popular choice for electronics protocol. The most immediate benefit to I2C over other protocols is that multiple master and multiple slave devices can all communicate data on the same bus with the caveat that master devices can not directly communicate with each other and must &#8220;take turns&#8221; when communicating with the slave devices. UART is restricted to communication between two devices and SPI can have multiple slave devices but at the cost of more Slave Select wires and still being restricted to a single master device. I2C is generally a 2-wire system: SDA (serial data line) and SCK (serial clock, sometimes shown as SCL), although ground and power lines may be present as well.<\/p>\n<p>As cool as this is, at this point you may be wondering.. how do multiple master and multiple slave devices send data over a shared, 2-wire bus?<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-25717\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/I2C_data_transfer.png\" alt=\"\" width=\"798\" height=\"133\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/I2C_data_transfer.png 798w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/I2C_data_transfer-600x100.png 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/I2C_data_transfer-768x128.png 768w\" sizes=\"auto, (max-width: 798px) 100vw, 798px\" \/><\/p>\n<p>I2C data transfer general example. Photo from <a href=\"https:\/\/commons.wikimedia.org\/wiki\/File:I2C_data_transfer.svg\">here<\/a>.<\/p>\n<p>The ICs used in I2C operate with open-drain (FET) or open-collector (BJT) output stages. What that means is that the output of the IC is connected internally to the gate\/base of a transistor, the source\/emitter is connected internally to ground, and the drain\/collector is externally connected to a pull-up resistor (&#8220;open&#8221; to connection outside of the IC). Since the pull-up resistor does not need to be connected to the IC power supply (which would be 5V or lower), the output can be connected to devices operating at voltages beyond the limitations of the chip. More than one of these chip outputs can be connected to the same wire while sharing the same pull-up resistor since only one output will be active at any particular time.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25721 size-full\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/Open-Collector-Prinzip-e1538418915708.jpg\" alt=\"\" width=\"598\" height=\"212\" \/><\/p>\n<p>A general schematic to illustrate an open collector circuit. Photo from <a href=\"https:\/\/commons.wikimedia.org\/wiki\/File:Open-Collector-Prinzip.JPG\">here<\/a>.<\/p>\n<p>The output transistor acts as a switch for the chip: when the IC output is applied to the gate\/base of the transistor and the threshold voltage is exceeded, the transistor turns on and drives the drain\/collector to nearly 0V. When no output from the IC is applied\u00a0to the gate\/base of the transistor, the transistor is &#8220;off&#8221; and results in an open circuit at the\u00a0drain\/collector which restores it to a logic level high. So, when any chip output becomes active, it drives the output to a logic level low and can only drive it low. Since no device can drive the data line high, this prevents a few undesirable circumstances: competing driving signals (one low and one high) which could cause a short from the power supply to ground, damage to chips\/drivers, and excessive power consumption. Furthermore, this is what allows the data line to be bidirectional between master and slave devices.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-25726\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/both-ways.png\" alt=\"\" width=\"2000\" height=\"2000\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/both-ways.png 2000w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/both-ways-150x150.png 150w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/both-ways-600x600.png 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/both-ways-768x768.png 768w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/both-ways-1024x1024.png 1024w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/both-ways-800x800.png 800w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/both-ways-300x300.png 300w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/both-ways-1200x1200-cropped.png 1200w\" sizes=\"auto, (max-width: 2000px) 100vw, 2000px\" \/><\/p>\n<p>Master and Slave, they share the road. Photo from <a href=\"https:\/\/commons.wikimedia.org\/wiki\/File:Diamond_road_sign_two-way_traffic_lanes.svg\">here<\/a>.<\/p>\n<p>Master devices are what drives the SCK signal and initiates data transfer to\/from slave devices. Each device connected to the I2C bus is software addressable by a unique address. The process of how a master device communicates with slave devices has three main parts: the Start Condition, Data Transfer, and Stop Condition. Recalling that both SDA and SCK idle at logic level high, the Start Condition is defined as when the master device pulls the SDA line to logic level low, while leaving SCK at logic level high. After one clock cycle, communication begins between master and slave devices. When the data transfer is over, the Stop Condition is initiated by the master device and is defined as leaving the SDA line pulled down and releasing the SCK line allowing the pull-up resistor to drive the SCK line to logic level high. After one clock cycle in this state, the SDA line is released and that pull-up resistor returns it to a logic level high.<\/p>\n<p>Below is an example schematic of an I2C system. Photo from <a href=\"https:\/\/commons.wikimedia.org\/wiki\/File:I2C_bus.jpg\">here<\/a>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25722 size-full\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/I2C_bus-e1538418934650.jpg\" alt=\"\" width=\"576\" height=\"247\" \/><\/p>\n<p>Lastly, for our introduction to I2C, the data transmission itself has a few intrinsic characteristics. Data is sent byte-wise (8 bits) with an additional Acknowledge Bit (ACK). ACK is the 9th bit in the sequence and is left low when SCK is high. This is to &#8220;acknowledge&#8221; to the transmitter that the receiver successfully read the byte of data and that another byte can be sent. If the SDA line is high on the 9th bit, then it is called a Not Acknowledge (NACK) and is basically an error message. This is the Stop Condition mentioned earlier. SDA being a single wire, the transmitter and receiver must take turns pulling it down for ACK\/NACK to occur. If you wish to dive further into the nitty gritty of the different data transmission characteristics, more detailed information from the Digilent documentation resources is available <a href=\"https:\/\/digilent.com\/reference\/learn\/fundamentals\/communication-protocols\/i2c\/start\">here<\/a>.<\/p>\n<p>Below is a graphical example to distinguish between ACK and NACK. Photo from <a href=\"https:\/\/commons.wikimedia.org\/wiki\/File:I2C_ACK.svg\">here<\/a>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25718 size-full\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/I2C_ACK.png\" alt=\"\" width=\"451\" height=\"179\" \/><\/p>\n<p>Before you run off to get started on your own I2C project, I want to show you a visual example of I2C protocol in action using the <a href=\"https:\/\/digilent.com\/shop\/analog-discovery-2-100msps-usb-oscilloscope-logic-analyzer-and-variable-power-supply\/\">Analog Discovery 2<\/a>\u00a0and the Logic Analyzer (to show the individual signals) and the Protocol Analyzer (to show the overall communication) in\u00a0<a href=\"https:\/\/digilent.com\/shop\/waveforms-previously-waveforms-2015\/\">WaveForms<\/a>. I built the project found <a href=\"https:\/\/www.hackster.io\/56487\/using-the-pmod-ad2-with-arduino-uno-f00876\">here<\/a>\u00a0that uses an <a href=\"https:\/\/store-usa.arduino.cc\/products\/arduino-uno-rev3?selectedStore=us\">Arduino Uno<\/a>, <a href=\"https:\/\/digilent.com\/shop\/pmod-ad2-4-channel-12-bit-a-d-converter\/\">Pmod AD2<\/a>, and <a href=\"https:\/\/digilent.com\/shop\/pmod-cls-character-lcd-with-serial-interface-retired\/\">Pmod CLS<\/a> to convert an analog input to a digital display of the input value.<\/p>\n<p>Below is a view from the Logic Analyzer. Right-click on the picture and open in a new tab to see a larger version. We can see the Start Condition happens right before time = 0 seconds. Then, 8 clock cycles gather 8 bits of data (as we are expecting) before the ACK\/NACK 9th bit. We can also see that this particular system is gathering data in 3-byte chunks before initiating the Stop Condition. The data result is displayed as a hexadecimal value in the I2C logic line including the ACK\/NACK result and Stop Condition.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-25714\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/2018-09-28-11_06_29-.png\" alt=\"\" width=\"1600\" height=\"861\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/2018-09-28-11_06_29-.png 1600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/2018-09-28-11_06_29--600x323.png 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/2018-09-28-11_06_29--768x413.png 768w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/2018-09-28-11_06_29--1024x551.png 1024w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/2018-09-28-11_06_29--800x431.png 800w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/p>\n<p>Below is a view from the Protocol Analyzer. Right-click on the picture and open in a new tab to see a larger version. We can see the data being written to, and read from, memory, the hexadecimal result of the input analog voltage conversion (which is nearly constant in this case because I wasn&#8217;t changing the input analog voltage), the ACK\/NACK bit (only NACK in this case), and the Stop Condition. This is a great way to streamline debugging without analyzing logic signals.<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-25715\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/2018-09-28-11_06_45-Window.png\" alt=\"\" width=\"1600\" height=\"860\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/2018-09-28-11_06_45-Window.png 1600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/2018-09-28-11_06_45-Window-600x323.png 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/2018-09-28-11_06_45-Window-768x413.png 768w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/2018-09-28-11_06_45-Window-1024x550.png 1024w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/2018-09-28-11_06_45-Window-800x430.png 800w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/p>\n<p>The data was from different points in time so don&#8217;t try too hard to connect the two screenshots. The Protocol Analyzer and Logic Analyzer are key tools that can help debug I2C protocol if your project doesn&#8217;t seem to be operating or communicating properly. There are more, finer details to each I2C system than discussed here so make sure you are checking out your data sheets.<\/p>\n<p>Thanks for reading!<\/p>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style6 like-25546 jlk' data-task='like' data-post_id='25546' data-nonce='e5335d04d0' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Like' \/><span class='lc-25546 lc'>+2<\/span><\/a><\/div><div class='action-unlike'><a class='unlbg-style6 unlike-25546 jlk' data-task='unlike' data-post_id='25546' data-nonce='e5335d04d0' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Unlike' \/><span class='unlc-25546 unlc'>0<\/span><\/a><\/div><\/div> <div class='status-25546 status align-left'><\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>Ian tackles the topic of I2C in an attempt to help users get comfortable with the protocol.<\/p>\n","protected":false},"author":49,"featured_media":25717,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1563],"tags":[],"ppma_author":[4459],"class_list":["post-25546","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guide"],"jetpack_featured_media_url":"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2019\/09\/I2C_data_transfer.png","authors":[{"term_id":4459,"user_id":49,"is_guest":0,"slug":"ian","display_name":"Ian Etheridge","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/8a19055c49586a33bb17b9a5823ac103?s=96&d=mm&r=g","author_category":"","user_url":"","last_name":"Etheridge","last_name_2":"","first_name":"Ian","first_name_2":"","job_title":"","description":""}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/25546","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/users\/49"}],"replies":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/comments?post=25546"}],"version-history":[{"count":2,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/25546\/revisions"}],"predecessor-version":[{"id":31639,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/25546\/revisions\/31639"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media\/25717"}],"wp:attachment":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media?parent=25546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/categories?post=25546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/tags?post=25546"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=25546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}