<?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 the same i2c peripheral in two different pins?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/95267/how-to-use-the-same-i2c-peripheral-in-two-different-pins</link><description>Hi, I have a project using the chip nRF52832 and sdk nRF5 14.2, I&amp;#39;m updating the firmware to use the nRF Connect SDK 2.2(NCS). 
 In my project, i use spi0 and spi2, so a can just use i2c1 to talk with the i2c sensors, but 2 sensors have the same address</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 30 Aug 2024 12:24:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/95267/how-to-use-the-same-i2c-peripheral-in-two-different-pins" /><item><title>RE: How to use the same i2c peripheral in two different pins?</title><link>https://devzone.nordicsemi.com/thread/500584?ContentTypeID=1</link><pubDate>Fri, 30 Aug 2024 12:24:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:edf0f7f7-d517-47d5-a8d0-a996ea6c7822</guid><dc:creator>Viral Patel</dc:creator><description>&lt;p&gt;Hi, can you attach a link to the issue here&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use the same i2c peripheral in two different pins?</title><link>https://devzone.nordicsemi.com/thread/409054?ContentTypeID=1</link><pubDate>Thu, 09 Feb 2023 07:05:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ff2ab37-b733-4e09-8454-7c4658ce6e66</guid><dc:creator>Priyanka</dc:creator><description>&lt;p&gt;Hi Rodrigo,&lt;/p&gt;
&lt;p&gt;I see that you have another ticket for the same issue with my colleague and are getting support there. Please continue the conversation there. &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;-Priyanka&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use the same i2c peripheral in two different pins?</title><link>https://devzone.nordicsemi.com/thread/406495?ContentTypeID=1</link><pubDate>Wed, 25 Jan 2023 14:40:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:12ba6ed5-f91e-4a49-82d2-b90661632bad</guid><dc:creator>Brunelli</dc:creator><description>&lt;p&gt;Hi, I tried to use the Dynamic pincontrol example, but I had some doubts.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;1 - In the example, it says that you have to make the change before booting the system, in my case I want to change it while the device is working, is this possible?&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;2 - How do I return the pins to default again? Would you use the pinctrl_update_states command again? If so, what would this macro look like? PINCTRL_DT_STATE_PINS_DEFINE(DT_PATH(zephyr_user), i2c1); ?&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;3 - I tried following that example to change the control pins and make an i2c communication using the following code:&lt;/p&gt;
&lt;p&gt;dts file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;pinctrl{
	i2c1_battery_default:i2c1_battery_default {
		group1 {
			psels = &amp;lt;NRF_PSEL(TWIM_SDA,0,8)&amp;gt;,
					&amp;lt;NRF_PSEL(TWIM_SCL,0,6)&amp;gt;;
		};
	};
	i2c1_battery_sleep:i2c1_battery_sleep {
		group1 {
			psels = &amp;lt;NRF_PSEL(TWIM_SDA,0,8)&amp;gt;,
					&amp;lt;NRF_PSEL(TWIM_SCL,0,6)&amp;gt;;
			low-power-enable;
		};
	};
};

/{
	zephyr,user{
		i2c1_battery_default = &amp;lt;&amp;amp;i2c1_battery_default&amp;gt;;
		i2c1_battery_sleep = &amp;lt;&amp;amp;i2c1_battery_sleep&amp;gt;;
	};
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;conf file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_DYNAMIC_INTERRUPTS=y

CONFIG_PINCTRL=y
CONFIG_PINCTRL_DYNAMIC=y
CONFIG_CONSOLE_INIT_PRIORITY=70
CONFIG_I2C_INIT_PRIORITY=60
CONFIG_PM_DEVICE=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;code to initialize i2c and communicate:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;BUILD_ASSERT((CONFIG_GPIO_INIT_PRIORITY &amp;lt; CONFIG_REMAP_INIT_PRIORITY) &amp;amp;&amp;amp;
	           (CONFIG_REMAP_INIT_PRIORITY &amp;lt; CONFIG_I2C_INIT_PRIORITY),
       	     &amp;quot;Device driver priorities are not set correctly&amp;quot;);

PINCTRL_DT_DEV_CONFIG_DECLARE(DT_NODELABEL(i2c1));
PINCTRL_DT_STATE_PINS_DEFINE(DT_PATH(zephyr_user), i2c1_battery_default);
PINCTRL_DT_STATE_PINS_DEFINE(DT_PATH(zephyr_user), i2c1_battery_sleep);

static const struct pinctrl_state i2c1_alt[] = {
	PINCTRL_DT_STATE_INIT(i2c1_battery_default, PINCTRL_STATE_DEFAULT),
	PINCTRL_DT_STATE_INIT(i2c1_battery_sleep, PINCTRL_STATE_SLEEP),
};

static const struct i2c_dt_spec eeprom_i2c   = I2C_DT_SPEC_GET(DT_NODELABEL(eeprom_i2c));

(void) main (void){
    struct pinctrl_dev_config *i2c1_config =
    		PINCTRL_DT_DEV_CONFIG_GET(DT_NODELABEL(i2c1));
    
    pinctrl_update_states(i2c1_config, i2c1_alt, ARRAY_SIZE(i2c1_alt));
    
    fnBMP280_Init(); //initiate this driver in i2c1 default pinout and works fine
    
    if (!device_is_ready(eeprom_i2c.bus)) // initiate the device to read in i2c1 alternative pinout
        LOG_INF(&amp;quot;I2C bus %s is not ready!\n\r&amp;quot;,eeprom_i2c.bus-&amp;gt;name);
    
    struct pinctrl_dev_config *i2c1_config =
			PINCTRL_DT_DEV_CONFIG_GET(DT_NODELABEL(i2c1));

	pinctrl_update_states(i2c1_config, i2c1_alt, ARRAY_SIZE(i2c1_alt));
	
    int ret;
    uint8_t u8_reg = 0
    uint8_t pu8_reg_data[6];
    
    ret = i2c_burst_read_dt(&amp;amp;eeprom_i2c,0,&amp;amp;pu8_reg_data[0],6);
    if(ret != 0){
        printk(&amp;quot;Failed to read from I2C device address %x at Reg. %x n&amp;quot;, eeprom_i2c.addr,u8_reg);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Using this code, when I try to communicate with the eeprom_i2c device I get the error &amp;quot;i2c_nrf_twim: Error 0x0BAE0001 occurred for message 0.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/priyankakesav"&gt;Priyanka&lt;/a&gt;&amp;nbsp;, can you help me with these problems?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use the same i2c peripheral in two different pins?</title><link>https://devzone.nordicsemi.com/thread/403134?ContentTypeID=1</link><pubDate>Wed, 04 Jan 2023 10:18:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:23fdb9f0-f9e9-4eee-94d1-fa7e47341a4c</guid><dc:creator>Priyanka</dc:creator><description>&lt;p&gt;Hi Rodrigo,&lt;/p&gt;
&lt;p&gt;I believe you can get a solution by using &lt;a href="https://github.com/nrfconnect/sdk-zephyr/tree/main/samples/boards/nrf/dynamic_pinctrl"&gt;Dynamic pincontrol&lt;/a&gt;. You can have same addresses for sensors, but you need to use two different pins for the connections.&lt;/p&gt;
&lt;p&gt;Please do take a look at this and do let me know how it goes.&lt;/p&gt;
&lt;p&gt;-Priyanka&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use the same i2c peripheral in two different pins?</title><link>https://devzone.nordicsemi.com/thread/402834?ContentTypeID=1</link><pubDate>Mon, 02 Jan 2023 14:09:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:efcc57d9-9b19-4fce-b0e8-d9972a385aa5</guid><dc:creator>Brunelli</dc:creator><description>&lt;p&gt;Hi Priyanka,&lt;br /&gt;This ticket shows an example of using i2c in two different addresses, but I need to communicate with sensors that have different pinouts.&lt;br /&gt;In my project I have a total of 5 sensors, where two of them have the same address so I have to programmatically change between the i2c communication pins:&lt;br /&gt;4 sensors are on pins-&amp;gt; SDA pin 7 SCL pin 5;&lt;br /&gt;1 sensor is on pins -&amp;gt;&amp;nbsp; &amp;nbsp; SDA pin 8 SCL pin 6;&lt;br /&gt;I need to alternate the i2c communication pins to be able to read all the sensors.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use the same i2c peripheral in two different pins?</title><link>https://devzone.nordicsemi.com/thread/402832?ContentTypeID=1</link><pubDate>Mon, 02 Jan 2023 13:56:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7efcc9f7-0dc8-49c7-b60e-a914942c4e49</guid><dc:creator>Priyanka</dc:creator><description>&lt;p&gt;Hi Rodrigo,&lt;/p&gt;
&lt;p&gt;Could you take a look at &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/90416/how-to-configure-two-or-more-sensors-having-different-address-on-same-i2c-bus-in-zephyr-rtos---nrf-connect-sdk"&gt;this ticket&lt;/a&gt; and see if it helps?&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;Priyanka&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>