<?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 interrupt by the Bluetooth</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/68972/spi-slave-interrupt-by-the-bluetooth</link><description>Hi. I am using nrf52840 with Softdevice 16.0.0 + BLE_uart_peripheral. 
 The SPI master transmits 2 SPI packets every 10 ms. At the the SPIS event handler, I call ble_nus_data_send() to send the SPI packet out. 
 However, I found the first couple bytes</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 14 Dec 2020 07:38:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/68972/spi-slave-interrupt-by-the-bluetooth" /><item><title>RE: SPI Slave interrupt by the Bluetooth</title><link>https://devzone.nordicsemi.com/thread/284686?ContentTypeID=1</link><pubDate>Mon, 14 Dec 2020 07:38:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc4ed9b0-aa9a-413a-a94b-8a3341360df2</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user=""]&lt;p&gt;I think it might be the issue similar to this post:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/4034/spi-slave-with-heavy-interrupt-in-btle#post-id-17712"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/4034/spi-slave-with-heavy-interrupt-in-btle#post-id-17712&lt;/a&gt;&lt;/p&gt;[/quote]
&lt;p&gt;&amp;nbsp;This very much sounds like the issue mentioned in the link. We have to understand that this is a single core chip with the softdevice taking the highest priority with the CPU. And once the CPU has the SPIS semaphore there is little we can do on the slave side to get that semaphore back in time.&lt;/p&gt;
&lt;p&gt;One of the problems seems to be the connection interval of your BLE connection. The softdevice might steal the CPU too often if you have very low number set for the connection perameters. Try increasing the connection interval if you are not targetting the throughput.&lt;/p&gt;
&lt;p&gt;Change the&amp;nbsp;SPIS_DEFAULT_CONFIG_IRQ_PRIORITY to 2 to give the SPIS handling a higher priority than the BLE host processing. This will increase the likelihood of the SPI owning the semaphore when the master is transmitting (increases the chances but not 100% guarenteed)&lt;/p&gt;
&lt;p&gt;You can also tell the SPIM to retransmit the packet, when the slave responds with DEF character (happens when slave has to ignore packet sent by master as slave does not own the spi semaphore at that time)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Slave interrupt by the Bluetooth</title><link>https://devzone.nordicsemi.com/thread/284500?ContentTypeID=1</link><pubDate>Fri, 11 Dec 2020 11:45:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e7625b7-0c9b-4b31-a15a-3106cdb505c9</guid><dc:creator>dayizhang</dc:creator><description>&lt;p&gt;I tried storing spi receive data into fifo and call m_ble_send in the main loop. But it doesnt help &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f61e.svg" title="Disappointed"&gt;&amp;#x1f61e;&lt;/span&gt;. I found the problem became worse when my ble central (another 52840 chip) connected the first device and scanning for the second device. It backs to the normal problem behavior after both devices connected.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Slave interrupt by the Bluetooth</title><link>https://devzone.nordicsemi.com/thread/282766?ContentTypeID=1</link><pubDate>Tue, 01 Dec 2020 22:39:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f1cbc953-65f6-4408-ac5c-65b5c69b292f</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;&lt;em&gt;I cant trigger my scope without single stepping&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Try increasing&amp;nbsp;the &amp;#39;scope io pin drive to H0H1 in case the probes are very capacitive; it would have to be a very slow &amp;#39;scope not to catch that toggle (must set &lt;em&gt;Trig&lt;/em&gt; to &lt;em&gt;Normal&lt;/em&gt;). Adding a second pin to the &amp;#39;scope (also H0H1) which is driven on the packet corrupted condition might provide some useful information.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Slave interrupt by the Bluetooth</title><link>https://devzone.nordicsemi.com/thread/282765?ContentTypeID=1</link><pubDate>Tue, 01 Dec 2020 22:19:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a44bdc9-eecf-4a2b-9277-a40bd7987ff6</guid><dc:creator>dayizhang</dc:creator><description>&lt;p&gt;I understand. But I scoped the gpio line which toggling at the entrance and exit of spi handler. I cant trigger my scope without single stepping, which suggests the time is very very short. Much less than 1 ms.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Slave interrupt by the Bluetooth</title><link>https://devzone.nordicsemi.com/thread/282763?ContentTypeID=1</link><pubDate>Tue, 01 Dec 2020 21:41:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6108a23a-88ab-44dc-b6a6-e4c695051013</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Perhaps I was too vague and quick to answer; this is a typical invocation of&amp;nbsp;&lt;em&gt;ble_nus_data_send()&lt;/em&gt;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    do
    {
       uint16_t length = (uint16_t)index;
       err_code = ble_nus_data_send(&amp;amp;m_nus, data_array, &amp;amp;length, m_conn_handle);
       // Also now check BLE_ERROR_GATTS_SYS_ATTR_MISSING or correctly set up due to timer race hazard
       if ((err_code != NRF_ERROR_INVALID_STATE)
        &amp;amp;&amp;amp; (err_code != NRF_ERROR_RESOURCES)
        &amp;amp;&amp;amp; (err_code != NRF_ERROR_NOT_FOUND)
        &amp;amp;&amp;amp; (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING))
       {
          APP_ERROR_CHECK(err_code);
       }
    } while (err_code == NRF_ERROR_RESOURCES);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This effectively blocks within an interrupt, which is to be discouraged. Blocking in the foreground is fine.&amp;nbsp;The master may be sending the next SPI packet while the previous SPI interrupt is still active;&amp;nbsp; simple to test, maybe it&amp;#39;ll help. Buffering (copying) the received data might also help, hard to say without sight of the SPI handler&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Slave interrupt by the Bluetooth</title><link>https://devzone.nordicsemi.com/thread/282762?ContentTypeID=1</link><pubDate>Tue, 01 Dec 2020 21:13:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba7ab359-5388-4229-8273-d239b34ca518</guid><dc:creator>dayizhang</dc:creator><description>&lt;p&gt;&lt;em&gt;I thought ble_nus_data_send() just moves the packet into the bluetooth stack and softdevice handles the actual bluetooth communication at the background. So the conflict is the interrupts from softdevice and spi.&amp;nbsp;&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Slave interrupt by the Bluetooth</title><link>https://devzone.nordicsemi.com/thread/282758?ContentTypeID=1</link><pubDate>Tue, 01 Dec 2020 20:45:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:032b9c39-5073-4d91-bf09-411023fb4a00</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Nested interrupts are often the issue; try moving&amp;nbsp;&lt;span&gt;&lt;em&gt;ble_nus_data_send()&lt;/em&gt; out of the SPIS event handler and into foreground code such as &lt;em&gt;main()&lt;/em&gt;. Set a bool flag in the SPIS event handler and when seen as set in the foreground then invoke&amp;nbsp;&lt;em&gt;ble_nus_data_send()&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>