<?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>Multiple SPI Instances</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89449/multiple-spi-instances</link><description>Hi, 
 
 I&amp;#39;m working on a project where the NRF52840 chip is connected to multiple peripherals (4 of them) through SPI. The hardware has been designed in a way that each peripheral has its separate SPI pins (separate clock and data pins). I&amp;#39;m trying to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 11 Jul 2022 22:53:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89449/multiple-spi-instances" /><item><title>RE: Multiple SPI Instances</title><link>https://devzone.nordicsemi.com/thread/376513?ContentTypeID=1</link><pubDate>Mon, 11 Jul 2022 22:53:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33202d6c-3df8-4df0-85b3-ee76363c5c16</guid><dc:creator>EAkeila</dc:creator><description>&lt;p&gt;Makes sense. Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiple SPI Instances</title><link>https://devzone.nordicsemi.com/thread/376349?ContentTypeID=1</link><pubDate>Mon, 11 Jul 2022 08:14:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:230fbe79-3304-4c70-9635-51f184b2fd58</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes, because you need to re-initialize the instance to re-configure the assigned pins for the SPIM instance. Before you can reinitialize you would have to un initialize the instance.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Alternatively, you can use 4 instances for each SPI slave. That way you would only have to configure it once.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiple SPI Instances</title><link>https://devzone.nordicsemi.com/thread/376304?ContentTypeID=1</link><pubDate>Mon, 11 Jul 2022 01:32:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e01f3b8-5ed7-4126-b0d2-0c7c0372d7ef</guid><dc:creator>EAkeila</dc:creator><description>[quote userid="73165" url="~/f/nordic-q-a/89449/multiple-spi-instances/374911"]Have you un initialized the driver first by calling&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/drivers_nrfx_v2.8.0/group__nrfx__spim.html#gae4d9fcf6dd9db5fe9f9d64bb7c6c80a3"&gt;nrfx_spim_uninit&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/drivers_nrfx_v2.8.0/structnrfx__spim__t.html"&gt;nrfx_spim_t&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;const *p_instance)?&lt;/span&gt;[/quote]
&lt;p&gt;Thanks Jared. So for using one SPI instance for 2 peripherals, do I need to call &amp;quot;nrfx_spim_uinit&amp;quot; and re-initialise spi every time I need to do an spi transaction on each peripheral?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiple SPI Instances</title><link>https://devzone.nordicsemi.com/thread/374911?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2022 12:43:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d05824eb-714d-4434-9771-5db4fb2f3e83</guid><dc:creator>Jared</dc:creator><description>[quote user="EAkeila"]&lt;p&gt;2- For this one, I used Instance 0 for example to initialize the spi interface for two peripherals (i.e. I reinitialised the same instance twice for 2 peripherals), which does not work from the description of the error code.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;Have you un initialized the driver first by calling&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/drivers_nrfx_v2.8.0/group__nrfx__spim.html#gae4d9fcf6dd9db5fe9f9d64bb7c6c80a3"&gt;nrfx_spim_uninit&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/drivers_nrfx_v2.8.0/structnrfx__spim__t.html"&gt;nrfx_spim_t&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;const *p_instance)?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
[quote user="EAkeila"]3- I agree that would be the ideal case. However, I dont think I can change the hardware at the moment. My question was more about how to handle the current hardware from the firmware side. Do you recommend defining a different instance for each peripheral or can I reuse the same instance for multiple peripherals[/quote]
&lt;p&gt;I don&amp;#39;t think it matters much if you don&amp;#39;t use them at the same time. The current consumption would effectively be the same.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiple SPI Instances</title><link>https://devzone.nordicsemi.com/thread/374810?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2022 00:08:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f31b6cb5-81bc-49b2-881a-86407e33f1b5</guid><dc:creator>EAkeila</dc:creator><description>&lt;p&gt;Thanks a lot Jared. Here are my responses:&lt;/p&gt;
&lt;p&gt;- On the hardware side, each peripheral has a separate CS pin. I know this is not the ideal design but I need to live with that.&lt;/p&gt;
&lt;p&gt;And for the questions:&lt;/p&gt;
&lt;p&gt;1- Thanks for the info. I&amp;#39;ll try that and see if this works.&lt;/p&gt;
&lt;p&gt;2- For this one, I used Instance 0 for example to initialize the spi interface for two peripherals (i.e. I reinitialised the same instance twice for 2 peripherals), which does not work from the description of the error code.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;3- I agree that would be the ideal case. However, I dont think I can change the hardware at the moment. My question was more about how to handle the current hardware from the firmware side. Do you recommend defining a different instance for each peripheral or can I reuse the same instance for multiple peripherals&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks a lot in advance!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiple SPI Instances</title><link>https://devzone.nordicsemi.com/thread/374709?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2022 11:10:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2159f2f6-1fdb-4571-9943-3ae20d4af83d</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""] The hardware has been designed in a way that each peripheral has its separate SPI pins (separate clock and data pins). [/quote]
&lt;p&gt;But not separate CS pins?&amp;nbsp;&lt;/p&gt;
[quote user=""]&lt;p&gt;1- I used SPI instance 0 with no issues. I used instance 1 for another device and I got this compilation error:&lt;/p&gt;
&lt;p&gt;error:&amp;nbsp; #20: identifier &amp;quot;NRF_DRV_SPI_INSTANCE_1&amp;quot; is undefined&lt;/p&gt;
&lt;p&gt;I tried to enable multiple things in the sdk_config.h but none of them worked. Please let me know how to enable Instances1,2,3 properly.&lt;/p&gt;[/quote]
&lt;p&gt;You need to enable corresponding nrfx define in sdk_config.h:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// &amp;lt;e&amp;gt; NRFX_SPIM_ENABLED - nrfx_spim - SPIM peripheral driver
//==========================================================
#ifndef NRFX_SPIM_ENABLED
#define NRFX_SPIM_ENABLED 1
#endif
// &amp;lt;q&amp;gt; NRFX_SPIM0_ENABLED  - Enable SPIM0 instance
 

#ifndef NRFX_SPIM0_ENABLED
#define NRFX_SPIM0_ENABLED 1
#endif

// &amp;lt;q&amp;gt; NRFX_SPIM1_ENABLED  - Enable SPIM1 instance
 

#ifndef NRFX_SPIM1_ENABLED
#define NRFX_SPIM1_ENABLED 1
#endif

// &amp;lt;q&amp;gt; NRFX_SPIM2_ENABLED  - Enable SPIM2 instance
 

#ifndef NRFX_SPIM2_ENABLED
#define NRFX_SPIM2_ENABLED 1
#endif

// &amp;lt;q&amp;gt; NRFX_SPIM3_ENABLED  - Enable SPIM3 instance
 

#ifndef NRFX_SPIM3_ENABLED
#define NRFX_SPIM3_ENABLED 1
#endif

// &amp;lt;q&amp;gt; NRFX_SPIM_EXTENDED_ENABLED  - Enable extended SPIM features
 

#ifndef NRFX_SPIM_EXTENDED_ENABLED
#define NRFX_SPIM_EXTENDED_ENABLED 1
#endif

// &amp;lt;o&amp;gt; NRFX_SPIM_MISO_PULL_CFG  - MISO pin pull configuration.
 
// &amp;lt;0=&amp;gt; NRF_GPIO_PIN_NOPULL 
// &amp;lt;1=&amp;gt; NRF_GPIO_PIN_PULLDOWN 
// &amp;lt;3=&amp;gt; NRF_GPIO_PIN_PULLUP 

#ifndef NRFX_SPIM_MISO_PULL_CFG
#define NRFX_SPIM_MISO_PULL_CFG 1
#endif

// &amp;lt;o&amp;gt; NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
 
// &amp;lt;0=&amp;gt; 0 (highest) 
// &amp;lt;1=&amp;gt; 1 
// &amp;lt;2=&amp;gt; 2 
// &amp;lt;3=&amp;gt; 3 
// &amp;lt;4=&amp;gt; 4 
// &amp;lt;5=&amp;gt; 5 
// &amp;lt;6=&amp;gt; 6 
// &amp;lt;7=&amp;gt; 7 

#ifndef NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY
#define NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY 6
#endif&lt;/pre&gt;&lt;/p&gt;
[quote user=""]&lt;p&gt;2- I tried to reuse the same instance for 2 peripherals but I got this runtime error:&lt;/p&gt;
&lt;p&gt;NRF_ERROR_INVALID_STATE which occurred when calling&amp;nbsp; &amp;quot;nrfx_spi_init&amp;quot; inside &amp;quot;nrf_drv_spi_init&amp;quot;&lt;/p&gt;[/quote]
&lt;p&gt;The driver will return this when it has already been initialized. What do you mean using same instance for 2 peripherals?&lt;/p&gt;
[quote user=""]3- Is there a better approach you can recommend to talk to 4 devices at the through different SPI?[/quote]
&lt;p&gt;You can have one SPIM for multiple slaves by connecting them on the same bus, but you have to use separate CS for each slave. There is possibility that this would decrease the maximum frequency due to the increased line capacitance, but I think it should be ok if you set the GPIO to high drive. Either way you would have to test and see if it works or not.&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>