{"id":2769,"date":"2017-02-20T00:00:27","date_gmt":"2017-02-20T08:00:27","guid":{"rendered":"http:\/\/192.168.3.4\/?p=2769"},"modified":"2018-01-09T06:51:27","modified_gmt":"2018-01-09T14:51:27","slug":"i2c-squaring-up-multi-device-communications","status":"publish","type":"post","link":"https:\/\/www.cloudacm.com\/?p=2769","title":{"rendered":"I2C &#8211; Squaring up multi device communications"},"content":{"rendered":"<p>UART and SPI communication have benefits and limitations.\u00a0 UART is confined to point to point links, whereas SPI requires additional slave select channels from the master.\u00a0 Both do not scale well for multiple devices.\u00a0 For that reason, I2C was developed with the introduction of device addressing in the data channel.<\/p>\n<p>I2C stands for Inter-integrated Circuit and it uses a clock channel to synchronize its data channel.\u00a0 Only two wires are required to achieve this.\u00a0 They are defined as SDA for the data channel and SCL for the clock channel.\u00a0 I2C can support up to 1008 slave devices with same 2 wires.\u00a0 The protocol can also support a multi-master setup.\u00a0 I2C can send data at a rate of 100Khz to 400Khz, depending on the physical environment it&#8217;s deployed in.\u00a0 There is some hardware overhead required to operate I2C links.\u00a0 However it is simpler than UART and not much more complex that SPI.<\/p>\n<p><a href=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/02\/Arduino-I2C.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-2773\" src=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2017\/02\/Arduino-I2C-300x219.png\" alt=\"\" width=\"300\" height=\"219\" srcset=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/02\/Arduino-I2C-300x219.png 300w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/02\/Arduino-I2C-768x562.png 768w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/02\/Arduino-I2C-369x270.png 369w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2017\/02\/Arduino-I2C.png 954w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>One of the most exciting features of I2C is Arduino natively supports the protocol with the WIRE library.\u00a0 This will be essential as we begin to interconnect micro controllers and Raspberry Pi devices together.\u00a0 The Arduino also supports software defined I2C addressing.\u00a0 I&#8217;ll cover addressing more later, but do note that this is significant.\u00a0 As with any interconnecting technology, level shifting might be needed for platforms of differing voltage levels.<\/p>\n<p>Now lets cover some details about the two channels that I2C uses.\u00a0 The clock channel, referred to as SCL, is an oscillating digital signal that is generated by the bus master.\u00a0 The data channel, referred to as SDA, is held high through a pullup resistor to VCC.\u00a0 When data needs to be sent, the devices bring SDA low as needed.\u00a0 This method eliminates the potential from damage should bus contention occur since a multi device low state doesn&#8217;t produce an over voltage condition.\u00a0 SCL also is held high through a pullup resistor to VCC and brought low by the bus master while generating clock ticks.<\/p>\n<p>The distances between I2C devices can be influenced by the value of the pullup resistor.\u00a0 If higher resistor values are used, lower standby power is used but the distance is limited.\u00a0 Conversely, if lower resistor values are used, more power is consumed but greater distances are allowed.\u00a0 It should also be noted that the more I2C devices that connect to the bus, the lower the pullup resistor values should be.<\/p>\n<p>Data is structured as frames on the SDA channel.\u00a0 There are at least two frames initially sent when I2C communication begins.\u00a0 The master device always initiates data communication.\u00a0 First it sends an address frame which is then followed by a data frame.\u00a0 All slave devices on the I2C bus await the detection of the SDA line going low.\u00a0 When it does, they start to listen for that address frame from the master.\u00a0 If the address frame matches the address in the slave&#8217;s register, that device continues to listen.\u00a0 The remaining slave devices that do not have that address match return to standby mode.<\/p>\n<p>Address frames are mostly 7-bit addresses.\u00a0 They start with the MSB and end with the LSB.\u00a0 The frame also contains 2 additional bits.\u00a0 The next bit is a read\/write instruction for the slave.\u00a0 The last bit is instruction for the slave to either acknowledge or not acknowledge it received the frame, commonly refereed to as ACK\/NACK<\/p>\n<p>However, there are 10-bit addresses.\u00a0 To send these 10-bit addresses, the master has to send 2 address frames.\u00a0 The first frame has a standard Bx11110 address header that will be ignored by all 7-bit address devices.\u00a0 This eliminates the chance that a 7-bit slave will perceive the second 10-bit address frame as data.\u00a0 The first 10-bit frame also contains the first 2 MSB, most significant bits, of the 10-bit slave address.\u00a0 It also contains a read\/write bit.\u00a0 The remaining 10-bit address is sent in the second frame.<\/p>\n<p>Once all address and data frames are sent by the master, the slave device will either send data back to the master or not, depending on the instruction it received.\u00a0 When all communications are done, the SDA is allowed to return to a high state and all slave devices return to standby.<\/p>\n<p>The I2C protocol is going to be central in the interconnecting of smart sensors in my up coming posts.\u00a0 The ease and scalability of it make it a preferred method for this application.\u00a0 This should cover all the fundamentals we&#8217;ll need in order to move forward.\u00a0 Thank you for joining me and I hope you have found the information useful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>UART and SPI communication have benefits and limitations.\u00a0 UART is confined to point to point links, whereas SPI requires additional slave select channels from the master.\u00a0 Both do not scale well for multiple devices.\u00a0 For that reason, I2C was developed with the introduction of device addressing in the data channel. I2C stands for Inter-integrated Circuit and it uses a clock channel to synchronize its data channel.\u00a0 Only two wires are required to achieve this.\u00a0 They are defined as SDA for&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.cloudacm.com\/?p=2769\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,6,3,8],"tags":[],"class_list":["post-2769","post","type-post","status-publish","format-standard","hentry","category-arduino","category-raspberry-pi","category-rd","category-xbee"],"_links":{"self":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/2769","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2769"}],"version-history":[{"count":3,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/2769\/revisions"}],"predecessor-version":[{"id":2777,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/2769\/revisions\/2777"}],"wp:attachment":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}