<?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>SPI Slave Question</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/76615/spi-slave-question</link><description>When NRF52832 as SPI Slave, how can I know how many bytes the slave should read,the API nrf_drv_spis_buffers_set(&amp;amp;spis, m_tx_buf, length, m_rx_buf, length)),does not have the real receive byte</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 23 Jun 2021 08:03:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/76615/spi-slave-question" /><item><title>RE: SPI Slave Question</title><link>https://devzone.nordicsemi.com/thread/316619?ContentTypeID=1</link><pubDate>Wed, 23 Jun 2021 08:03:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:348e613f-d02c-4df9-91d0-8b57265f0486</guid><dc:creator>great-master</dc:creator><description>&lt;p&gt;I know 大哥。。。&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Slave Question</title><link>https://devzone.nordicsemi.com/thread/316618?ContentTypeID=1</link><pubDate>Wed, 23 Jun 2021 07:59:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dad24906-eee2-4137-8a0a-8de6f2ab9fd4</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;You are developing the Slave - so &lt;em&gt;&lt;strong&gt;you&lt;/strong&gt; &lt;/em&gt;define the commands that it will accept.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Slave Question</title><link>https://devzone.nordicsemi.com/thread/316617?ContentTypeID=1</link><pubDate>Wed, 23 Jun 2021 07:54:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2fb5fd88-11f1-4115-addd-ad0c0eb71a61</guid><dc:creator>great-master</dc:creator><description>&lt;p&gt;May be my question is not description clearly, in short ,I don&amp;#39;t know what&amp;#39;s data to put into&amp;nbsp;m_tx_buf before first command received.So Now my master must read twice that can get the correct result.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Slave Question</title><link>https://devzone.nordicsemi.com/thread/316584?ContentTypeID=1</link><pubDate>Wed, 23 Jun 2021 05:19:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce895189-9a09-41d7-818c-3d882c59300a</guid><dc:creator>great-master</dc:creator><description>&lt;p&gt;I have write a test SPI master, when execute read operation, SPI slave produce&amp;nbsp;NRF_DRV_SPIS_XFER_DONE event, then the whole data is in buffer, I have no time to process the data and judgement which command have receive&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Slave Question</title><link>https://devzone.nordicsemi.com/thread/316573?ContentTypeID=1</link><pubDate>Wed, 23 Jun 2021 00:57:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e83e26a8-e560-4d80-bdd0-44e96e02f96c</guid><dc:creator>great-master</dc:creator><description>&lt;p&gt;how to know the command?When CS pin is low, first receive one bye to judgement which command have received?Then know the length and read once again?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Slave Question</title><link>https://devzone.nordicsemi.com/thread/316447?ContentTypeID=1</link><pubDate>Tue, 22 Jun 2021 11:20:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5dcfcd0-8a79-4095-8613-6fd31777aba4</guid><dc:creator>awneil</dc:creator><description>[quote userid="103671" url="~/f/nordic-q-a/76615/spi-slave-question/316440#316440"]the slave can not know which cmd will receive, so how can set write length[/quote]
&lt;p&gt;Again, it is the Slave which defines this - so it&amp;#39;s up to you.&lt;/p&gt;
&lt;p&gt;The Master has to abide by&amp;nbsp;what the Slave does; ie, the agreed protocol.&lt;/p&gt;
&lt;p&gt;You will have to design-in handling of invalid conditions.&lt;/p&gt;
&lt;p&gt;This has nothing specifically to do with nRF - this applies to &lt;em&gt;&lt;strong&gt;any&lt;/strong&gt; &lt;/em&gt;comms interface.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Slave Question</title><link>https://devzone.nordicsemi.com/thread/316440?ContentTypeID=1</link><pubDate>Tue, 22 Jun 2021 11:09:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6020bfa1-cb10-4590-bb4c-76a2ad19a72c</guid><dc:creator>great-master</dc:creator><description>&lt;p&gt;I put&amp;nbsp;&lt;span&gt;nrf_drv_spis_buffers_set in a task, and block until csn_pin is low, then read/write&amp;nbsp;to master. if I define the&amp;nbsp;protocol&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;cmd:0x01, return 2 bytes, so the master can read 3 bytes(one byte cmd)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;cmd:0x02,return 4 bytes,&amp;nbsp;so the master can read 5 bytes(one byte cmd)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The question is the slave can not know which cmd will receive, so how can set write length in&amp;nbsp;nrf_drv_spis_buffers_set at task.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void station_gpiote_evt_handler_t(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    BaseType_t higher_priority_task_woken, result;
    higher_priority_task_woken = pdFALSE;

    if(station_event_handle == NULL)
    {
        NRF_LOG_WARNING(&amp;quot;Task event is not create now\r\n&amp;quot;);
        return;
    }

    if((pin == SPIS_CS_PIN) &amp;amp;&amp;amp; (action == NRF_GPIOTE_POLARITY_HITOLO))
    {
        result = xEventGroupSetBitsFromISR(station_event_handle, 
                                           SPIS_CSN_EVENT, 
                                           &amp;amp;higher_priority_task_woken);
        if(result != pdFAIL)
        {
            portYIELD_FROM_ISR( higher_priority_task_woken );
        }
    }
}


static void station_main_task(void *args)
{
    UNUSED_PARAMETER(args);
    ret_code_t err_code;
    EventBits_t event;

    while(1)
    {
        event = xEventGroupWaitBits(station_event_handle,
                                    SPIS_CSN_EVENT,
                                    pdTRUE,  /* bit should be cleared before returning. */
                                    pdFALSE, /* Don&amp;#39;t wait for both bits, either bit will do. */
                                    portMAX_DELAY);
        if((event &amp;amp; SPIS_CSN_EVENT) == SPIS_CSN_EVENT)
        {
            NRF_LOG_INFO(&amp;quot;CS High-&amp;gt;Low, now read spi bus&amp;quot;);
            nrf_drv_spis_buffers_set(&amp;amp;spis, m_tx_buf, length, m_rx_buf, length)
        }
    }
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Slave Question</title><link>https://devzone.nordicsemi.com/thread/316420?ContentTypeID=1</link><pubDate>Tue, 22 Jun 2021 09:15:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69725956-2c9f-42d8-9e62-66ea09a8ed35</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;This is usually defined by the Slave. So, in the usual use-case of the microcontroller being the master, you would look it up in the Slave&amp;#39;s documentation.&lt;/p&gt;
&lt;p&gt;As you are creating the Slave here, it is you that defines what&amp;nbsp;it does.&lt;/p&gt;
&lt;p&gt;If you want it to be variable, then you will have to devise some sort of protocol to exchange the information.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>