<?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>add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/8337/add-timer-in-ble_app_uart</link><description>I am working on adding a timer in the ble_app_uart sample, aiming on disconnect with device which doesn&amp;#39;t send any data in specific time, such as 5 seconds. 
 Now I have found an example &amp;quot;timer_pca10028&amp;quot;, and try to insert useful part into my application</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 16 Dec 2015 09:11:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/8337/add-timer-in-ble_app_uart" /><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30195?ContentTypeID=1</link><pubDate>Wed, 16 Dec 2015 09:11:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41cc2c9b-5775-4305-b717-659d365b8d97</guid><dc:creator>Primož Kralj</dc:creator><description>&lt;p&gt;yiran, could you post a working example now? I have the same problem as you did and I can&amp;#39;t make sense of this code-mixing.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30194?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2015 07:57:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a624bf3f-db9b-4904-a957-47c69948d742</guid><dc:creator>yiran</dc:creator><description>&lt;p&gt;Thank you! This problem has bored me several days&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30193?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2015 07:54:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ea5eacb-24b1-43b0-8f70-b96ed6075573</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;you need to fix both, setpriority and also the compare event rest that you found.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30192?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2015 07:52:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd8f1899-98a5-40d3-a98f-6548c5a491d5</guid><dc:creator>yiran</dc:creator><description>&lt;p&gt;Yes, SetPriority also works , thank you very much!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30191?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2015 07:52:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4aea9478-f6ed-42ce-b9b5-2f2c59d32774</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;oh yes, that too.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30190?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2015 07:47:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00b9ee72-a7a3-42d0-995e-b0f974ad95de</guid><dc:creator>yiran</dc:creator><description>&lt;p&gt;I find the cause...I should execute &lt;code&gt;NRF_TIMER2-&amp;gt;EVENTS_COMPARE[0] = 0;&lt;/code&gt; immediately when the time is up....&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30189?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2015 07:46:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7722059-cc62-47c7-8b51-6b1c0da645cb</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;you forgot to set the priority of Timer2 Irq handler&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_TIMER2-&amp;gt;INTENSET = (TIMER_INTENSET_COMPARE0_Enabled &amp;lt;&amp;lt; 
TIMER_INTENSET_COMPARE0_Pos);
NVIC_SetPriority(TIMER2_IRQn, NRF_APP_PRIORITY_LOW);
NVIC_EnableIRQ(TIMER2_IRQn);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30188?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2015 07:38:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:452efbdb-bb88-469d-8666-369d53463d82</guid><dc:creator>yiran</dc:creator><description>&lt;p&gt;thank you for helping me so much ~my current problem is, before the connection is established, everything goes well, however when I start a timer when I connect to the dongle, and when the time is up, connection is lost before I terminate manually, and dongle doesn&amp;#39;t go back to advertising mode.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30187?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2015 07:32:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a71b3b69-fe1d-4ad0-b7a1-cd322d2be440</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;just before the for loop, i did not test connecting to the device. I was just checking if the device logs are coming to the terminal or not. I will see now what happens when We try to connect to it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30186?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2015 07:20:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4b99ae8-4d74-4825-8a73-5c1a3071d1f3</guid><dc:creator>yiran</dc:creator><description>&lt;p&gt;where did you add &amp;#39;time is up&amp;#39;? In my side application advertises well at the beginning, and it only crush after a little while when I connect to it. I start the timer when I connected to the dongle, it my crush when time is up.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30184?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2015 06:50:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f984fbd-3d4d-44d5-a51a-61e7b76ee8c2</guid><dc:creator>yiran</dc:creator><description>&lt;p&gt;No, it is also stucked. I put a printf command in main&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;for (;;)
{
		printf(&amp;quot;b&amp;quot;);
    power_manage();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It continued outputting &amp;#39;b&amp;#39; before the device is connected.My current complete code is here &lt;a href="https://github.com/darouwan/uart/blob/master/main.c"&gt;github.com/.../main.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30185?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2015 05:56:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:87ffc532-111d-477f-80dc-66c2d46989fa</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Is the printf working from main? if yes, there seems to be some problem with your UART configuration , disable everything and see if the printfs are working from the main context.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30183?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2015 01:11:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c272294-a72b-4413-96e6-2e2281056a44</guid><dc:creator>yiran</dc:creator><description>&lt;p&gt;it stucks in the place &lt;code&gt;printf(&amp;quot;atime\n&amp;quot;);&lt;/code&gt;, where it just print out one letter &amp;#39;a&amp;#39;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30179?ContentTypeID=1</link><pubDate>Mon, 27 Jul 2015 09:57:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e5f360a-e4f5-47d8-a799-62f65db13f89</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;sounds like the UART is stuck, comment the printfs out and see if it continues. UART log are too slow to be used in interrupt handlers.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30178?ContentTypeID=1</link><pubDate>Mon, 27 Jul 2015 09:32:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73e66f1f-a8ec-430c-90d1-03cc1a58c9dd</guid><dc:creator>yiran</dc:creator><description>&lt;p&gt;Fine. Now I tried to integrate the timer to my current work. I start the timer&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;case BLE_GAP_EVT_CONNECTED:
					//nrf_drv_timer_enable(&amp;amp;TIMER_LED);
        err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
        APP_ERROR_CHECK(err_code);
        m_conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;break;
					printf(&amp;quot;%s&amp;quot;,&amp;quot;Device Connected:&amp;quot;);
					
					NRF_TIMER2-&amp;gt;TASKS_START = 1;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;but  TIMER2_IRQHandler is blocked when it is called....&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void TIMER2_IRQHandler(void)
{
	//printf(&amp;quot;atime\n&amp;quot;);
	if (NRF_TIMER2-&amp;gt;EVENTS_COMPARE[0] != 0 )
		printf(&amp;quot;time is up&amp;quot;);
		if ( !is_received_data)
			{
				printf(&amp;quot;no data&amp;quot;);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the terminal it prints out &amp;#39;t&amp;#39; as the begining of &amp;quot;time is up&amp;quot;, then stacked here. LED indicates it is still in connected mode, but in UART app I cannot disconnect from it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30177?ContentTypeID=1</link><pubDate>Mon, 27 Jul 2015 08:03:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ecc5a1a0-aee5-4c7b-9f8a-bca3d8b35ee5</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;There is only 16 bit max supported by TIMER2
And select the prescaler to be 11. Then put 0X9896 in 16 bit CC register which will fit.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30176?ContentTypeID=1</link><pubDate>Mon, 27 Jul 2015 07:50:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c55fef28-a786-49fd-b43f-8b46f3b12c5c</guid><dc:creator>yiran</dc:creator><description>&lt;p&gt;I found another problem...No matter how I set the NRF_TIMER2-&amp;gt;CC[0], the actual interval would not change unless I change the value of PRESCALER. Now I set &lt;code&gt;NRF_TIMER2-&amp;gt;PRESCALER = 4;&lt;/code&gt;, &lt;code&gt;NRF_TIMER2-&amp;gt;CC[0] = 5000*1000; NRF_TIMER2-&amp;gt;BITMODE = TIMER_BITMODE_BITMODE_32Bit;&lt;/code&gt;, the actual interval is 100ms approximately, while it should be 5 seconds.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30182?ContentTypeID=1</link><pubDate>Mon, 27 Jul 2015 06:16:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:971da789-f61e-4407-b619-af47852b8538</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;if you want an event for 5 seconds, then you can even choose PRESCALER to be 4.
Lower value of prescaler is for applications that need events in few milliseconds, precision gets very important then.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30181?ContentTypeID=1</link><pubDate>Mon, 27 Jul 2015 02:09:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:961af773-da5a-4ded-9a3f-d5cff8a10c44</guid><dc:creator>yiran</dc:creator><description>&lt;p&gt;I have got one here &lt;a href="https://devzone.nordicsemi.com/question/4142/some-question-of-nrf51822-timer/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt; ~thx&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30180?ContentTypeID=1</link><pubDate>Mon, 27 Jul 2015 01:43:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27b595e2-6c91-4e45-977e-e3b2357b8cbc</guid><dc:creator>yiran</dc:creator><description>&lt;p&gt;So I need to customize a prescaler for TIMER 1 or 2?
Where can I get a sample code of it？ I tried to find one but most of them are discrete code...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30175?ContentTypeID=1</link><pubDate>Fri, 24 Jul 2015 08:25:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ba68883-3f54-4612-8897-4adf643a0f75</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;YES, apps can use TIMER1 and TIMER2 if softdevice is used (use can use timer0 if using timeslots, but dont  get yourself confused with that) change the prescaler to something like 4, its a 16-bit timer, 10 seconds does not fit in CC with prescaler 0.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30174?ContentTypeID=1</link><pubDate>Fri, 24 Jul 2015 07:50:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0c649515-a7f8-4a9d-8e59-25d34cb8c728</guid><dc:creator>yiran</dc:creator><description>&lt;p&gt;Thank you very much. So any code relates to TIMER0  should be TIMER1?
I have modified my code as you suggested, and set timer as 10000ms. Then program execute to &lt;code&gt;case NRF_TIMER_EVENT_COMPARE1&lt;/code&gt; immediately after the phone connect to 51822, rather than waiting 10 seconds.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30173?ContentTypeID=1</link><pubDate>Fri, 24 Jul 2015 06:58:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e9df630a-f3f4-46ee-a506-7255d0a835f2</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;OK, found the problem,
you cannot use TIMER0 as it is reserved by softdevice. Please read the softdevice reference manual.
In old softdevices this would have hardfaulted, but since the newer version does not write anything to UICR.CLENR0, the hardware protection is not enabled. So it is upto users to understand which peripherals are used by softdevice and not touch them.
In your code , change&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(1);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30172?ContentTypeID=1</link><pubDate>Fri, 24 Jul 2015 06:39:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1cd16bff-291e-4399-96f2-9862e9d1ca22</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;I will check your code later, common mistake when starting app_timer, have you increased APP_TIMER_MAX_TIMERS ? this needs to be done to allocate buffers for it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: add timer in ble_app_uart</title><link>https://devzone.nordicsemi.com/thread/30171?ContentTypeID=1</link><pubDate>Fri, 24 Jul 2015 02:14:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7951f272-d483-4b39-bd0f-7d4374569454</guid><dc:creator>yiran</dc:creator><description>&lt;p&gt;Thanks for your help. After fixing the problem you mentioned above, my application can start properly. However when I enable &lt;code&gt;nrf_drv_timer_enable(&amp;amp;TIMER_LED);&lt;/code&gt;, mobile phone still disconnect once it connects to the 51822.  My whole code is here &lt;a href="https://github.com/darouwan/uart/blob/master/main.c"&gt;github.com/.../main.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>