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

Timer interrupt problem

Dear Nordic developers,

I'm trying radio reciever example. I want to stay 7 ms in listening mode, if there is no event turn off the radio. For that I'm using timer interrupt. Please see the code bellow, I'm using radio reciever code

static uint32_t                   flag1;

uint32_t read_packet()

{


    uint32_t result = 0;
		timer_flag = true;
		flag1 = 0;

    NRF_RADIO->EVENTS_READY = 0U;
    // Enable radio and wait for ready
    NRF_RADIO->TASKS_RXEN = 1U;

    while (NRF_RADIO->EVENTS_READY == 0U)
    {
        // wait
    }
    NRF_RADIO->EVENTS_END = 0U;
    // Start listening and wait for address received event
    NRF_RADIO->TASKS_START = 1U;
		
		start_timer();

    // Wait for end of packet or buttons state changed
		//nrf_delay_ms(10);
    while (NRF_RADIO->EVENTS_END == 0U)
		{
			if (flag1 == 1)
				break;
	  }
		
		LEDS_ON(BSP_LED_1_MASK);
		if (NRF_RADIO->CRCSTATUS == 1U)
    {
        result = packet;
    }
    NRF_RADIO->EVENTS_DISABLED = 0U;
    // Disable radio
    NRF_RADIO->TASKS_DISABLE = 1U;

    while (NRF_RADIO->EVENTS_DISABLED == 0U)
    {
        // wait
    }
		nrf_delay_ms(10);
    return result;
}


void start_timer(void)

{
		
	NRF_TIMER0->TASKS_STOP = 1;
	NRF_TIMER0->MODE = TIMER_MODE_MODE_Timer;
	NRF_TIMER0->TASKS_CLEAR = 1;
	NRF_TIMER0->PRESCALER = 4;
	NRF_TIMER0->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
	NRF_TIMER0->CC[0] = 7000;
	
	// Set and enable interrupt on Timer0
	NRF_TIMER0->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos;
	NVIC_EnableIRQ(TIMER0_IRQn);
	NRF_TIMER0->EVENTS_COMPARE[0] = 0;
		
	NRF_TIMER0->TASKS_START = 1;
}


void TIMER0_IRQHandler(void)

{

	 flag1 = 1;
	 if (NRF_TIMER0->EVENTS_COMPARE[0] != 0)
		NRF_TIMER0->EVENTS_COMPARE[0] = 0;
}

I'm debugging my code, but I never get outof the while loop while (NRF_RADIO->EVENTS_END == 0U) loop

I'd really appreciate if someone can help me, Thanks, Gor

Parents
  • Hi,

    Since you're not receiving any packets the radio is not going to send an EVENTS_END, but instead it will wait for a packet to come. You can see that this stalling in while(NRD_RADIO->EVENTS_END == 0U) occurs in the base receiver example as well. A solution for this is to add a timeout, a set amount of time that your radio will listen.

    In pseudocode: while(NRF_RADIO->EVENTS_END == 0U && some_counter < some_number)

    Best regards,

    Øyvind

  • Hi Øyvind,

    Thanks for your response. I change to TIMER1 it doesn't help. I can debugg and see that the program enters to a interrupt handling function and I assume It should set flag1 to 1. But when it returns to a while loop it doesn't break the loop, I really don't understand why. I even tried the same example by removing radio and using only the timer, but no difference. I would really appreciate any advice.

    Thanks Gor

Reply
  • Hi Øyvind,

    Thanks for your response. I change to TIMER1 it doesn't help. I can debugg and see that the program enters to a interrupt handling function and I assume It should set flag1 to 1. But when it returns to a while loop it doesn't break the loop, I really don't understand why. I even tried the same example by removing radio and using only the timer, but no difference. I would really appreciate any advice.

    Thanks Gor

Children
No Data
Related