<?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>main thread no longer running</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10519/main-thread-no-longer-running</link><description>Hi,Nordic and all great guys, 
 I am a new developer for NRF51822, and quite unfortunately ,we have a complex application to develop. We need to run code in the main thread ,and we don`t even find examples about it in the SDK(there only have sd_app_evt_wait</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 01 Dec 2015 03:52:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10519/main-thread-no-longer-running" /><item><title>RE: main thread no longer running</title><link>https://devzone.nordicsemi.com/thread/39123?ContentTypeID=1</link><pubDate>Tue, 01 Dec 2015 03:52:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13cf2c28-d47c-4611-9b7c-5b0ae3ebdb88</guid><dc:creator>hunterliuyi</dc:creator><description>&lt;p&gt;Maybe the BLE interrupt which also calls UART prints has changed the value of TXDRDY, and disrupt the proccess of TXDRDY in the main thread. whatever ,since we confirmed the main thread is not dead, so we can solve this problem by simply adding a timeout for the __uart_put function. Now we moved to other problems of our application. Thanks a lot.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: main thread no longer running</title><link>https://devzone.nordicsemi.com/thread/39125?ContentTypeID=1</link><pubDate>Mon, 30 Nov 2015 09:37:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d449a4af-4ee6-4cba-822f-16b735deafd1</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;The &lt;code&gt;TXDRDY&lt;/code&gt; flag is set by hardware, but must be cleared by software. Thus you should initialize it to zero when you configure UART (I assume you have done that?), and always set it to zero after the while loop, so that it is zero before you send the next byte (as you do in the code in your comment).&lt;/p&gt;
&lt;p&gt;Are you accessing the UART registers other places in your code, some with higher priorities? You could get problems in that case, if &lt;code&gt;TXDRDY&lt;/code&gt; is cleared by one thread, before another that is waiting for it to be set. This is discussed in &lt;a href="https://devzone.nordicsemi.com/question/15682/app-stucks-in-simple_uartc/"&gt;this thread&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You could consider using the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk51.v10.0.0/group__nrf__drv__uart.html"&gt;driver&lt;/a&gt; or the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk51.v10.0.0/group__app__uart.html"&gt;app_uart library&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: main thread no longer running</title><link>https://devzone.nordicsemi.com/thread/39124?ContentTypeID=1</link><pubDate>Sat, 28 Nov 2015 08:22:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:17622fb5-fd06-4411-a1d1-c422b8e7d80d</guid><dc:creator>hunterliuyi</dc:creator><description>&lt;p&gt;HI,Einar Thorsrud ,
Thanks for you help , after using debugger,I think I found where the problem is ,it is all about NRF_UART0-&amp;gt;EVENTS_TXDRDY, we have code section below:
static void __uart_put(H_U8 ch)
{
NRF_UART0-&amp;gt;TXD = (H_U16)ch;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;while (NRF_UART0-&amp;gt;EVENTS_TXDRDY != 1)
{
	// Wait for TXD data to be sent.
	//TEST
	nrf_gpio_pin_set(ALARM_ENABLE_PORT);
	
}
nrf_gpio_pin_clear(ALARM_ENABLE_PORT);
//hs_tools_op()-&amp;gt;_delay_ms(1);
NRF_UART0-&amp;gt;EVENTS_TXDRDY = 0;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;If there is no interrupt or interrupt did not happened just at UART print（NOTE THAT in the interrupt handler ,there are also prints）, this section worked normally, otherwise, the value of NRF_UART0-&amp;gt;EVENTS_TXDRDY would stay at 0, then it is a dead loop.  I found the cause of the problem, but I don`t know why this will happen, why the  NRF_UART0-&amp;gt;EVENTS_TXDRDY have wrong value,and after searching this forum,I know I can not change this value manually ,it is set by hardware. Can you help me with that? Thanks again for your help.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: main thread no longer running</title><link>https://devzone.nordicsemi.com/thread/39122?ContentTypeID=1</link><pubDate>Fri, 27 Nov 2015 10:08:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4b315b2-f0cb-42e9-877d-cb3328101852</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;As long as the CPU is active (which it is as your interrupt handlers are running) the main thread will also do &lt;em&gt;something&lt;/em&gt;, given that it has time to run. Without knowing anything about your code I would assume that one of the following things are happening:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Your main thread is in some unexpected state. (E.g. it could be in a eternal loop in an error handler such as the &lt;code&gt;app_error_handler()&lt;/code&gt;, defined in components\libraries\util\app_error.c after an error code was used as input to &lt;code&gt;APP_ERROR_CHECK()&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;One or more interrupt handlers are running constantly, giving no time for lower priority threads to run.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Have you tried using a debugger to see what your code is doing when it is in the bad state?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: main thread no longer running</title><link>https://devzone.nordicsemi.com/thread/39121?ContentTypeID=1</link><pubDate>Fri, 27 Nov 2015 08:40:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c31c1ac-612c-41de-82e1-49a323e04722</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I took the liberty to edit the formatting of your question as the indentation in front of each paragraph caused most of the question to be presented in verbatim with no soft line breaks etc. (This is because all posts on this forum are parsed as &lt;a href="https://en.wikipedia.org/wiki/Markdown"&gt;Markdown&lt;/a&gt;).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>