nRF Connect Timer PPI

Hi,

I am trying to get a simple LED blinking using a timer, gpiote and the ppi. So the Idea is:

Timer compare event -- PPI --> gpio toggle. I am using the nRF connect sdk version 1.9.0.

My main.c is pretty simple, only containing the basic code.

#include <sys/printk.h>

#include <nrfx_timer.h>
#include <nrfx_gpiote.h>
#include <nrfx_ppi.h>

static void timer_event_handler(nrf_timer_event_t event_type, void *p_context)
{
	printk("Event");
}

#define LED_PIN 17

static nrf_ppi_channel_t out_channel;
static const nrfx_timer_t my_nrfx_timer = NRFX_TIMER_INSTANCE(1); // get TIMER1 device struct pointer; TIMER0 is used for the radio!

void app_error_check(nrfx_err_t err){
	if (err != NRFX_SUCCESS){
		printk("Error!");
	}
}

void main(void)
{
	printk("Hello World! %s\n", CONFIG_BOARD);
	nrfx_err_t err = NRFX_SUCCESS;

	nrfx_gpiote_out_config_t out_config = NRFX_GPIOTE_CONFIG_OUT_TASK_TOGGLE(false);
	err = nrfx_gpiote_out_init(LED_PIN, &out_config);
	app_error_check(err);
	
	nrfx_gpiote_out_task_enable(LED_PIN);

	// Connect the EVENTS_COMPARE[0] event to a gpio output	
	err = nrfx_ppi_channel_alloc(&out_channel);
	app_error_check(err);
	uint32_t timer_event_addr = nrfx_timer_compare_event_address_get(&my_nrfx_timer, NRF_TIMER_EVENT_COMPARE0);
	uint32_t gpio_task_addr = nrfx_gpiote_out_task_addr_get(LED_PIN);

	err = nrfx_ppi_channel_assign(out_channel, timer_event_addr, gpio_task_addr);
	app_error_check(err);

	err = nrfx_ppi_channel_enable(out_channel);
	app_error_check(err);

	// start the timer
	// initialize the timer with default values
	nrfx_timer_config_t conf = NRFX_TIMER_DEFAULT_CONFIG;
	conf.mode = NRF_TIMER_MODE_TIMER;
	conf.bit_width = NRF_TIMER_BIT_WIDTH_32;
	err = nrfx_timer_init(&my_nrfx_timer, &conf, timer_event_handler);
	app_error_check(err);
	nrfx_timer_extended_compare(&my_nrfx_timer, NRF_TIMER_CC_CHANNEL0, nrfx_timer_ms_to_ticks(&my_nrfx_timer, 1000), NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

	nrfx_timer_enable(&my_nrfx_timer);
	
	while(true){}
}

And my prj.conf only enables the neccessary modules:

CONFIG_NRFX_TIMER1=y
CONFIG_NRFX_PPI=y
CONFIG_NRFX_GPIOTE=y
CONFIG_NRFX_TIMER=y

I have tried toggling the gpio via another gpiote event (button). This works, so i think the problem must be the timer.

I have when enabling the interrupt, the board resets and when disabling it, it simply does not work.

Do you have an idea, where the problem could reside? Something seems to be really misconfigured.

Thank you!

Related