<?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 can I assign a new Slave Select Pin to the SPI?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/80246/how-can-i-assign-a-new-slave-select-pin-to-the-spi</link><description>if i am controlling two spi devices with one instance, can I just define a new SS in the same SPIconfiguration or do i have to close the connection and select a new one? 
 is it possible to control the second SPI while the first one is waiting to receive</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 06 Oct 2021 11:44:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/80246/how-can-i-assign-a-new-slave-select-pin-to-the-spi" /><item><title>RE: How can I assign a new Slave Select Pin to the SPI?</title><link>https://devzone.nordicsemi.com/thread/332818?ContentTypeID=1</link><pubDate>Wed, 06 Oct 2021 11:44:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a409567-b16e-4121-bd4f-fd68dbce774b</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote userid="95174" url="~/f/nordic-q-a/80246/how-can-i-assign-a-new-slave-select-pin-to-the-spi/332419#332419"]perfect! thank you very much![/quote]
&lt;p&gt;No problem at all, I am happy to help! :)&amp;nbsp;&lt;/p&gt;
[quote userid="95174" url="~/f/nordic-q-a/80246/how-can-i-assign-a-new-slave-select-pin-to-the-spi/332419#332419"]i will let you know how it goes![/quote]
&lt;p&gt;Great, I look forward to hearing about it!&lt;br /&gt;&lt;br /&gt;Please do not hesitate to open another ticket if you should encounter any issues or questions in the future.&lt;br /&gt;&lt;br /&gt;Good luck with your development!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I assign a new Slave Select Pin to the SPI?</title><link>https://devzone.nordicsemi.com/thread/332419?ContentTypeID=1</link><pubDate>Mon, 04 Oct 2021 16:14:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e74db8a4-21ae-4502-a74d-fa043cf48688</guid><dc:creator>Javiehm</dc:creator><description>&lt;p&gt;perfect! thank you very much! i will let you know how it goes! (this, of course is the answer to the last comment)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I assign a new Slave Select Pin to the SPI?</title><link>https://devzone.nordicsemi.com/thread/332408?ContentTypeID=1</link><pubDate>Mon, 04 Oct 2021 14:59:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d38654be-d889-4c81-9c70-d7485caec20e</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello again,&lt;/p&gt;
[quote user="Javiehm"]thanks for trying to answer the questions, i will explain a little bit more[/quote]
&lt;p&gt;No problem at all, I am happy to help!&lt;br /&gt;Thank you for elaborating.&lt;/p&gt;
[quote user="Javiehm"]Should i overwrite the structure with a function that makes something like:&lt;br /&gt;spi_config.ss_pin=&amp;nbsp;NEW_SS_PIN&lt;br /&gt;&lt;br /&gt;I somehow think this is not possible since the structure is already defined[/quote]
&lt;p&gt;Oh, now I understand what you mean. My apologies, I should have been more explicit.&lt;br /&gt;Yes, the SPIM peripheral can not control the SS pin directly. Please see &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/59943/spi-master-example-fix"&gt;the answer by my colleague Håkon in this ticket&lt;/a&gt;. Furthermore, neither of the SPI drivers are made for having multiple slaves on the same bus, so in this case you will have to control the SS pins separately.&lt;br /&gt;You can &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/hardware_driver_spi_master.html"&gt;read more about this in the driver description&lt;/a&gt;.&lt;br /&gt;I do not recommend that you modify the driver to incorporate this, since modifying of the driver may break it. Instead, you could create a separate function for initiating a transfer with either device, and toggle the appropriate SS pin from there.&lt;/p&gt;
[quote user="Javiehm"]2) Whenever you activate a sensor with spi you have to wait for the sensor to gather the data, normally you could just poll until it is done. What I want to do is to use this time to effectuate a second SPI call, with the same instance, to another sensor, so that it starts gathering information[/quote]
&lt;p&gt;The first sensor will be listening in on the bus as long as its SS is active, so if you intend to communicate with another sensor you will need to deactivate the first SS so that it does not receive the commands meant for the second device.&lt;br /&gt;If the device you are working with does not require its SS to be high for the entire duration of the initial command + processing delay then I see no reason why this should not work.&lt;br /&gt;Essentially, you would then toggle the first SS, send the first command, toggle the first SS, toggle the second SS, send some command, toggle the second SS, toggle the first SS, and finally receive the data from the initial device.&lt;/p&gt;
[quote user="Javiehm"]and i know that i have to change the SS pin, the question is where? do you have a snippet where SPIM_0 addresses two slaves?&amp;nbsp;[/quote]
&lt;p&gt;I do not have this, unfortunately, but I would suggest following the approach from the top of my answer - incorporating the SS toggling in a separate function for initiating transfers with a specific device. Note that you should create some kind of semaphore to avoid both SS being selected at the same time.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I assign a new Slave Select Pin to the SPI?</title><link>https://devzone.nordicsemi.com/thread/332392?ContentTypeID=1</link><pubDate>Mon, 04 Oct 2021 14:08:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd7dc083-0089-4418-b3ce-6fb6dad9a7b9</guid><dc:creator>Javiehm</dc:creator><description>&lt;p&gt;Hey thanks for trying to answer the questions, i will explain a little bit more:&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1) I know I have to change the SS, the question is in which part does this take place then:&lt;br /&gt;In the &lt;strong&gt;initializeSPI_Instance&lt;/strong&gt; you define which are the pins clock, miso, mosi and ss, plus the frequency, etc.&amp;nbsp;Should i overwrite the structure with a function that makes something like:&lt;br /&gt;spi_config.ss_pin=&amp;nbsp;NEW_SS_PIN&lt;br /&gt;&lt;br /&gt;I somehow think this is not possible since the structure is already defined&lt;br /&gt;&lt;br /&gt;2) Whenever you activate a sensor with spi you have to wait for the sensor to gather the data, normally you could just poll until it is done. What I want to do is to use this time to effectuate a second SPI call, with the same instance, to another sensor, so that it starts gathering information&lt;br /&gt;&lt;br /&gt;3) If i need a SPI Instance for each sensor, then i can only get two slaves with the NRFf5832 PCA1400....&lt;br /&gt;So yeah my question is precisely how:&amp;nbsp;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/80246/how-can-i-assign-a-new-slave-select-pin-to-the-spi/332388#332388"]you will need to control which of the devices you are targeting by selecting their SS pin[/quote]
&lt;p&gt;&lt;br /&gt;and i know that i have to change the SS pin, the question is where? do you have a snippet where SPIM_0 addresses two slaves?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;thank you!&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I assign a new Slave Select Pin to the SPI?</title><link>https://devzone.nordicsemi.com/thread/332388?ContentTypeID=1</link><pubDate>Mon, 04 Oct 2021 13:54:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29a3ee1d-a701-464a-8d48-6d071d003589</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]if i am controlling two spi devices with one instance, can I just define a new SS in the same SPIconfiguration or do i have to close the connection and select a new one?[/quote]
&lt;p&gt;I am not entirely sure what you mean when you say close the connection, but you could toggle the SS pin as a GPIO, to control which device on the SPI bus that receives the transfer.&lt;/p&gt;
[quote user=""]is it possible to control the second SPI while the first one is waiting to receive data?[/quote]
&lt;p&gt;Could you elaborate on what you mean by this as well?&lt;br /&gt;Only one slave may be active on MISO at the same time - so unless there is a waiting period in between transfers in which you release the SS of the first device, and then toggle the SS of the second device, then this is not possible, no.&lt;br /&gt;Slave devices will only listen for messages on the bus when their SS is active.&lt;/p&gt;
[quote user=""]if not, can i use another spi instance or do both Instances are clock connected?[/quote]
&lt;p&gt;You may indeed use a separate SPI instance for each device, just duplicate the setup and configuration for your previous SPIM instance and change the pin configuration.&lt;br /&gt;You could also have multiple SPI devices on the same SPI bus, but as mentioned you will need to control which of the devices you are targeting by selecting their SS pin.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>