<?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 blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/7864/spi-blocking-or-nonblocking</link><description>Just to make sure: Will The spi_master_send_recv return when it is done writing and reading, or do you have to have some event wait functionality listening to SPI_MASTER_EVT_TRANSFER_COMPLETED ? I guess it is blocking because you have an output buffer</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 02 Mar 2016 13:26:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/7864/spi-blocking-or-nonblocking" /><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28054?ContentTypeID=1</link><pubDate>Wed, 02 Mar 2016 13:26:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81e96df7-8b64-42b2-8d41-d4add2d98664</guid><dc:creator>Emil</dc:creator><description>&lt;p&gt;There&amp;#39;s nothing that indicates that it wouldn&amp;#39;t. The fact is that it&amp;#39;s event based, and i interpret this as a certain &amp;quot;return&amp;quot; of the function signaling the COMPLETED event.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28053?ContentTypeID=1</link><pubDate>Wed, 02 Mar 2016 13:23:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8a1565e-4c6d-4dbe-bb0e-b4016ee2df54</guid><dc:creator>wim</dc:creator><description>&lt;p&gt;i am still using SDK7.2.0, there I only have SPI_MASTER_EVT_TRANSFER_STARTED and SPI_MASTER_EVT_TRANSFER_COMPLETED in the spi_master_evt_type_t enumeration, so I guess I am ok. It should always return, right?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28052?ContentTypeID=1</link><pubDate>Wed, 02 Mar 2016 13:21:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e310d11a-a4d2-4fa1-88da-75d84523de5f</guid><dc:creator>Emil</dc:creator><description>&lt;p&gt;The SDK has changed, but it should always return. Also you might want to handle   SPI_MASTER_EVT_TRANSFER_ABORTED.&lt;/p&gt;
&lt;p&gt;I changed from this SPI library to an SPI library that is simpler and doesn&amp;#39;t use events. This is much tighter and faster and you don&amp;#39;t need to have this logic:  &lt;a href="https://devzone.nordicsemi.com/question/57483/spi-optimization/?answer=57818#post-id-57818"&gt;devzone.nordicsemi.com/.../&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28051?ContentTypeID=1</link><pubDate>Wed, 02 Mar 2016 13:08:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00bd9f51-651b-4bb8-a482-8eddc69e8722</guid><dc:creator>wim</dc:creator><description>&lt;p&gt;question: I also use a blocking mechanism with a flag. Is it guaranteed to get a SPI_MASTER_EVT_TRANSFER_COMPLETED? or do I need to cover other cases?
Or do I  need to put a safety timeout to exit my while loop  if the SPI access takes to much time?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28050?ContentTypeID=1</link><pubDate>Tue, 21 Jul 2015 13:13:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bed7e62e-cb85-4948-91b9-ca00dd2cb171</guid><dc:creator>Emil</dc:creator><description>&lt;p&gt;Thank you! That cleared everything up!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28049?ContentTypeID=1</link><pubDate>Tue, 21 Jul 2015 12:47:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5e74a76-cb38-401c-8fd7-235e9a7c1b43</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;it calls _WFE, so it falls through only after. Read the discussion regarding this.
&lt;a href="https://devzone.nordicsemi.com/question/1555/how-do-you-put-the-nrf51822-chip-to-sleep/#reply-1589"&gt;devzone.nordicsemi.com/.../&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28048?ContentTypeID=1</link><pubDate>Tue, 21 Jul 2015 12:31:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e81cdb97-23c0-478d-bc16-60cc0b961287</guid><dc:creator>Emil</dc:creator><description>&lt;p&gt;Yeah, I need it in top and bottom. But another important thing is to know for certain that sd_app_evt_wait falls through AFTER the handler is called, if it falls through before, it will wait forever for next transfer (?)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28047?ContentTypeID=1</link><pubDate>Tue, 21 Jul 2015 12:30:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15ce5c51-5b99-46c1-b738-1af39c4f151d</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Damn, i missed that.
you need that flag else you cannot tell which event occured. Sorry for that&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;while (_isTransferring)
{
  uint32_t err_code = sd_app_evt_wait();
  APP_ERROR_CHECK(err_code);
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28046?ContentTypeID=1</link><pubDate>Tue, 21 Jul 2015 12:27:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc4baec8-ddeb-49bb-b7cc-21a34e7b04d4</guid><dc:creator>Emil</dc:creator><description>&lt;p&gt;Thanks! But that will wait on any event, what if there are more events in my application? Is there a way to check which event occured? Will the code in the handler get executed before sd_app_evt_wait falls through or after?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28045?ContentTypeID=1</link><pubDate>Tue, 21 Jul 2015 12:22:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc5f8ebf-cb22-41fa-b3f5-f67563b2bb80</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;It is not sleep, instead the CPU is busy waiting, you can use sd_app_evt_wait() instead, renive _isTransfering completely.&lt;/p&gt;
&lt;p&gt;while (_isTransferring)
nrf_delay_us(1);&lt;/p&gt;
&lt;p&gt;change to&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t err_code = sd_app_evt_wait();
APP_ERROR_CHECK(err_code);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28044?ContentTypeID=1</link><pubDate>Tue, 21 Jul 2015 12:12:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c03f79b9-f7c6-4ba9-810c-f9ac71fd3bfa</guid><dc:creator>Emil</dc:creator><description>&lt;p&gt;I just wondered what the best way to block a function while waiting for something. Is it still sleeping every µs and poll the volatile bool?&lt;/p&gt;
&lt;p&gt;I do this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static inline void SpiTransfer(uint8_t * const txBuffer, const uint16_t txBufferLength,
	uint8_t * const rxBuffer, const uint16_t rxBufferLength)
{	
	while (_isTransferring)
		nrf_delay_us(1);

	_count = rxBufferLength;

	_isTransferring = true;
	uint32_t result = spi_master_send_recv(SPI_MASTER_HW, txBuffer, txBufferLength, rxBuffer,     rxBufferLength);
	APP_ERROR_CHECK(result);

	while (_isTransferring)
		nrf_delay_us(1);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;pre&gt;&lt;code&gt;static void spi_master_event_handler(spi_master_evt_t spi_master_evt)
{
	switch (spi_master_evt.evt_type)
	{
	case SPI_MASTER_EVT_TRANSFER_COMPLETED:

		_receivedCount = spi_master_evt.data_count;

		if (_receivedCount &amp;gt;= _count)
		{
			_count = 0;
			_isTransferring = false;
		}

		break;

	default:
		// No implementation needed.
		break;
	}
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28043?ContentTypeID=1</link><pubDate>Tue, 21 Jul 2015 12:10:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ccfb00b-cc38-459e-a727-5c3b364388b6</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Emil, could you please update this thread with latest info, if this answer helped you then please click the ✓ to the left of the answer so that others can come and look here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28039?ContentTypeID=1</link><pubDate>Fri, 03 Jul 2015 14:59:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:184f0b9b-8f68-4459-b1a8-5203561b27c0</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;I think checking for a flag and sleeping if not flag not enabled is not dirty. It takes just few ARM instructions to do it. it makes the logic simple too and this method does not effect power consumption. There is scheduler but that also does indirect signalling only if main is polling .&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28042?ContentTypeID=1</link><pubDate>Wed, 01 Jul 2015 08:37:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5ecb752-e11f-466f-a67e-568067356bbe</guid><dc:creator>Emil</dc:creator><description>&lt;p&gt;Thanks!&lt;/p&gt;
&lt;p&gt;The callback function is in place, and it is waiting. I was thinking more of nrf_delay_us as &amp;quot;sleep&amp;quot;. I feel that it&amp;#39;s &amp;quot;dirty&amp;quot; to sleep and check a volatile bool if it&amp;#39;s done. Is there some Event framework I can use for signaling it from the SPI callback ? Like:&lt;/p&gt;
&lt;p&gt;wait_for_event(_eventObject, timeout);&lt;/p&gt;
&lt;p&gt;.....&lt;/p&gt;
&lt;p&gt;Handler:&lt;/p&gt;
&lt;p&gt;signal_event(_eventObject);&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28041?ContentTypeID=1</link><pubDate>Tue, 30 Jun 2015 11:45:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d26f32c-b75f-4a0e-b78c-c960e98df846</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;In the event callback function that you register using &lt;code&gt;spi_master_evt_handler_reg&lt;/code&gt; you can enable a flag (bool) when you get &lt;code&gt;SPI_MASTER_EVT_TRANSFER_COMPLETED&lt;/code&gt;.
You can wait for this flag to be set in your main context. You can even sleep as the event handler callback is called in interrupt context so the chip will wake up after completion. Make sure you use WFE instead of WFI&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28040?ContentTypeID=1</link><pubDate>Tue, 30 Jun 2015 10:14:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:70cea182-ce60-4d2a-8916-9b13f395a32c</guid><dc:creator>Emil</dc:creator><description>&lt;p&gt;Thanks!!! I need to make this a blocking function. What is the best way to block it? In windows you have events that you wait for and signal. Should I use IRQs in this context? Or a sleep + a volatile bool (not preferred) ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI blocking or nonblocking?</title><link>https://devzone.nordicsemi.com/thread/28038?ContentTypeID=1</link><pubDate>Tue, 30 Jun 2015 10:12:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:91562581-662d-43c8-9d26-5d7dae9d3293</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;The spi_master_send_recv function will only transmit first bytes to start the transaction and then return. This is non blocking.&lt;/p&gt;
&lt;p&gt;After the bytes are received for the transmitted first bytes then the rest of the transaction happens in the interrupt context. When the interrupt context has started for the first time you get a SPI_MASTER_EVT_TRANSFER_STARTED event and when the whole transaction is finished then you get SPI_MASTER_EVT_TRANSFER_COMPLETED event.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>