This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Using app timer in sdk13

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 not be used anymore, so it wouldn't interfere with the SD.

On my custom board I have an ADC conected through SPI. I want to take a sample every 100ms based on a app timer timeout. However the timeout interrupt is not fired.

I use the following code in main start:

NRF_LOG_INIT(NULL); // Initialize the logging module

err_code = app_timer_init();
APP_ERROR_CHECK(err_code);


/* Initialize peripherals */
adc_init();
twi_init();
press_init();
batt_init();
ds2431_getprofile();
measurement_init();
NRF_LOG_FLUSH();

/* Initialize bluetooth */
ble_stack_init();
peer_manager_init(erase_bonds);
gap_params_init();
gatt_init();
advertising_init();
ble_services_init();
conn_params_init();

/* Start advertising on start-up */
err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code); 

measurement_start();

The timer is started in measurement_start and created in measurement_create:

APP_TIMER_DEF(m_pt100_timer_id);

void measurement_init(void)
{
	uint32_t time_base;
	ret_code_t err_code;

	/* Define a timer id used for 10Hz sample rate */
	err_code = app_timer_create(&m_pt100_timer_id, APP_TIMER_MODE_REPEATED, measurement_handler);
	APP_ERROR_CHECK(err_code);
}

void measurement_start(void)
{
	/* Start timer */
	app_timer_start(&m_pt100_timer_id, MEAS_TIMER_INTERVAL, NULL);

	/* Clear previous measurement in flash */

}

void measurement_handler(void * p_context) // this code is not fired
{
	float 	temperature = 0, pressure = 0;

	// do measurement, code currently not included
}

I have the following questions:

  1. Does app_timer module enable RTC1 or do I need to enable it?
  2. Do I need to initialize the LF clk?
  3. Should I first enable the softdevice and then the timer, or the other way around?
  4. Do you guys know why my timeout is not fired?
  • Hi,

    Q1: Does app_timer module enable RTC1 or do I need to enable it?

    A1: The app_timer module enable RTC1 in the function app_timer_init()


    Q2:Do I need to initialize the LF clk?

    A2:If you are using the SoftDevice, the LFCLCK gets initialized and enabled when you enable the SoftDevice.


    Q3:Should I first enable the softdevice and then the timer, or the other way around?

    A3: You can do both, but you won't get any timeout before the LFCLK is started.


    Q4:Do you guys know why my timeout is not fired?

    A4: Try to change app_timer_start(&m_pt100_timer_id, MEAS_TIMER_INTERVAL, NULL); with app_timer_start(m_pt100_timer_id, APP_TIMER_TICKS(100), NULL);

  • Hi Sigurd,

    I tried the change you suggested in A4. Unfortunately it did not work. The following snippet is from the sdk_config.h:

        // <e> APP_TIMER_ENABLED - app_timer - Application timer functionality
    //==========================================================
    #ifndef APP_TIMER_ENABLED
    #define APP_TIMER_ENABLED 1
    #endif
    #if  APP_TIMER_ENABLED
    // <o> APP_TIMER_CONFIG_RTC_FREQUENCY  - Configure RTC prescaler.
    
    // <0=> 32768 Hz
    // <1=> 16384 Hz
    // <3=> 8192 Hz
    // <7=> 4096 Hz
    // <15=> 2048 Hz
    // <31=> 1024 Hz
    
    #ifndef APP_TIMER_CONFIG_RTC_FREQUENCY
    #define APP_TIMER_CONFIG_RTC_FREQUENCY 0
    #endif
    
    // <o> APP_TIMER_CONFIG_IRQ_PRIORITY  - Interrupt priority
    
    
    // <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
    // <0=> 0 (highest)
    // <1=> 1
    // <2=> 2
    // <3=> 3
    // <4=> 4
    // <5=> 5
    // <6=> 6
    // <7=> 7
    
    #ifndef APP_TIMER_CONFIG_IRQ_PRIORITY
    #define APP_TIMER_CONFIG_IRQ_PRIORITY 7
    #endif
    
    // <o> APP_TIMER_CONFIG_OP_QUEUE_SIZE - Capacity of timer requests queue.
    // <i> Size of the queue depends on how many timers are used
    // <i> in the system, how often timers are started and overall
    // <i> system latency. If queue size is too small app_timer calls
    // <i> will fail.
    
    #ifndef APP_TIMER_CONFIG_OP_QUEUE_SIZE
    #define APP_TIMER_CONFIG_OP_QUEUE_SIZE 10
    #endif
    
    // <q> 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
    
    // <q> APP_TIMER_WITH_PROFILER  - Enable app_timer profiling
     
    
    #ifndef APP_TIMER_WITH_PROFILER
    #define APP_TIMER_WITH_PROFILER 0
    #endif
    
    // <q> APP_TIMER_KEEPS_RTC_ACTIVE  - Enable RTC always on
     
    
    // <i> If option is enabled RTC is kept running even if there is no active timers.
    // <i> 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
    
    // <o> APP_TIMER_CONFIG_SWI_NUMBER  - Configure SWI instance used.
    
    // <0=> 0
    // <1=> 1
    
    #ifndef APP_TIMER_CONFIG_SWI_NUMBER
    #define APP_TIMER_CONFIG_SWI_NUMBER 0
    #endif
    
    #endif //APP_TIMER_ENABLED
    // </e>
    

    Do you have any other suggestions?

  • The rest of the application is working fine? The only problem is that the timeout is not fired?

    Have you tried debugging the application? Are you running into the error handler somewhere? See this post on how to debug.

  • 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.

  • What does app_timer_start(m_pt100_timer_id, APP_TIMER_TICKS(100), NULL); return? Try do send the err_code to the error handler:

    void measurement_start(void)
    {
        ret_code_t err_code;
        /* Start timer */
        err_code = app_timer_start(&m_pt100_timer_id, MEAS_TIMER_INTERVAL, NULL);
        APP_ERROR_CHECK(err_code);
    
        /* Clear previous measurement in flash */
    
    }
    
Related