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