<?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>nrf52832 SPI Code execution time</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/78283/nrf52832-spi-code-execution-time</link><description>Hi, 
 I&amp;#39;m BLE-sending out Sensor values using a nrf52832. When the sensor gets a (new) value an interrupt is generated and the nrf then transfers the value in the gpiote inerrupt handler via SPI from the sensor. Therefore 2 SPI Commands like the following</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 10 Aug 2021 08:09:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/78283/nrf52832-spi-code-execution-time" /><item><title>RE: nrf52832 SPI Code execution time</title><link>https://devzone.nordicsemi.com/thread/324146?ContentTypeID=1</link><pubDate>Tue, 10 Aug 2021 08:09:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8413b3f8-24b8-4618-93cc-0aef10bce46d</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="hannes"]I&amp;#39;m still not sure If there would be an improvement in moving something to the main context?[/quote]
&lt;p&gt;In terms of speed, it&amp;nbsp;isn&amp;#39;t an improvement, but in terms of reducing time spent in interrupt; it will be. However, 40 us is not that costly timing wise.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 SPI Code execution time</title><link>https://devzone.nordicsemi.com/thread/324140?ContentTypeID=1</link><pubDate>Tue, 10 Aug 2021 08:01:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf98e70d-228a-47d2-a990-ed18b9c60beb</guid><dc:creator>hannes</dc:creator><description>&lt;p&gt;Thanks H&amp;aring;kon,&lt;/p&gt;
&lt;p&gt;removing &amp;quot;__WFE()&amp;quot; speeded it up to 40 microseconds which is pretty good for my application. I&amp;#39;m still not sure If there would be an improvement in moving something to the main context?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 SPI Code execution time</title><link>https://devzone.nordicsemi.com/thread/324038?ContentTypeID=1</link><pubDate>Mon, 09 Aug 2021 13:42:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:75f3e41f-6f0f-4f47-85a5-84c8f69cd300</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="hannes"]&lt;p&gt;The IRQ-priorities are set as:&lt;/p&gt;
&lt;p&gt;GPIOTE_CONFIG_IRQ_PRIORITY 6&lt;br /&gt;SPI_DEFAULT_CONFIG_IRQ_PRIORITY 5&lt;/p&gt;
&lt;p&gt;Is this OK?&lt;/p&gt;[/quote]
&lt;p&gt;Yes, that is fine.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="hannes"]thank&amp;#39;s very much for your detailed answer. I&amp;#39;m not sure how to implement the SPI-while() loop in main as I&amp;#39;m already using&amp;nbsp;&lt;em&gt;idle_state_handle();&lt;/em&gt; in main like in the nordic BLE-Examples. Can you please tell me how to get theese things together in my code example?[/quote]
&lt;p&gt;&amp;nbsp;You are still handling this directly in two interrupt vectors, with no scheduling (ie. offloading processing) to main. If you want to speed up, remove the &amp;quot;__WFE()&amp;quot; call in getValues().&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Since the call &amp;quot;nrf_drv_spi_transfer()&amp;quot; is effectively a blocking call due to your next line while(!spi_xfer_done), the minimum time for those interrupts is equal to the time it takes to transfer those bytes over SPI.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 SPI Code execution time</title><link>https://devzone.nordicsemi.com/thread/323982?ContentTypeID=1</link><pubDate>Mon, 09 Aug 2021 11:38:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3e51ef4-0885-4655-8ac8-8029c522164c</guid><dc:creator>hannes</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;H&amp;aring;kon,&lt;br /&gt;&lt;br /&gt;thank&amp;#39;s very much for your detailed answer. I&amp;#39;m not sure how to implement the SPI-while() loop in main as I&amp;#39;m already using&amp;nbsp;&lt;em&gt;idle_state_handle();&lt;/em&gt; in main like in the nordic BLE-Examples. Can you please tell me how to get theese things together in my code example?&lt;/p&gt;
&lt;p&gt;The IRQ-priorities are set as:&lt;/p&gt;
&lt;p&gt;GPIOTE_CONFIG_IRQ_PRIORITY 6&lt;br /&gt;SPI_DEFAULT_CONFIG_IRQ_PRIORITY 5&lt;/p&gt;
&lt;p&gt;Is this OK?&lt;/p&gt;
&lt;p&gt;Thank you very much in advance!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void getValues(uint8_t sensor[])
{
    APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, m_tx_buf, 1, m_rx_buf, 2));
    while (!spi_xfer_done) { __WFE(); }		
    spi_xfer_done = false;
}


static void int_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    uint8_t   sensor[2];
    getValues(sensor);
}

void spi_event_handler(nrf_drv_spi_evt_t const * p_event, void *p_context)
{
    spi_xfer_done = true;
}


int main(void)
{
    initialize_nrf;
    initialize_nrf_ble;
    initialize_sersor_via_spi;

    for (;;)
    {
        idle_state_handle();
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 SPI Code execution time</title><link>https://devzone.nordicsemi.com/thread/323718?ContentTypeID=1</link><pubDate>Fri, 06 Aug 2021 11:47:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2739631-6740-44d5-ab6b-332515fa9043</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]So adding this line of code seems to speed up the execution time of the SPI commands[/quote]
&lt;p&gt;Compilers optimize in the strangest ways.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you are triggering a SPI transaction from the GPIOTE irq vector, you should avoid to do this in the interrupt handler:&lt;/p&gt;
&lt;p&gt;* logging&lt;/p&gt;
&lt;p&gt;* sleeping&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please also note that if you set the same priority on the two IRQs, you will get into a while(1) loop on the spi_xfer_done call.&lt;/p&gt;
&lt;p&gt;This will essentially take as long as it takes to:&lt;/p&gt;
&lt;p&gt;* Handle two interrupt vectors&lt;/p&gt;
&lt;p&gt;* Send and receive over SPI&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you want to make the ISR functions run quicker, disable logging, and move the while() loop to main context.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>