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

LFCLK: The interrupt that never came.

I'm doing a more complex application than what I'm showing here, but I've reduced it to the minimum. I'm initializing the RTC subsystem, creating a timer, and starting that timer.

I have the S130 SoftDevice installed on my nRF51422 DK board (Nordic 10028).

When I run this code in the debugger, my breakpoint in the callback code at int x = 42; is never reached. (It wasn't reached when I had something more substantive there either, so it's not a matter of the compiler optimizing it away.)

I single step through all the setup code and it seems to go well, including calling NVIC_SetPendingIRQ(SWI_IRQn); in app_timer.c. So what I think I'm seeing is the LFCLK interrupt being set but never actually invoked.

Finally, I've tried this code with and without the __WFI(); call in the event loop.

Long story short, I think I'm contriving the simplest possible application that uses RTC over LFCLK but it's not ever "ticking." What am I doing wrong here?

Aside: Is there any possibility I'm using the wrong SDK, or is the nRF51 SDK appropriate for all boards in the nRF51 family?

/*

	main.c
	
*/

#include <assert.h>
#include <stdbool.h>
#include "nrf.h"
#include "app_error.h"
#include "app_timer.h"

const int APP_TIMER_PRESCALER = 0;
const int APP_TIMER_OP_QUEUE_SIZE = 4;

void timer_module_start (app_timer_timeout_handler_t callback)
{
	uint32_t number_of_ticks = 5; // calculate this
	APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL);
	APP_TIMER_DEF(rtc);
	app_timer_create(&rtc, APP_TIMER_MODE_REPEATED, callback);
	assert(number_of_ticks >= 5);
	app_timer_start(rtc, number_of_ticks, NULL);
}

void timer_callback (void *data)
{
	int x = 42;
}

int main (int argc, char *argv[])
{
	timer_module_start(timer_callback);

	while (true)
	{
		__WFI();
	}
}
Parents
  • Maybe the problem is that the LFCLK clock isn't being started. Even if the RTC peripheral is set up properly it won't count until LFCLK is started. According to the documentation for APP_TIMER_INIT, if you aren't using the SoftDevice you have to start it manually. Just having the SoftDevice installed in flash isn't sufficient; you have to initialize it from the main function.

Reply
  • Maybe the problem is that the LFCLK clock isn't being started. Even if the RTC peripheral is set up properly it won't count until LFCLK is started. According to the documentation for APP_TIMER_INIT, if you aren't using the SoftDevice you have to start it manually. Just having the SoftDevice installed in flash isn't sufficient; you have to initialize it from the main function.

Children
Related