NCS 2.9.1 - NRF5340DK
I am trying to use multiple compare channels on Timer1 (output_timer) such that an interrupt handler fires for both compare values, the second of which is enabled with the compare_extend shortcut such that it clears the timer. My app_timer_init function also inits Timer0 (timer_inst).
static void output_timer_handler(nrf_timer_event_t event_type, void * p_context)
{
switch(event_type)
{
case NRF_TIMER_EVENT_COMPARE1://3 or 1us - timer doesn't stop
//Drive data pin low
NRF_P1->OUTCLR = (1UL << (POLL_PIN - 32));
break;
case NRF_TIMER_EVENT_COMPARE0://4us - timer clears
// Set the next compare value on CC1
// Drive data pin high
NRF_P1->OUTSET = (1UL << (POLL_PIN - 32));
break;
default:
break;
}
}
static void app_timer_init()
{
nrfx_err_t status;
(void)status;
uint32_t base_frequency = NRF_TIMER_BASE_FREQUENCY_16MHZ;
nrfx_timer_config_t timer_config = NRFX_TIMER_DEFAULT_CONFIG(base_frequency);
timer_config.bit_width = NRF_TIMER_BIT_WIDTH_32;
timer_config.p_context = "Some context";
nrfx_timer_config_t timer_config2 = NRFX_TIMER_DEFAULT_CONFIG(base_frequency);
timer_config2.bit_width = NRF_TIMER_BIT_WIDTH_32;
status = nrfx_timer_init(&timer_inst, &timer_config, NULL);
if(status != NRFX_SUCCESS)
{
printk("Error Timer Init No: %d\n", status);
return;
}
else
printk("Controller Response Timer Initialized\n");
nrfx_timer_clear(&timer_inst);
status = nrfx_timer_init(&output_timer, &timer_config2, output_timer_handler);
if(status != NRFX_SUCCESS)
{
printk("Error Timer Init No: %d\n", status);
return;
}
else
printk("Poll Timer Initialized\n");
uint32_t period_len = nrfx_timer_us_to_ticks(&output_timer, (uint32_t) 4);
uint32_t zero_interval = nrfx_timer_us_to_ticks(&output_timer, (uint32_t) 1);
nrfx_timer_extended_compare(&output_timer, NRF_TIMER_CC_CHANNEL0, period_len, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
nrfx_timer_compare(&output_timer, NRF_TIMER_CC_CHANNEL1, zero_interval, true);
// ^ enabling this iterrupt causes no output
nrfx_timer_clear(&output_timer);
}
This is how I've connected IRQ in main().
IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_TIMER_INST_GET(TIMER_INST_IDX)), IRQ_PRIO_LOWEST,
NRFX_TIMER_INST_HANDLER_GET(TIMER_INST_IDX), 0, 0);
IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_TIMER_INST_GET(OUTPUT_TIMER_IDX)), IRQ_PRIO_LOWEST,
NRFX_TIMER_INST_HANDLER_GET(OUTPUT_TIMER_IDX), 0, 0);
The problem arises when I enable just the second compare interrupt on the output_timer. The application compiles but does not output anything to the console. When I set the int_enable parameter in the nrfx_timer_compare() function to false, everything behaves as expected.
Am I implementing this incorrectly?