<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to use both I2C pins on nRF52840 ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/51160/how-to-use-both-i2c-pins-on-nrf52840</link><description>Problem : 
 I have two I2C devices and would like to connect them both to nRF52840 DK on different I2C pins. According to datasheet nRF52840 has two I2C pins (P1.00, P0.22) and (P0.27, 0.26). I want to connect one device on (P1.00, P0.22) and other on</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 28 Aug 2019 06:23:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/51160/how-to-use-both-i2c-pins-on-nrf52840" /><item><title>RE: How to use both I2C pins on nRF52840 ?</title><link>https://devzone.nordicsemi.com/thread/206494?ContentTypeID=1</link><pubDate>Wed, 28 Aug 2019 06:23:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41e95af8-722c-4794-9c29-4b9f24c852c2</guid><dc:creator>shockline</dc:creator><description>[quote userid="7377" url="~/f/nordic-q-a/51160/how-to-use-both-i2c-pins-on-nrf52840/205850"]I see. There is one important point I forgot to ask about earlier.&amp;nbsp;P0.22 is connected to the onboard [/quote]
&lt;p&gt;Thank You. Everything is working fine now.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;What did I change ?&lt;br /&gt;&lt;/b&gt;I used some other digital pins for 2nd I2C instance. Other than (P1.00, P0.22).&lt;br /&gt;I also set&amp;nbsp;TWI0_ENABLED and TWI1_ENABLED to 1.&lt;/p&gt;
&lt;p&gt;Maybe the problem was due to P0.22 being connected to external flash.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/two_2D00_i2c_2D00_instance.zip"&gt;This is link to the source code I used.&lt;/a&gt; If anyone is trying to solve this problem in future.&lt;br /&gt;In this source code I have merged code of NFC Adafruit Tag Example (from SDK example) and OLED (&lt;a href="https://github.com/jimmywong2003/SSD1306-LCD-on-NRF52"&gt;Github Link to library&lt;/a&gt;). NFC Reader and OLED are working on two different I2C pins.&lt;/p&gt;
&lt;p&gt;I also tested on some other digital pins and some pins don&amp;#39;t seem to work on nRF52840 DK. Maybe this is due to them being connected to some other things internally.&lt;/p&gt;
&lt;p&gt;This is my finding.&lt;br /&gt;*********TESTED PINS FOR OLED*************&lt;br /&gt;SCL &amp;nbsp;&amp;nbsp; SDA &amp;nbsp;&amp;nbsp; Result&lt;br /&gt;0.07 &amp;nbsp;&amp;nbsp; 0.08 &amp;nbsp;&amp;nbsp; True (Working)&lt;br /&gt;1.09 &amp;nbsp;&amp;nbsp; 0.08 &amp;nbsp;&amp;nbsp; True&lt;br /&gt;0.09 &amp;nbsp;&amp;nbsp; 0.1&lt;span style="background-color:#ffffff;color:#000000;float:none;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:12px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal;"&gt; &amp;nbsp; &amp;nbsp; &lt;/span&gt;False&lt;br /&gt;0.04 &amp;nbsp;&amp;nbsp; 0.05&lt;span style="background-color:#ffffff;color:#000000;float:none;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:12px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal;"&gt; &amp;nbsp; &lt;/span&gt;True&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use both I2C pins on nRF52840 ?</title><link>https://devzone.nordicsemi.com/thread/205850?ContentTypeID=1</link><pubDate>Fri, 23 Aug 2019 10:46:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8708cf77-ea57-4283-a868-4812fa60c92f</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The code looks good.&lt;/p&gt;
[quote user="shockline"]Both the slave devices work on (P0.27, P0.26) but none of them work on the other pins.[/quote]
&lt;p&gt;I see. There is one important point I forgot to ask about earlier.&amp;nbsp;P0.22 is connected to the onboard external flash on the DK by default, and not to the pin header. So you need to short solder bridge SB25 and cut SB15. Have you done that? If not, there is no electrical connection between the pin on the chip and the corresponding pin header.&lt;/p&gt;
[quote user="shockline"]What do you mean by TWI0 &amp;amp; TWI1 peripherial ?[/quote]
&lt;p&gt;That was a typo on my part. I meant to write TWIM0 and TWIM1, which are the two instances of the TWIM peripheral. TWI0 and TWI1 are the two instances of the corresponding non-DMA peripheral. Note that the driver often uses TWI for both (without the M), since it separates between the TWI and TWIM peripheral by the&amp;nbsp;TWI0_USE_EASY_DMA and&amp;nbsp;TWI1_USE_EASY_DMA configuration parameters in sdk_config.h.&lt;/p&gt;
[quote user="shockline"]If TWI1_ENABLED is set to 0 in sdk_config.h and create a TWI instance with&amp;nbsp;NRF_DRV_TWI_INSTANCE giving it an input of 1. Will I get a linker error ?[/quote]
&lt;p&gt;Yes, you will get a build error. But it will probably fail earlier than linking, during compilation.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use both I2C pins on nRF52840 ?</title><link>https://devzone.nordicsemi.com/thread/205692?ContentTypeID=1</link><pubDate>Thu, 22 Aug 2019 16:55:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:06e1644e-cd59-4640-90b9-9c974ffcd387</guid><dc:creator>shockline</dc:creator><description>[quote userid="7377" url="~/f/nordic-q-a/51160/how-to-use-both-i2c-pins-on-nrf52840/205184"]Do you mind sharing the code where you try to talk to the I2C device?[/quote]
&lt;p&gt;&lt;span style="font-size:12px;"&gt;&lt;strong&gt;&lt;a style="background-attachment:scroll;background-color:transparent;background-image:none;background-repeat:repeat;background-size:auto;color:#24b8cc;font-style:normal;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal;" title="Link to Source Code" href="https://devzone.nordicsemi.com/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-dca79341f33d492e88515229f5fc95bb/main.c" rel="noopener noreferrer" target="_blank"&gt;Link to Source Code&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/51160/how-to-use-both-i2c-pins-on-nrf52840/205184"]what happens if you move the slave device that you were able to communicate with to the other bus which did not work?[/quote]
&lt;p&gt;Both the slave devices work on (P0.27, P0.26) but none of them work on the other pins.&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/51160/how-to-use-both-i2c-pins-on-nrf52840/205184"]TWI0_ENABLED enables the driver for the TWI0 peripheral[/quote]
&lt;p&gt;What do you mean by TWI0 &amp;amp; TWI1 peripherial ?&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/51160/how-to-use-both-i2c-pins-on-nrf52840/205184"]The only parameter for&amp;nbsp;NRF_DRV_TWI_INSTANCE is the instance ID, which can be either 0 or 1. 0 represents the TWIM0 peripheral and 1 represents TWIM1 peripheral.[/quote]
&lt;p&gt;If TWI1_ENABLED is set to 0 in sdk_config.h and create a TWI instance with&amp;nbsp;NRF_DRV_TWI_INSTANCE giving it an input of 1. Will I get a linker error ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use both I2C pins on nRF52840 ?</title><link>https://devzone.nordicsemi.com/thread/205184?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2019 07:10:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:869b434c-30a0-489b-b491-997e54ebacce</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="shockline"]It fails to detect device connected to the corresponding pins.[/quote]
&lt;p&gt;I see. Do you mind sharing the code where you try to talk to the I2C device? Have you measured with a logic analyzer on the I2C lines (SCL and SDA) to see what is happening? Could there be a problem with the device you are trying to communicate with? For instance, what happens if you move the slave device that you were able to communicate with to the other bus which did not work?&lt;/p&gt;
[quote user="shockline"]What is the purpose of&amp;nbsp;TWI_ENABLED, TWI0_ENABLED and TWI1_ENABLED ?[/quote]
&lt;p&gt;These configuration macros are used to enable or disable parts of the driver. This approach is used across most of the SDK to have the preprocessor strip out unused code. So if you need some functionality, you need to enable it in sdk_config.h. This is not as tricky as it might sound since you would get a linker error if you tried to use something that was not included by the preprocessor due to it not being enabled in sdk_config.h.&lt;/p&gt;
&lt;p&gt;Specifically, TWI_ENABLED enabled the TWI_DRIVER. If this is set to 0, all other TWI configurations will be ignored.&amp;nbsp;TWI0_ENABLED enables the driver for the TWI0 peripheral.&amp;nbsp;TWI1_ENABLED enables the driver for the TWI1 peripheral. There is also the&amp;nbsp;TWI0_USE_EASY_DMA and&amp;nbsp;TWI1_USE_EASY_DMA, which is used to select if you want to use DMA (TWIM peripheral) or not (legacy TWI peripheral). Setting it to 1 is most sensible in most cases.&lt;/p&gt;
[quote user="shockline"]What is the purpose of 0 or 1 given to&amp;nbsp;NRF_DRV_TWI_INSTANCE() as an input ?[/quote]
&lt;p&gt;The only parameter for&amp;nbsp;NRF_DRV_TWI_INSTANCE is the instance ID, which can be either 0 or 1. 0 represents the TWIM0 peripheral and 1 represents TWIM1 peripheral.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use both I2C pins on nRF52840 ?</title><link>https://devzone.nordicsemi.com/thread/205124?ContentTypeID=1</link><pubDate>Tue, 20 Aug 2019 16:40:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ecbfa8a0-5c7e-4a9a-aa47-5a883a7a4f22</guid><dc:creator>shockline</dc:creator><description>[quote userid="7377" url="~/f/nordic-q-a/51160/how-to-use-both-i2c-pins-on-nrf52840/205062"]In what way does it fail?[/quote]
&lt;p&gt;It fails to detect device connected to the corresponding pins.&lt;/p&gt;
&lt;p&gt;&lt;span style="background-color:#ffffff;color:#11171a;float:none;font-family:&amp;#39;GT Eesti&amp;#39;,&amp;#39;Helvetica&amp;#39;,Arial,sans-serif;font-size:14px;font-style:normal;font-weight:400;letter-spacing:normal;line-height:1.5em;text-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal;"&gt;&lt;/span&gt;&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/51160/how-to-use-both-i2c-pins-on-nrf52840/205062"]Also, does your project build without any warnings or errors?[/quote]
&lt;p&gt;Yes, It builds without any error.&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/51160/how-to-use-both-i2c-pins-on-nrf52840/205062"] Have you remembered to set&amp;nbsp;at least&amp;nbsp;TWI_ENABLED, TWI0_ENABLED and&amp;nbsp;TWI1_ENABLED to 1 in your projects sdk_config.h[/quote]
&lt;p&gt;I have set all the three macros (TWI_ENABLED, TWI0_ENABLED and TWI1_ENABLED) to 1. &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/2727.sdk_5F00_config.h"&gt;Download sdk_config.h&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What is the purpose of&amp;nbsp;TWI_ENABLED, TWI0_ENABLED and TWI1_ENABLED ?&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/51160/how-to-use-both-i2c-pins-on-nrf52840/205062"]You can think of the TWI master driver instance crated by&amp;nbsp;NRF_DRV_TWI_INSTANCE() as a TWI object.[/quote]
&lt;p&gt;&lt;strong&gt;What is the purpose of 0 or 1 given to&amp;nbsp;NRF_DRV_TWI_INSTANCE() as an input ?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use both I2C pins on nRF52840 ?</title><link>https://devzone.nordicsemi.com/thread/205062?ContentTypeID=1</link><pubDate>Tue, 20 Aug 2019 13:28:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9990b4bb-0542-4b4d-87ce-b11fb83ffecd</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]According to datasheet nRF52840 has two I2C pins (P1.00, P0.22) and (P0.27, 0.26).[/quote]
&lt;p&gt;Where do you see this? There are no dedicated TWI pins in the nRF5 devices. Any GPIO pin can be used for any function with any digital peripheral. You just need to configure the peripheral to use the correct pins, typically via the driver configuration as you do.&lt;/p&gt;
[quote user=""] I try to scan for I2C devices on both TWI instances and fail to read on (P1.00, P0.22).[/quote]
&lt;p&gt;In what way does it fail? Also, does your project build without any warnings or errors? Have you remembered to set&amp;nbsp;at least&amp;nbsp;TWI_ENABLED, TWI0_ENABLED and&amp;nbsp;TWI1_ENABLED to 1 in your projects sdk_config.h (You should have gotten a linker error if not)?&lt;/p&gt;
[quote user=""]What is the use &lt;span style="font-size:12px;"&gt;&lt;em&gt;&lt;span style="background-color:#ffffff;color:#000000;float:none;font-family:Verdana, Arial, Helvetica, sans-serif;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal;"&gt;NRF_DRV_TWI_INSTANCE() ? &lt;/span&gt;&lt;/em&gt;&lt;span style="background-color:#ffffff;color:#000000;float:none;font-family:Verdana, Arial, Helvetica, sans-serif;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal;"&gt;What is TWI instance exactly ?&lt;/span&gt;&lt;/span&gt;[/quote]
&lt;p&gt;You can think of the TWI master driver instance crated by&amp;nbsp;NRF_DRV_TWI_INSTANCE() as a TWI object. This represents a TWI peripheral, connected to a specific TWI bus (set of TWI/I2C pins). Since each of the two instances represents independent HW, they&amp;nbsp;can be used independently.&lt;/p&gt;
[quote user=""]What is the difference between the TWI hardware driver and TWI transaction Manager ?[/quote]
&lt;p&gt;The &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.3.0/hardware_driver_twi.html?cp=5_1_2_0_17"&gt;TWI hardware driver&lt;/a&gt; is a low-level driver that handles the TWI peripheral for you, so you don&amp;#39;t need to think about or know how to use the TWIM peripheral in the nRF52 device in detail. The &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.3.0/lib_nrf_twi_mngr.html?cp=5_1_3_53"&gt;TWI transaction manager&lt;/a&gt;, on the other hand, is a higher-level library that helps you with more &amp;quot;complex&amp;quot; transactions. It uses the driver under the hood. Which of those make more sense depending on your use case. There is also an even high-level library nrf_twi_sensor that use the TWI transaction manager that may or may not be suited for your needs.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>