<?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>Stuck in Timer Interrupt Handler</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/40931/stuck-in-timer-interrupt-handler</link><description>I keep getting stuck in the TIMER1_IRQHandler function. 
 
 When I debug the code, I get to line 20 (exiting interrupt function scope) and then the assembly code hits a nop instruction. This then brings the debugger back up to line 17. 
 
 Why won&amp;#39;t the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 29 Nov 2018 17:03:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/40931/stuck-in-timer-interrupt-handler" /><item><title>RE: Stuck in Timer Interrupt Handler</title><link>https://devzone.nordicsemi.com/thread/159613?ContentTypeID=1</link><pubDate>Thu, 29 Nov 2018 17:03:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6f2015f-d36d-44ca-8c1f-3607014f57d9</guid><dc:creator>mbards</dc:creator><description>&lt;p&gt;This works. Thank you both&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Stuck in Timer Interrupt Handler</title><link>https://devzone.nordicsemi.com/thread/159568?ContentTypeID=1</link><pubDate>Thu, 29 Nov 2018 13:06:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:683c6db2-3394-4e77-a476-26c23162a3a4</guid><dc:creator>Hakon</dc:creator><description>&lt;p&gt;Doing it this way wont work either, because you are not clearing the interupt flag for the TIMER1 event when executing the TIMER1_IRQHandler.&amp;nbsp; Your first attempt was correct except for the fact that you didn&amp;#39;t force write back of EVENTS_COMPARE[0] = 0. You can do that by reading it to a dummy variable like this&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void TIMER1_IRQHandler(void) {
    timer_flag = true;
    TIMER0 -&amp;gt; TASKS_STOP = 1;
	
	
	volatile uint32_t dummy;
	if (NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0] == 1)
	{
		NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0] = 0;

		// Read back event register so ensure we have cleared it before exiting IRQ handler.
		dummy = NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0];
		dummy; // to get rid of set but not used warning
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Hope this answers your question.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Stuck in Timer Interrupt Handler</title><link>https://devzone.nordicsemi.com/thread/159319?ContentTypeID=1</link><pubDate>Tue, 27 Nov 2018 23:56:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e98745b5-2da0-49bd-a37b-dab55dba2961</guid><dc:creator>mbards</dc:creator><description>&lt;p&gt;I have optimization level set to none. For good measure, I added in the keyword. Same problem.&lt;/p&gt;
&lt;p&gt;Thanks for the EVENT_COMPARE heads up.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/** @file
* @brief Example template project.
* @defgroup nrf_templates_example Example Template
*
* NOTE: To get build to work, I right clicked nRF_micro-ecc folder and excluded it from build
*/

#include &amp;quot;main.h&amp;quot;

NRF_TIMER_Type* TIMER0 = (NRF_TIMER_Type*) TIMER0_BASE; // NRF_TIMER_Type has register structure
NRF_TIMER_Type* TIMER1 = (NRF_TIMER_Type*) TIMER1_BASE; // NRF_TIMER_Type has register structure
NRF_GPIOTE_Type* GPIOTE = (NRF_GPIOTE_Type*) GPIOTE_BASE; // NRF_GPIOTE_Type has register structure

volatile bool timer_flag = false;

void TIMER1_IRQHandler(void) {
    timer_flag = true;
    TIMER0 -&amp;gt; TASKS_STOP = 1;
}

void timer_init(hx711_mode_t number_of_pulses) {
    /*
      Setup timer for PWM
    */
    TIMER0 -&amp;gt; MODE &amp;amp;= 0; // Timer mode [DEFAULT]
    TIMER0 -&amp;gt; CC[0] |= 0x10; // Set value in CC[0] to 10
    TIMER0 -&amp;gt; PRESCALER |= 0x4; // Counts at 1 MHz [DEFAULT]
    TIMER0 -&amp;gt; SHORTS |= 1; // On compare[0] event, CLEAR timer
    
    /*
      Setup counter to stop PWM after number_of_pulses
    */
    TIMER1 -&amp;gt; MODE |= 0x2; // Timer set to low power counter mode
    TIMER1 -&amp;gt; CC[0] |= number_of_pulses; // Counter set to mode
    TIMER1 -&amp;gt; INTENSET |= (1 &amp;lt;&amp;lt; 16); // initialise interrupt
    TIMER1 -&amp;gt; SHORTS |= (1 &amp;lt;&amp;lt; 8); // On compare[0] event, STOP timer
    NVIC_SetPriority(TIMER1_IRQn, 0); // Priority 0 (lowest)
    NVIC_ClearPendingIRQ(TIMER1_IRQn);
    NVIC_EnableIRQ(TIMER1_IRQn); // Enables interrupt in NVIC interrupt controllers

    /*
      Use PPI for PWM generation
      Mode: task, Pin: PD_SCK, Polarity: Toggle, Initial pin value: LOW
    */
    GPIOTE-&amp;gt; CONFIG[0] = (0x3 &amp;lt;&amp;lt; 0) |
                          (PD_SCK &amp;lt;&amp;lt; 8) |
                          (0x3 &amp;lt;&amp;lt; 16)|
                          (0 &amp;lt;&amp;lt; 20);    

    NRF_PPI -&amp;gt; CH[0].EEP = (uint32_t) &amp;amp;TIMER0 -&amp;gt; EVENTS_COMPARE[0]; // Connect TIMER0 event to PPI channel 0
    NRF_PPI -&amp;gt; CH[0].TEP = (uint32_t) &amp;amp;GPIOTE-&amp;gt; TASKS_OUT[0]; // Connect toggle task to PPI channel 0
    NRF_PPI -&amp;gt; FORK[0].TEP = (uint32_t) &amp;amp;TIMER1-&amp;gt; TASKS_COUNT; // Connect toggle task to PPI channel 0
    NRF_PPI -&amp;gt; CHEN = (0x1 &amp;lt;&amp;lt; 0); // Enable PPI channel 0
}

/**
 * @brief Function for application main entry.
 */
int main(void)
{
    timer_init(CHANNEL_A_128); // Setup Timer
    TIMER0 -&amp;gt; TASKS_START = 1;

    while(true) {
        if (timer_flag) {
            TIMER0 -&amp;gt; EVENTS_COMPARE[0] = 0;
            nrf_delay_ms(500);
            TIMER1 -&amp;gt; TASKS_CLEAR = 1;
            TIMER0 -&amp;gt; TASKS_START = 1;
            timer_flag = false;
            
        }
    }

}
/** @} */
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Stuck in Timer Interrupt Handler</title><link>https://devzone.nordicsemi.com/thread/159315?ContentTypeID=1</link><pubDate>Tue, 27 Nov 2018 22:44:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:abfb6806-8d29-4c59-9292-6a2bcc1de3bd</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;It wont&amp;#39;t enter the if statement because timer_flag is not declared volatile.&lt;/p&gt;
&lt;p&gt;Without the volatile, the optimizer sees an if that will &lt;em&gt;never&lt;/em&gt; be true.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Note that the EVENTS_COMPARE[0] = 0; statement should not be the last statement in the IRQ handler due to the write buffer. This will cause the interrupt be still pending during the function return - causing tail chaining back into the handler function.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Stuck in Timer Interrupt Handler</title><link>https://devzone.nordicsemi.com/thread/159307?ContentTypeID=1</link><pubDate>Tue, 27 Nov 2018 17:26:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:657bc918-d8b5-474c-bb5d-96998a43ae76</guid><dc:creator>mbards</dc:creator><description>&lt;p&gt;Apologies. Details: SDK v15.2.0. Windows 8.1. Uploading to nRF52 DK.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Stuck in Timer Interrupt Handler</title><link>https://devzone.nordicsemi.com/thread/159263?ContentTypeID=1</link><pubDate>Tue, 27 Nov 2018 14:35:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f55b942-ce16-4947-b897-4b51ada2f00c</guid><dc:creator>Hakon</dc:creator><description>&lt;p&gt;Hey, which sdk version are you using?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>