<?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>3 SPI and 2 I2C pin switching on runtime</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/108224/3-spi-and-2-i2c-pin-switching-on-runtime</link><description>Hi, 
 We are using nRF52840 with nRF Connect SDK 2.5.0 
 We have 3 SPI and 2 I2C slaves on our device. All 5 slaves are individually connected to the separate pins. 
 
 The nRF52840 has 3 serial instances that can be used as TWI or SPI master and slaves</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 13 Feb 2024 14:36:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/108224/3-spi-and-2-i2c-pin-switching-on-runtime" /><item><title>RE: 3 SPI and 2 I2C pin switching on runtime</title><link>https://devzone.nordicsemi.com/thread/468660?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2024 14:36:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8ef93f9-3ad8-47cc-b189-7faf3ad0ad1f</guid><dc:creator>Kenneth</dc:creator><description>[quote user="akif"]But you said in the other ticket you have shared you have developed code in bullet 2 based on bullet 1 page. One needs reset, other one doesn&amp;#39;t. So, why the behave is&amp;nbsp;different ?[/quote]
&lt;p&gt;I don&amp;#39;t want to discuss semantics here, I am not a native english speaker, but the intention of the example in bullett point 2 is to show a way that dynamic pin switching can be done by using the power management api. It&amp;#39;s the only way, afaik, that this can be done in zephyr.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 3 SPI and 2 I2C pin switching on runtime</title><link>https://devzone.nordicsemi.com/thread/468649?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2024 14:13:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5cba1258-9564-478b-9164-ec4fde1a6c45</guid><dc:creator>akif</dc:creator><description>[quote userid="2111" url="~/f/nordic-q-a/108224/3-spi-and-2-i2c-pin-switching-on-runtime/468645"]&lt;p&gt;Correct.&lt;/p&gt;
&lt;div class="quote-header"&gt;&lt;/div&gt;&lt;blockquote class="quote"&gt;&lt;div class="quote-user"&gt;&lt;/div&gt;&lt;/blockquote&gt;[/quote]
&lt;p&gt;&lt;span&gt;But you said in the other ticket you have shared you have developed code in bullet 2 based on bullet 1 page. One needs reset, other one doesn&amp;#39;t. So, why the behave is&amp;nbsp;different ?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
[quote userid="2111" url="~/f/nordic-q-a/108224/3-spi-and-2-i2c-pin-switching-on-runtime/468645"]&lt;p&gt;I agree with you.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;Thanks for confirmation.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 3 SPI and 2 I2C pin switching on runtime</title><link>https://devzone.nordicsemi.com/thread/468645?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2024 14:08:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4889148f-2a8c-452d-aeee-2779e74e5ee6</guid><dc:creator>Kenneth</dc:creator><description>[quote user="akif"]If I am not wrong, basically you are saying:&lt;br /&gt;on bullet 1 and 3 : reset is needed&lt;br /&gt;on bullet 2 : reset is NOT needed.[/quote]
&lt;p&gt;Correct.&lt;/p&gt;
[quote user="akif"]Could&amp;nbsp;you check the !Note box in the below link and please let me know if you think otherwise.&amp;nbsp;[/quote]
&lt;p&gt;I agree with you.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 3 SPI and 2 I2C pin switching on runtime</title><link>https://devzone.nordicsemi.com/thread/468628?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2024 13:27:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:187db172-8361-40b9-9347-70b51160d69f</guid><dc:creator>akif</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/kme"&gt;Kenneth&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you for the response.&lt;br /&gt;FYI, I had the clock stretching issue with a different MCU master device and using couple of commercial slave devices in the same bus. One of the commercial slave device stop responding even master supports clock stretching.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;If I am not wrong, basically you are saying:&lt;br /&gt;on bullet 1 and 3 : reset is needed&lt;br /&gt;on bullet 2 : reset is NOT needed.&lt;br /&gt;&lt;br /&gt;As I got, you have developed bullet 2 based on bullet 1. So it should behave similar. Right?&lt;/p&gt;
&lt;p&gt;As I mentioned above, in bullet 3 Zephyr basically says, the dynamic pin control has some issues.&amp;nbsp;Could&amp;nbsp;you check the !Note box in the below link and please let me know if you think otherwise.&amp;nbsp;&lt;/p&gt;
[quote userid="2111" url="~/f/nordic-q-a/108224/3-spi-and-2-i2c-pin-switching-on-runtime/468583"]&lt;a href="https://docs.zephyrproject.org/latest/hardware/pinctrl/index.html#dynamic-pin-control"&gt;Zephyr Dynamic pin control&lt;/a&gt;&amp;nbsp;[/quote]
&lt;p&gt;Thanks, Akif&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 3 SPI and 2 I2C pin switching on runtime</title><link>https://devzone.nordicsemi.com/thread/468583?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2024 12:13:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd98f95f-3bd8-4b51-8b26-e8281c10a4f4</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thanks for the explaination to why you have chosen to use different pins.&lt;/p&gt;
&lt;p&gt;FYI: The nRF52840 support clock stretching, so should not be any problem from it&amp;#39;s perspective at least.&lt;/p&gt;
[quote user="akif"]&lt;ul&gt;&lt;li&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.1/zephyr/samples/boards/nrf/dynamic_pinctrl/README.html"&gt;Dynamic Pin Control Sample(nRF)&lt;/a&gt;&amp;nbsp;On step 4 of this sample, the nRF52840 needs to be reset to continue to work.&amp;nbsp;Actually this doesn&amp;#39;t sounds like a dynamic pin allocation if need a reset. Is this reset actually required?&lt;/li&gt;
&lt;li&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/6761.hello_5F00_world_5F00_dynamic_5F00_pinctrl.zip"&gt;8156.hello_world_dynamic_pinctrl.zip&lt;/a&gt;&amp;nbsp;This sample you have provided doesn&amp;#39;t have a reset function. But I assume the nRF needs a reset&amp;nbsp;to continue to work without issue(assumed based below point)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.zephyrproject.org/latest/hardware/pinctrl/index.html#dynamic-pin-control"&gt;Zephyr Dynamic pin control&lt;/a&gt;&amp;nbsp;The note in this link looks very important. As I understand, basically says the runtime pin control is not working properly. Also, the note is a little bit strange. If a device is not initialized yet, that means I haven&amp;#39;t use the device with primary pin settings. And if I initialize It will initialize with secondary pin settings. If I am not gonna use the primary pin settings and if I can&amp;#39;t de-initialize why I should bother a pin switch?&lt;/li&gt;&lt;/ul&gt;[/quote]
&lt;p&gt;Regarding bullet 1 and 3: It&amp;#39;s been a while since I looked into those, but I remember making the same observation; that it was only possible to set it at boot time, so you basically required a reset to update the pins. This is not ideal no.&lt;/p&gt;
&lt;p&gt;Regarding bullet 2: This solves your problem by using power management api. If you look at the uart_pinout_update() you can find that the uart is suspended, pins are updated, and uart is resumed. Similar approach should be possible to do for spi and i2c/twi without any reset.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Keneth&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 3 SPI and 2 I2C pin switching on runtime</title><link>https://devzone.nordicsemi.com/thread/468482?ContentTypeID=1</link><pubDate>Mon, 12 Feb 2024 20:18:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b266311f-f1a2-4ab7-9b88-b8bbe063567b</guid><dc:creator>akif</dc:creator><description>&lt;p&gt;Just let you know, we already designed the custom board with&amp;nbsp;3 SPI and 2 I2C slaves on our device. All 5 slaves are individually connected to the separate pins.&amp;nbsp;&lt;br /&gt;Because we haven&amp;#39;t see a limitation&amp;nbsp;on the datasheet.&lt;/p&gt;
[quote userid="2111" url="~/f/nordic-q-a/108224/3-spi-and-2-i2c-pin-switching-on-runtime/468464"]Just to make sure I don&amp;#39;t misunderstand here, you are are planning&amp;nbsp;to use several SPI master and TWI/I2C master peripherals of the nRF52840 to communicate with several SPI slave and TWI/I2C slave devices. This is the most common setup, but I mention it in case I am missing something.[/quote]
&lt;p&gt;Correct, as mentioned above.&amp;nbsp;&lt;/p&gt;
[quote userid="2111" url="~/f/nordic-q-a/108224/3-spi-and-2-i2c-pin-switching-on-runtime/468464"]To comment on TWI/I2C, there is no need to swap pins here, it&amp;#39;s common to share pins, since the TWI/I2C master will allways use a device address for communication, so only one TWI/I2C slave will receive&amp;amp;respond at any time.[/quote]
&lt;p&gt;It is common to share pins but some I2C slave devices has clock stretching. And this issue may stop communication between master and slave and only recover until slave power is disconnected and connected again.&lt;br /&gt;So we didn&amp;#39;t want to have this problem and we have connected to separate pins of nRF52840.&lt;/p&gt;
[quote userid="2111" url="~/f/nordic-q-a/108224/3-spi-and-2-i2c-pin-switching-on-runtime/468464"]To comment on SPI, there is no need to swap pins here either, it&amp;#39;s common that the CLK, MISO and MOSI pins are shared between several SPI slaves. The way the SPI master ensure it only communicate with only one specific SPI slave, it that it will allways lower a Chip Select (CS) to indicate which SPI slave it communicate with at any given time. So you need to have several CS pins, but the 3 mentions CLK, MISO and MOSI can be shared.[/quote]
&lt;p&gt;We need to have a fast and constant communication with one SPI slave. So want to keep its pins are separate.&lt;br /&gt;For other slaves, we wanted keep pins separate for any possible signal error causes by any slave.&amp;nbsp;&lt;br /&gt;This shouldn&amp;#39;t cause a problem on the hardware of the nRF52840 as per datasheet. But as I understand, there are some limitations on the firmware that doesn&amp;#39;t allow us to do a pin switching on runtime.&lt;/p&gt;
[quote userid="2111" url="~/f/nordic-q-a/108224/3-spi-and-2-i2c-pin-switching-on-runtime/468464"]The reason I write the above is that dynamic re-allocation of pins in zephyr is not straight forward. However it is possible if you look at the way it can for instance be done for UART in this case:[/quote]
&lt;p&gt;Sorry, but I have reviewed the example and links, dynamic re-allocation of pin in zephyr have some problem.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.1/zephyr/samples/boards/nrf/dynamic_pinctrl/README.html"&gt;Dynamic Pin Control Sample(nRF)&lt;/a&gt;&amp;nbsp;On step 4 of this sample, the nRF52840 needs to be reset to continue to work.&amp;nbsp;Actually this doesn&amp;#39;t sounds like a dynamic pin allocation if need a reset. Is this reset actually required?&lt;/li&gt;
&lt;li&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/8156.hello_5F00_world_5F00_dynamic_5F00_pinctrl.zip"&gt;8156.hello_world_dynamic_pinctrl.zip&lt;/a&gt;&amp;nbsp;This sample you have provided doesn&amp;#39;t have a reset function. But I assume the nRF needs a reset&amp;nbsp;to continue to work without issue(assumed based below point)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.zephyrproject.org/latest/hardware/pinctrl/index.html#dynamic-pin-control"&gt;Zephyr Dynamic pin control&lt;/a&gt;&amp;nbsp;The note in this link looks very important. As I understand, basically says the runtime pin control is not working properly. Also, the note is a little bit strange. If a device is not initialized yet, that means I haven&amp;#39;t use the device with primary pin settings. And if I initialize It will initialize with secondary pin settings. If I am not gonna use the primary pin settings and if I can&amp;#39;t de-initialize why I should bother a pin switch?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Any comments would be appreciated. Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 3 SPI and 2 I2C pin switching on runtime</title><link>https://devzone.nordicsemi.com/thread/468464?ContentTypeID=1</link><pubDate>Mon, 12 Feb 2024 16:34:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:369b799c-9a32-4ce8-ba56-361418f7e638</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Just to make sure I don&amp;#39;t misunderstand here, you are are planning&amp;nbsp;to use several SPI master and TWI/I2C master peripherals of the nRF52840 to communicate with several SPI slave and TWI/I2C slave devices. This is the most common setup, but I mention it in case I am missing something.&lt;/p&gt;
&lt;p&gt;To comment on TWI/I2C, there is no need to swap pins here, it&amp;#39;s common to share pins, since the TWI/I2C master will allways use a device address for communication, so only one TWI/I2C slave will receive&amp;amp;respond at any time.&lt;/p&gt;
&lt;p&gt;To comment on SPI, there is no need to swap pins here either, it&amp;#39;s common that the CLK, MISO and MOSI pins are shared between several SPI slaves. The way the SPI master ensure it only communicate with only one specific SPI slave, it that it will allways lower a Chip Select (CS) to indicate which SPI slave it communicate with at any given time. So you need to have several CS pins, but the 3 mentions CLK, MISO and MOSI can be shared.&lt;/p&gt;
&lt;p&gt;The reason I write the above is that dynamic re-allocation of pins in zephyr is not straight forward. However it is possible if you look at the way it can for instance be done for UART in this case:&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/107317/configuring-uart1-using-pinctrl-for-two-uarts/463996"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/107317/configuring-uart1-using-pinctrl-for-two-uarts/463996&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>