Hi all,
I tried to implement a software ACK between two NRF24LE1 devices, but failed. In my tick_interrupt_ISR, I send a frame from device_A to device_B, and I want to wait for the ACK from device_B still in the tick_interrupt_ISR. To the detail, there is a flag variable in RF_IRQ(RF ISR), if a new RF frame is received, it will be set. And then the code in tick_interrupt_ISR will read the flag variable and check the received RF data, to determine whether it is a wanted ACK frame.
The simplified RF_IRQ ISR code is shown below:
void RF_IRQ(void) interrupt INTERRUPT_RFIRQ
{
uint8_t irq_flags;
irq_flags = hal_nrf_get_clear_irq_flags();// Read and clear IRQ flags from radio
switch(irq_flags)
{
// If data received
case (1 << (uint8_t)HAL_NRF_RX_DR):
// Read payload
while(!hal_nrf_rx_fifo_empty())
{
hal_nrf_read_rx_payload(RX_buffer);
}
// Flush RX FIFO
hal_nrf_flush_rx();
radio_receive_ready = true; //The flag is set here!!!
LED3 = ~LED3;
break;
// If Transmission success
case (1 << (uint8_t)HAL_NRF_TX_DS):
radio_send_busy = false;
break;
// Transmission failed (maximum re-transmits)
case (1 << (uint8_t)HAL_NRF_MAX_RT):
hal_nrf_flush_tx();
radio_send_busy = false;
break;
default:
break;
}
}
The simplified tick ISR is shown below:
void rtc2_isr(void) interrupt INTERRUPT_TICK
{
RTC2CON &= 0xfe; //Disable RTC2 function 1111 1110
TX_buffer[7] = 0x12; //control data to device_B
RF_Send(TX_buffer, RF_PLOAD_WIDTH); //Send a control frame to device_B
//Try to wait the ACK here
// while(!radio_receive_ready ); // line121
if( radio_receive_ready == true)
{
LED4 = ~LED4; //The LED4 never changed status!!!
}
}
My test results are shown below:
-
If "line121" is commented out, the LED3 always changes each time I send a frame, but LED4 never changes;
-
If "line121" is NOT commented, the device seems to be gotten stuck, and BOTH LED3 & LED4 never changes. The tick interrupt has a lower priority than RF interrupt, and I wonder if the interrupt nesting error happend.
Could you please help me analyze this problem, thanks in advance!
Best Regards, Junma