<?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>Using app timer in sdk13</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/21517/using-app-timer-in-sdk13</link><description>Hi all, 
 I am using a nRF52832 with SD S132 V4.0.2 ion SDK13. 
 My application currently uses TWI, SPI and BLE and also 1 wire (which is based on delays). Everything works fine. The 1 wire is used before the SD is enabled and after it is done it will</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 21 Apr 2017 10:19:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/21517/using-app-timer-in-sdk13" /><item><title>RE: Using app timer in sdk13</title><link>https://devzone.nordicsemi.com/thread/84461?ContentTypeID=1</link><pubDate>Fri, 21 Apr 2017 10:19:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94af8466-13a4-4391-bb90-2c79d7957a64</guid><dc:creator>Tostikoning</dc:creator><description>&lt;p&gt;With help from @Sigurd I managed to find the problem. It was a problem all programmers will experience in their careers and one of my finest &amp;quot;d&amp;#39;oh&amp;quot; moments.&lt;/p&gt;
&lt;p&gt;You should create the timer with the following function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ret_code_t app_timer_create(app_timer_id_t const *      p_timer_id,
                            app_timer_mode_t            mode,
                            app_timer_timeout_handler_t timeout_handler)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And start the timer with the following function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ret_code_t app_timer_start(app_timer_id_t timer_id, uint32_t timeout_ticks, void * p_context)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice the difference in the first argument. The init requires an address of your timer id, and when you start a timer it only needs a copy. So when I changed my call from:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;err_code = app_timer_start(&amp;amp;m_pt100_timer_id, APP_TIMER_TICKS(1000), NULL);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;err_code = app_timer_start(m_pt100_timer_id, APP_TIMER_TICKS(1000), NULL);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It worked like a charm! Oh and btw, do not try to debug after the softdevice was enabled, it can get quirky.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using app timer in sdk13</title><link>https://devzone.nordicsemi.com/thread/84467?ContentTypeID=1</link><pubDate>Fri, 21 Apr 2017 09:42:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c146271-f38e-4d83-8005-c9d8310e01a1</guid><dc:creator>Tostikoning</dc:creator><description>&lt;p&gt;Okay, this helped me. Not in an expected way. I missed a reset. i put a breakpoint in the measurement start function. No error code is returned but i can see it resetting. I&amp;#39;ll try to investigate this further.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;EDIT 1:&lt;/strong&gt;
Strange things are happening. I also placed a breakpoint in the RTC1_IRQHandler in app_timer.c . Another breakpoint is in measurement_start() just after&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;err_code = app_timer_start(m_pt100_timer_id, APP_TIMER_TICKS(5000), NULL);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;btw app_timer_start does not like to get a address of the timer id, but would rather like a copy.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ret_code_t app_timer_start(app_timer_id_t timer_id, uint32_t timeout_ticks, void * p_context);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This change allows me to enter the RTC1_IRQHandler() however I still do not enter my own handler and it still resets.&lt;/p&gt;
&lt;p&gt;Also it only enters the RTC1_IRQhandler if I wait a a few seconds, if I just continue it resets without entering the RTC1_IRQHandler(). I will continue..&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;EDIT 2:&lt;/strong&gt;
If I change the timeout value from 5s to 100ms it fires RTC1_IRQHandler a few times before restting. Is something else resetting my program? Further investigation..
&lt;strong&gt;EDIT 3:&lt;/strong&gt; I fixed it. I will update the question with an answer. The reset was probably induced by adding the breakpoints, after the SD was enabled.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using app timer in sdk13</title><link>https://devzone.nordicsemi.com/thread/84463?ContentTypeID=1</link><pubDate>Fri, 21 Apr 2017 09:39:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e50242c2-f1cf-4104-8ec5-da5c4d402485</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;What does &lt;code&gt;app_timer_start(m_pt100_timer_id, APP_TIMER_TICKS(100), NULL);&lt;/code&gt; return?
Try do send the err_code to the error handler:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void measurement_start(void)
{
    ret_code_t err_code;
    /* Start timer */
    err_code = app_timer_start(&amp;amp;m_pt100_timer_id, MEAS_TIMER_INTERVAL, NULL);
    APP_ERROR_CHECK(err_code);

    /* Clear previous measurement in flash */

}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using app timer in sdk13</title><link>https://devzone.nordicsemi.com/thread/84466?ContentTypeID=1</link><pubDate>Fri, 21 Apr 2017 09:34:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04c1626d-b8dc-4def-a2b8-ab7a34483b55</guid><dc:creator>Tostikoning</dc:creator><description>&lt;p&gt;Yeah, I mean I can connect to my application and read all my data. I use a LED blinking from main, just to detect if no error has occured or if it is stuck. It keeps blinking. A different LED is toggled in the handler, which does not blink, even when I set it to 1s instead of 100ms. In the debugger I do not enter the handler. Should I use the wait for event functions? Are those mandatory for the intterupt to fire? Also I do not use the scheduler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using app timer in sdk13</title><link>https://devzone.nordicsemi.com/thread/84465?ContentTypeID=1</link><pubDate>Fri, 21 Apr 2017 09:25:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b464279a-680a-4c58-94b3-a9fd7c131202</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;The rest of the application is working fine? The only problem is that the timeout is not fired?&lt;/p&gt;
&lt;p&gt;Have you tried debugging the application? Are you running into the error handler somewhere? See &lt;a href="https://devzone.nordicsemi.com/question/60125/my-device-is-freezing-and-restarting/"&gt;this post&lt;/a&gt; on how to debug.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using app timer in sdk13</title><link>https://devzone.nordicsemi.com/thread/84464?ContentTypeID=1</link><pubDate>Fri, 21 Apr 2017 09:20:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1517487c-266d-487d-b932-8b9ea1b43de7</guid><dc:creator>Tostikoning</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;I tried the change you suggested in A4. Unfortunately it did not work. The following snippet is from the sdk_config.h:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    // &amp;lt;e&amp;gt; APP_TIMER_ENABLED - app_timer - Application timer functionality
//==========================================================
#ifndef APP_TIMER_ENABLED
#define APP_TIMER_ENABLED 1
#endif
#if  APP_TIMER_ENABLED
// &amp;lt;o&amp;gt; APP_TIMER_CONFIG_RTC_FREQUENCY  - Configure RTC prescaler.

// &amp;lt;0=&amp;gt; 32768 Hz
// &amp;lt;1=&amp;gt; 16384 Hz
// &amp;lt;3=&amp;gt; 8192 Hz
// &amp;lt;7=&amp;gt; 4096 Hz
// &amp;lt;15=&amp;gt; 2048 Hz
// &amp;lt;31=&amp;gt; 1024 Hz

#ifndef APP_TIMER_CONFIG_RTC_FREQUENCY
#define APP_TIMER_CONFIG_RTC_FREQUENCY 0
#endif

// &amp;lt;o&amp;gt; APP_TIMER_CONFIG_IRQ_PRIORITY  - Interrupt priority


// &amp;lt;i&amp;gt; Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
// &amp;lt;0=&amp;gt; 0 (highest)
// &amp;lt;1=&amp;gt; 1
// &amp;lt;2=&amp;gt; 2
// &amp;lt;3=&amp;gt; 3
// &amp;lt;4=&amp;gt; 4
// &amp;lt;5=&amp;gt; 5
// &amp;lt;6=&amp;gt; 6
// &amp;lt;7=&amp;gt; 7

#ifndef APP_TIMER_CONFIG_IRQ_PRIORITY
#define APP_TIMER_CONFIG_IRQ_PRIORITY 7
#endif

// &amp;lt;o&amp;gt; APP_TIMER_CONFIG_OP_QUEUE_SIZE - Capacity of timer requests queue.
// &amp;lt;i&amp;gt; Size of the queue depends on how many timers are used
// &amp;lt;i&amp;gt; in the system, how often timers are started and overall
// &amp;lt;i&amp;gt; system latency. If queue size is too small app_timer calls
// &amp;lt;i&amp;gt; will fail.

#ifndef APP_TIMER_CONFIG_OP_QUEUE_SIZE
#define APP_TIMER_CONFIG_OP_QUEUE_SIZE 10
#endif

// &amp;lt;q&amp;gt; APP_TIMER_CONFIG_USE_SCHEDULER  - Enable scheduling app_timer events to app_scheduler


#ifndef APP_TIMER_CONFIG_USE_SCHEDULER
#define APP_TIMER_CONFIG_USE_SCHEDULER 0
#endif

// &amp;lt;q&amp;gt; APP_TIMER_WITH_PROFILER  - Enable app_timer profiling
 

#ifndef APP_TIMER_WITH_PROFILER
#define APP_TIMER_WITH_PROFILER 0
#endif

// &amp;lt;q&amp;gt; APP_TIMER_KEEPS_RTC_ACTIVE  - Enable RTC always on
 

// &amp;lt;i&amp;gt; If option is enabled RTC is kept running even if there is no active timers.
// &amp;lt;i&amp;gt; This option can be used when app_timer is used for timestamping.

#ifndef APP_TIMER_KEEPS_RTC_ACTIVE
#define APP_TIMER_KEEPS_RTC_ACTIVE 0
#endif

// &amp;lt;o&amp;gt; APP_TIMER_CONFIG_SWI_NUMBER  - Configure SWI instance used.

// &amp;lt;0=&amp;gt; 0
// &amp;lt;1=&amp;gt; 1

#ifndef APP_TIMER_CONFIG_SWI_NUMBER
#define APP_TIMER_CONFIG_SWI_NUMBER 0
#endif

#endif //APP_TIMER_ENABLED
// &amp;lt;/e&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Do you have any other suggestions?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using app timer in sdk13</title><link>https://devzone.nordicsemi.com/thread/84462?ContentTypeID=1</link><pubDate>Fri, 21 Apr 2017 09:13:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74d13d59-cb35-448d-a892-15117a64eb6b</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Q1: Does app_timer module enable RTC1 or do I need to enable it?&lt;/p&gt;
&lt;p&gt;A1: The app_timer module enable RTC1 in the function &lt;code&gt;app_timer_init()&lt;/code&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Q2:Do I need to initialize the LF clk?&lt;/p&gt;
&lt;p&gt;A2:If you are using the SoftDevice, the LFCLCK gets initialized and enabled when you enable the SoftDevice.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Q3:Should I first enable the softdevice and then the timer, or the other way around?&lt;/p&gt;
&lt;p&gt;A3: You can do both, but you won&amp;#39;t get any timeout before the LFCLK is started.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Q4:Do you guys know why my timeout is not fired?&lt;/p&gt;
&lt;p&gt;A4: Try to change &lt;code&gt;app_timer_start(&amp;amp;m_pt100_timer_id, MEAS_TIMER_INTERVAL, NULL);&lt;/code&gt;
with &lt;code&gt;app_timer_start(m_pt100_timer_id, APP_TIMER_TICKS(100), NULL);&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>