<?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>rtc nrf51 SDK example matches COMPARE0 only once</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/8772/rtc-nrf51-sdk-example-matches-compare0-only-once</link><description>In order to learn how to use the RTC0 to handle an event every second, I am debugging the rtc SDK example. 
 Expectation : The rtc example sets the time to check the counter time at 3 seconds. I expect every 3 seconds. the int_type in rtc_handler() will</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 28 Jul 2017 21:34:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/8772/rtc-nrf51-sdk-example-matches-compare0-only-once" /><item><title>RE: rtc nrf51 SDK example matches COMPARE0 only once</title><link>https://devzone.nordicsemi.com/thread/32167?ContentTypeID=1</link><pubDate>Fri, 28 Jul 2017 21:34:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6ceea78-c4f1-45f8-822c-96b94749d298</guid><dc:creator>flodis</dc:creator><description>&lt;p&gt;By constantly adding your interval time to the compare register and have it overflow when at the top, you can have the rtc event trigger eternally with the same exact interval. The timer will also overflow but your new compare value will be ahead all the time. Other compare registers on the rtc timer can be used in the same manner without disturbing each other.&lt;/p&gt;
&lt;p&gt;Before the event nrf library code permanently disables the event requiring it to be enabled again.&lt;/p&gt;
&lt;p&gt;This code fragment is from inside the compare interrupt of the nRF52840:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;//Add a time portion to rtc counter compare	
rtc.p_reg-&amp;gt;CC[0] += COMPARE_COUNTERTIME * 8;

//Re -enable COMPARE0 event &amp;amp; interrupt
nrf_drv_rtc_int_enable(&amp;amp;rtc, NRF_RTC_INT_COMPARE0_MASK);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The nrf_drv_rtc library only offers a &lt;em&gt;nrf_drv_rtc_cc_set&lt;/em&gt; function so direct increment of the CC[0] compare register was used in the test.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: rtc nrf51 SDK example matches COMPARE0 only once</title><link>https://devzone.nordicsemi.com/thread/32166?ContentTypeID=1</link><pubDate>Wed, 18 May 2016 16:37:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2d34b519-3ff7-4eb0-b156-7fda36a220af</guid><dc:creator>zhwzh308</dc:creator><description>&lt;p&gt;in &lt;code&gt;rtc_handler&lt;/code&gt;, after handling &lt;code&gt;COMPARE0&lt;/code&gt; interrupt and clear counter, you may also have to re-enable compare event by calling &lt;code&gt;nrf_drv_rtc_cc_set(&amp;amp;rtc, 0, val, true);&lt;/code&gt;. Otherwise it may not be able to interrupt after the first time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: rtc nrf51 SDK example matches COMPARE0 only once</title><link>https://devzone.nordicsemi.com/thread/32165?ContentTypeID=1</link><pubDate>Mon, 28 Mar 2016 02:08:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:80de91f1-8a34-4707-89d0-6b93be5c328d</guid><dc:creator>Jeong Hyun Seok</dc:creator><description>&lt;p&gt;I was curiout too. thank you. :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: rtc nrf51 SDK example matches COMPARE0 only once</title><link>https://devzone.nordicsemi.com/thread/32164?ContentTypeID=1</link><pubDate>Mon, 24 Aug 2015 09:36:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:578022d0-0a06-41ca-9f94-c6d988951978</guid><dc:creator>i_am_trying</dc:creator><description>&lt;p&gt;great answer.  Thank you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: rtc nrf51 SDK example matches COMPARE0 only once</title><link>https://devzone.nordicsemi.com/thread/32163?ContentTypeID=1</link><pubDate>Fri, 21 Aug 2015 09:48:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3cf3b8ff-f0e4-4a3b-83a2-66102e40fd42</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;The internal event handler of the rtc driver, i.e. the nrf_drv_rtc_int_handler, handles the RTC0 peripheral interupt and then calls the registered event handler of the application. If you look into the nrf_drv_rtc_int_handler, you see that interrupts for any COMPARE[x] events are disabled, while TICK and OVERFLOW interrupts are not disabled. If you avoid disabling the COMPARE[x] interrupts, then the COMPARE[0] interrupt will be recurrent after you clear the RTC0 counter. The following code shows the modified nrf_drv_rtc_int_handler where two lines are commented out to enable recurrent COMPARE[x] interrupt:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;__STATIC_INLINE void nrf_drv_rtc_int_handler(NRF_RTC_Type * p_reg, uint32_t instance_id)
{
		uint32_t i;
		uint32_t int_mask = (uint32_t)NRF_RTC_INT_COMPARE0_MASK;
		nrf_rtc_event_t event = NRF_RTC_EVENT_COMPARE_0;

		for (i = 0; i &amp;lt; RTC_CHANNEL_NUM; i++)
		{
				if (nrf_rtc_int_is_enabled(p_reg,int_mask) &amp;amp;&amp;amp; nrf_rtc_event_pending(p_reg,event))
				{
						//nrf_rtc_event_disable(p_reg,int_mask);
						//nrf_rtc_int_disable(p_reg,int_mask);
						nrf_rtc_event_clear(p_reg,event);
						m_handlers[instance_id]((nrf_drv_rtc_int_type_t)i);
				}
				int_mask &amp;lt;&amp;lt;= 1;
				event    = (nrf_rtc_event_t)((uint32_t)event + sizeof(uint32_t));
		}
		event = NRF_RTC_EVENT_TICK;
		if (nrf_rtc_int_is_enabled(p_reg,NRF_RTC_INT_TICK_MASK) &amp;amp;&amp;amp;
				nrf_rtc_event_pending(p_reg, event))
		{
				nrf_rtc_event_clear(p_reg, event);
				m_handlers[instance_id](NRF_DRV_RTC_INT_TICK);
		}

		event = NRF_RTC_EVENT_OVERFLOW;
		if (nrf_rtc_int_is_enabled(p_reg,NRF_RTC_INT_OVERFLOW_MASK) &amp;amp;&amp;amp;
				nrf_rtc_event_pending(p_reg, event))
		{
				nrf_rtc_event_clear(p_reg,event);
				m_handlers[instance_id](NRF_DRV_RTC_INT_OVERFLOW);
		}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;so with the above change to the nrf_drv_rtc and your proposed code of clearing the counter (as below code), it should work&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
{
		if (int_type == NRF_DRV_RTC_INT_COMPARE0)
		{
				nrf_gpio_pin_toggle(COMPARE_EVENT_OUTPUT);
				nrf_drv_rtc_counter_clear(&amp;amp;rtc);
		}
		else if (int_type == NRF_DRV_RTC_INT_TICK)
		{
				nrf_gpio_pin_toggle(TICK_EVENT_OUTPUT);
		}
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: rtc nrf51 SDK example matches COMPARE0 only once</title><link>https://devzone.nordicsemi.com/thread/32162?ContentTypeID=1</link><pubDate>Tue, 18 Aug 2015 10:59:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00222403-39f8-49f4-8279-600166e2013b</guid><dc:creator>i_am_trying</dc:creator><description>&lt;p&gt;sadly, I already had :-).... my question then is one of usage.  Please forgive this basic question however, I do not know the answer.
What I cannot get working is calling the interrupt handler for COMPARE0 every 3 seconds.  I.e.: it only gets called once.  On further debugging, I thought the following would work.  Why does it not work?  Thank you.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
{
    if (int_type == NRF_DRV_RTC_INT_COMPARE0)
    {
        nrf_gpio_pin_toggle(COMPARE_EVENT_OUTPUT);
        //Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds
        uint32_t err_code = nrf_drv_rtc_cc_set(&amp;amp;rtc,0,COMPARE_COUNTERTIME*RTC0_CONFIG_FREQUENCY,true);
        APP_ERROR_CHECK(err_code);
        //Power on RTC instance
        nrf_drv_rtc_disable(&amp;amp;rtc);
        nrf_drv_rtc_enable(&amp;amp;rtc);
    }
    else if (int_type == NRF_DRV_RTC_INT_TICK)
    {
        nrf_gpio_pin_toggle(TICK_EVENT_OUTPUT);
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: rtc nrf51 SDK example matches COMPARE0 only once</title><link>https://devzone.nordicsemi.com/thread/32161?ContentTypeID=1</link><pubDate>Tue, 18 Aug 2015 05:19:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98b06fd1-64be-49c6-8366-75db5c34166c</guid><dc:creator>Krzysztof Chruscinski</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;please check the documentation of this example: &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk51.v9.0.0/rtc_example.html?cp=4_1_0_4_6_17"&gt;http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk51.v9.0.0/rtc_example.html?cp=4_1_0_4_6_17&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&lt;code&gt;LED 1 is used to show the 8 Hz tick.
LED 2 is used to show the COMPARE0 event.
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: rtc nrf51 SDK example matches COMPARE0 only once</title><link>https://devzone.nordicsemi.com/thread/32160?ContentTypeID=1</link><pubDate>Tue, 18 Aug 2015 01:48:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:48d41bcb-6455-466b-878f-187712b5a63c</guid><dc:creator>i_am_trying</dc:creator><description>&lt;p&gt;Thank you for your answer.  I &lt;em&gt;think&lt;/em&gt; I do... it seems i reset the count, but the compare0 event doesn&amp;#39;t recur?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/** @brief: Function for handling the RTC0 interrupts.
 * Triggered on TICK and COMPARE0 match.
 */
static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
{
    if (int_type == NRF_DRV_RTC_INT_COMPARE0)
    {
        nrf_gpio_pin_toggle(COMPARE_EVENT_OUTPUT);
        nrf_drv_rtc_counter_clear(&amp;amp;rtc);
    }
    else if (int_type == NRF_DRV_RTC_INT_TICK)
    {
        nrf_gpio_pin_toggle(TICK_EVENT_OUTPUT);
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: rtc nrf51 SDK example matches COMPARE0 only once</title><link>https://devzone.nordicsemi.com/thread/32159?ContentTypeID=1</link><pubDate>Mon, 17 Aug 2015 23:37:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0869f23e-9a01-4094-9b88-24ad808470b5</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Are you resetting the timer when you get the compare? If not it will just count all the way to the maximum count, then wrap around and start at zero and only when it gets to the same count again will you get the next COMPARE0. If you have the timer running fast that&amp;#39;s 512 seconds, if you have it running as slowly as possible, that&amp;#39;s 24 days before you&amp;#39;ll see the next interrupt.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>