<?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 blocked by BLE(idle_state_handle())</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/103073/spi-blocked-by-ble-idle_state_handle</link><description>Hi all, 
 
 I have an issue, where the SPI communication with a MCP2518 doesn&amp;#39;t work correct. the required functionality needs to transmit 3 CAN Messages and to receive CAN answers every 25ms. 
 Without BLE involvement (especially when i comment out the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 24 Aug 2023 08:15:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/103073/spi-blocked-by-ble-idle_state_handle" /><item><title>RE: SPI blocked by BLE(idle_state_handle())</title><link>https://devzone.nordicsemi.com/thread/442898?ContentTypeID=1</link><pubDate>Thu, 24 Aug 2023 08:15:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0399cdf2-fb67-495c-9a3d-c8bfbf8b3b24</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="Buli"]I&amp;#39;m using only SPI, so I think it shouldn&amp;#39;t block something else.[/quote]
&lt;p&gt;The logs processing and the handling of BLE application events will be blocked since you&amp;#39;re spinning in a loop until the SPI transaction has been completed:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;err_code = nrf_drv_spi_transfer(&amp;amp;spi, SpiTxData, spiTransferSize, Spirxd, spiTransferSize);
while (!spi_xfer_done)
{
__WFE();
}&lt;/pre&gt;&lt;/p&gt;
[quote user="Buli"]A flag will be set in the timer callback handler. The flag will trigger in the main loop the call from getOBDData()[/quote]
&lt;p&gt;And&amp;nbsp;&lt;span&gt;getOBDData() will call&amp;nbsp;DRV_SPI_TransferData()?&lt;/span&gt;&lt;/p&gt;
[quote user="Buli"]At both modes the SPI is slowed down for an intervall 1,2sec[/quote]
&lt;p&gt;What kind of BLE activity are you running? Is it in a connection or is it advertising?&lt;/p&gt;
[quote user="Buli"]&lt;blockquote&gt;&lt;div&gt;an interrupt to happen,&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;/div&gt;
&lt;p&gt;When I comment out NRF_LOG_PROCESS(), then everything works fine. But why is it so? I couldn&amp;#39;t find an answer&lt;/p&gt;[/quote]
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;NRF_LOG_PROCESS will process any pending logs, the more logs that are in the queue, the longer time it will take for it to process the log data. If you don&amp;#39;t need to use the logger, then you can always disable it.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;regards&lt;br /&gt;Jared&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocked by BLE(idle_state_handle())</title><link>https://devzone.nordicsemi.com/thread/442746?ContentTypeID=1</link><pubDate>Wed, 23 Aug 2023 10:53:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:62444034-1787-4493-b43a-a3cb589bfab1</guid><dc:creator>Buli</dc:creator><description>&lt;p&gt;Hi, I&amp;#39;ll try to answer for all&lt;/p&gt;
[quote userid="73165" url="~/f/nordic-q-a/103073/spi-blocked-by-ble-idle_state_handle/442726"]Which SPI instance are you using?[/quote]
&lt;p&gt;SPI0&lt;/p&gt;
[quote userid="73165" url="~/f/nordic-q-a/103073/spi-blocked-by-ble-idle_state_handle/442726"]I see that you are running the SPI in blocking mode, why? Wouldn&amp;#39;t it better to let the program handle the logging in the meantime you wait for the SPI transaction to finish? Or maybe you&amp;#39;re only printing data from the SPI transaction?[/quote]
&lt;p&gt;I&amp;#39;m using only SPI, so I think it shouldn&amp;#39;t block something else.&lt;/p&gt;
[quote userid="73165" url="~/f/nordic-q-a/103073/spi-blocked-by-ble-idle_state_handle/442726"]From where do you call&amp;nbsp;DRV_SPI_TransferData() is it from the main loop in&amp;nbsp;getOBDData()?[/quote]
&lt;p&gt;A flag will be set in the timer callback handler. The flag will trigger in the main loop the call from getOBDData()&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void ndts_service_event_handler(ble_ndts_t * p_ndts, ble_ndts_evt_t * p_evt)
{

	if(p_evt-&amp;gt;evt_type == BLE_NDTS_EVT_NOTIFICATION_ENABLED)
	{
		NRF_LOG_INFO(&amp;quot;Notifications Enabled event occurred!!&amp;quot;);
		data_tx_timer_start();
		NRF_LOG_INFO(&amp;quot;DTS Timer started!&amp;quot;);
	}

	else if (p_evt-&amp;gt;evt_type == BLE_NDTS_EVT_NOTIFICATION_DISABLED)
	{
		NRF_LOG_INFO(&amp;quot;Notifications Disabled event occurred!!&amp;quot;);
		data_tx_timer_stop();
		NRF_LOG_INFO(&amp;quot;DTS Timer stopped!&amp;quot;);
	}

	else
	{
	}
}													&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void data_trans_timeout_handler(void * p_context)
{
	if(!obd_req_ready)
		obd_req_ready = true;
}

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Enter main loop.
	for (;;)
	{
			if(obd_req_ready)
			{
				getOBDData();
				obd_req_ready = false;
			}
			idle_state_handle();&lt;/pre&gt;&lt;/p&gt;
[quote userid="73165" url="~/f/nordic-q-a/103073/spi-blocked-by-ble-idle_state_handle/442726"]What is the BLE doing, is it in a connection or advertising? If you increase the interval, does it work fine? At what BLE interval is it fine?&amp;nbsp;[/quote]
&lt;p&gt;At both modes the SPI is slowed down for an intervall 1,2sec&lt;/p&gt;
[quote userid="73165" url="~/f/nordic-q-a/103073/spi-blocked-by-ble-idle_state_handle/442726"]Which SDK and softdevice version are you using?[/quote]
&lt;p&gt;SDK 17.1&lt;/p&gt;
&lt;p&gt;Softdevice is 112&lt;/p&gt;
[quote userid="73165" url="~/f/nordic-q-a/103073/spi-blocked-by-ble-idle_state_handle/442726"]It shouldn&amp;#39;t really be blocked in that function, what it basically does is to call __WFE() and wait for an interrupt to happen,[/quote]
&lt;p&gt;When I comment out NRF_LOG_PROCESS(), then everything works fine. But why is it so? I couldn&amp;#39;t find an answer&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void idle_state_handle(void)
{
	//if(NRF_LOG_PROCESS() == false)
	nrf_pwr_mgmt_run();
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;B&amp;uuml;li&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocked by BLE(idle_state_handle())</title><link>https://devzone.nordicsemi.com/thread/442726?ContentTypeID=1</link><pubDate>Wed, 23 Aug 2023 10:07:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:debda022-e3fb-45b2-8a36-234281ca26e6</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I have some questions,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Which SPI instance are you using?&lt;/li&gt;
&lt;li&gt;I see that you are running the SPI in blocking mode, why? Wouldn&amp;#39;t it better to let the program handle the logging in the meantime you wait for the SPI transaction to finish? Or maybe you&amp;#39;re only printing data from the SPI transaction?&lt;/li&gt;
&lt;li&gt;From where do you call&amp;nbsp;DRV_SPI_TransferData() is it from the main loop in&amp;nbsp;getOBDData()?&lt;/li&gt;
&lt;li&gt;What is the BLE doing, is it in a connection or advertising? If you increase the interval, does it work fine? At what BLE interval is it fine?&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Which SDK and softdevice version are you using?&lt;/li&gt;
&lt;/ol&gt;
[quote user="Buli"]I don&amp;#39;t know why the NRF_LOG_PROCESS() is blocking for 1,2sec. Without to check for logs to transmit it, the data is fired over BLE every 20ms in a notify.[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;It shouldn&amp;#39;t really be blocked in that function, what it basically does is to call __WFE() and wait for an interrupt to happen,&lt;/p&gt;
&lt;p&gt;&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><item><title>RE: SPI blocked by BLE(idle_state_handle())</title><link>https://devzone.nordicsemi.com/thread/442644?ContentTypeID=1</link><pubDate>Tue, 22 Aug 2023 20:44:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4d7381b-b3b4-4e50-9248-8dbda429da21</guid><dc:creator>Buli</dc:creator><description>&lt;p&gt;I found where it&amp;#39;s blocked&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void idle_state_handle(void)
{
	//if(NRF_LOG_PROCESS() == false)
	nrf_pwr_mgmt_run();
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know why the NRF_LOG_PROCESS() is blocking for 1,2sec. Without to check for logs to transmit it, the data is fired over BLE every 20ms in a notify.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>