Hi All!
I have a problem which i can't really understood. I'm using nRF5340-DK evaluation board, and currently i'm trying to get one of timer (TIMER1 in this example) to have a tick every 1s.
I want to have it done via NRF(X) library, not using Zephyr. Here's my code:
Z_ISR_DECLARE( TIMER1_IRQn, 0, nrfx_timer_1_irq_handler, NULL );
void timerEventHandler( nrf_timer_event_t event_type, void *p_context )
{
printk("Timer called");
}
nrfx_timer_config_t initCfg = {
.frequency = NRF_TIMER_FREQ_16MHz,
.mode = NRF_TIMER_MODE_TIMER,
.bit_width = TIMER_BITMODE_BITMODE_32Bit,
.interrupt_priority = 1,
.p_context = NULL
};
z_arm_irq_priority_set( TIMER1_IRQn, 1, 0 );
nrfx_timer_init( NRFX_TIMER_INSTANCE( 1 ), &initCfg, timerEventHandler );
uint32_t maxVal = nrfx_timer_us_to_ticks( NRFX_TIMER_INSTANCE( 1 ), 1000000 );
nrfx_timer_extended_compare( NRFX_TIMER_INSTANCE( 1 ), NRF_TIMER_CC_CHANNEL0, maxVal, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true );
nrfx_timer_enable( NRFX_TIMER_INSTANCE( 1 ) );
Now the problem is, that in most situations it is working fine. However, after some time (ex. 20 seconds), i observe the lag on UART console, meaning that timer has been called not a second ago prior to last call, but about 2-3 seconds.
Can't really get what could be reason?
I have also another issue facing timers. If i add infinite while loop like this into main:
while(1)
{
uart_irq_rx_disable( device);
checkFlag = !checkFlag;
uart_irq_rx_enabe( device );
}
Then it appears that uart_irq_rx_disable also disables timer interrupt. When i do frequently rx_disable, then timer interrupt is lagging even more.
Can't really understood why disabling UART interrupt also disables Timer interrupt?
Thank you for any help!