<?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 Master transfer not completing</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/5420/spi-master-transfer-not-completing</link><description>Hi, 
 I am using the SPI Master 1 to control an EEPROM. I used the spi_example project to help get the code working. It all works fine if the code that initiates the SPI transfer is in main() or simply in a function called by main(). But if I attempt</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 06 Feb 2015 14:13:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/5420/spi-master-transfer-not-completing" /><item><title>RE: SPI Master transfer not completing</title><link>https://devzone.nordicsemi.com/thread/18910?ContentTypeID=1</link><pubDate>Fri, 06 Feb 2015 14:13:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:417bb1a8-3c7f-4fba-b17e-966f0cd93233</guid><dc:creator>Jack</dc:creator><description>&lt;p&gt;Thanks Stefan,&lt;/p&gt;
&lt;p&gt;I have now set it up to that it changes a flag which then executes the SPI transfer in main.&lt;/p&gt;
&lt;p&gt;Thanks to both of you!&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Jack&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Master transfer not completing</title><link>https://devzone.nordicsemi.com/thread/18911?ContentTypeID=1</link><pubDate>Fri, 06 Feb 2015 10:40:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40c72a3e-4902-42af-9578-42d559094ba1</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi Jack&lt;/p&gt;
&lt;p&gt;I believe that John&amp;#39;s comments are valid, that your while loop in the app_timer interrupt handler is blocking the SPI interrupt which has the same priority. Are you still having problems? You could do as John has suggested and set a flag in the app_timer interrupt handler and then check for that flag in main, or you could use the &lt;a href="http://developer.nordicsemi.com/nRF51_SDK/doc/7.2.0/s110/html/a00014.html"&gt;scheduler as documented here&lt;/a&gt;, which basically does the same thing. Simply call &lt;a href="http://developer.nordicsemi.com/nRF51_SDK/doc/7.2.0/s110/html/a00779.html#ga49ec0ad278ece44b5dc56b86ac44489c"&gt;app_sched_event_put()&lt;/a&gt; from your app_timer interrupt handler and then add the scheduler handler in main and the app_sched_execute() in the main loop in order to execute the scheduler handler.&lt;/p&gt;
&lt;p&gt;I then suggest you press the &amp;quot;convert to answer&amp;quot; for the comment that you think is the most adequate answer to your question. Then accept that answer by clicking the &amp;quot;accept&amp;quot; icon below the voting arrows.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Master transfer not completing</title><link>https://devzone.nordicsemi.com/thread/18909?ContentTypeID=1</link><pubDate>Wed, 04 Feb 2015 14:22:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c683e2f4-44e1-4bba-9b6a-dce1ccfa478c</guid><dc:creator>John</dc:creator><description>&lt;p&gt;Hi Jack,
Sorry, I am not really familiar with the scheduler. I have not needed to use it. What I have been doing is setting a flag in the interrupt handler and checking the flag in main. Check the flag in the main loop and if it is set, then do the processing needed. Unless you have done something really odd you should always end back up in main after an interrupt is processed. I haven&amp;#39;t had any processing complex enough to require the scheduler so I&amp;#39;m not a lot of help to you there.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Master transfer not completing</title><link>https://devzone.nordicsemi.com/thread/18908?ContentTypeID=1</link><pubDate>Wed, 04 Feb 2015 12:12:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0ad33d5-996a-484c-9597-048c79f90493</guid><dc:creator>Jack</dc:creator><description>&lt;p&gt;Hi John,&lt;/p&gt;
&lt;p&gt;It seems like you are right and the problem is due to the fact that the SPI interrupt will not be handled until the timeout handler of the application timer will complete. This cannot complete as it is stuck in the while loop.&lt;/p&gt;
&lt;p&gt;I tried changing the SPI priority to APP_IRQ_PRIORITY_HIGH but this cannot be used with the Soft Device API, so that was no good.&lt;/p&gt;
&lt;p&gt;I am using the macro APP_TIMER_INIT. I tried setting the &amp;quot;USE_SCHEDULER&amp;quot; flag to true so that the timeout handlers are called in the main context, however when USE_SCHEDULER to true I am stuck in the ble_debug_assert_handler, as I get an &amp;quot;Invalid Length&amp;quot; error at line 355 of app_timer.c:
static void timeout_handler_exec(timer_node_t * p_timer)
{
uint32_t err_code = m_evt_schedule_func(p_timer-&amp;gt;p_timeout_handler, p_timer-&amp;gt;p_context);
APP_ERROR_CHECK(err_code);
...&lt;/p&gt;
&lt;p&gt;Do you know why this occurs?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Master transfer not completing</title><link>https://devzone.nordicsemi.com/thread/18907?ContentTypeID=1</link><pubDate>Tue, 03 Feb 2015 20:29:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:61373cbd-98ea-470d-899e-485d45a89572</guid><dc:creator>Jack</dc:creator><description>&lt;p&gt;Hi John,&lt;/p&gt;
&lt;p&gt;Many thanks for your quick response! I have added some code to my original question. It couldn&amp;#39;t manage to make all of the code appear like code.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Jack&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Master transfer not completing</title><link>https://devzone.nordicsemi.com/thread/18912?ContentTypeID=1</link><pubDate>Tue, 03 Feb 2015 19:20:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2c897e0f-719f-4fda-9c5d-fa2f6d7100d5</guid><dc:creator>John</dc:creator><description>&lt;p&gt;Without seeing the code when you are running this in the timer callback I&amp;#39;m going to have to make a couple of guesses. First, the code that pulls the chip select high after the SPI transaction is complete is after your while loop waiting for m_transfer_completed to become true? Second, that m_transfer_completed is set to true in a SPI IRQ handler?&lt;/p&gt;
&lt;p&gt;I believe the app timer callbacks execute in an interrupt context which then could be blocking the SPI interrupt from being handled and you would end up in this situation.&lt;/p&gt;
&lt;p&gt;If that is not the case, perhaps you could post your code so we could take a look at it.&lt;/p&gt;
&lt;p&gt;One solution would be to just have your timer callback set a flag that indicates it is time to perform the SPI transaction and still do the transaction in the context of main() when the flag is set. There is also an app_scheduler that could be used but I am not familiar with it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>