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

Using NRF52 Radio IRQhandler for sending and receiving data

Hello there,

I'd like to send and receive data through NRF Radio's handler. I've been able to configure the handler to receive data. Otherwise, I'm having difficulty on sending data.

Here's my current IRQHandler function:

void RADIO_IRQHandler(void) {
	nrf_gpio_pin_set(RECPIN);
	NRF_RADIO->EVENTS_END = 0U;
	NRF_RADIO->TASKS_START = 1U;
	if (NRF_RADIO->EVENTS_READY && (NRF_RADIO->INTENSET & RADIO_INTENSET_READY_Msk)) {
		NRF_RADIO->EVENTS_READY = 0;
	}

	if (NRF_RADIO->EVENTS_END && (NRF_RADIO->INTENSET & RADIO_INTENSET_END_Msk)) {
		NRF_RADIO->EVENTS_END = 0U;
	}

	if (NRF_RADIO->EVENTS_ADDRESS && (NRF_RADIO->INTENSET & RADIO_INTENSET_ADDRESS_Msk)) {
		NRF_RADIO->EVENTS_ADDRESS = 0;
	}
	NRF_RADIO->EVENTS_DISABLED = 0U;

	if (NRF_RADIO->CRCSTATUS == 1U) {
		receive_packet();
		if (targetID == MyID || targetID == ALL_NODES) {
			if (My_Role == MASTER) {
				communicator();
			} else {
				normal();
			}
		}
	}
	nrf_gpio_pin_clear(RECPIN);
}

And here's my send_packet function:

void send_packet()
{
    // send the packet:
    NRF_RADIO->EVENTS_READY = 0U;
    NRF_RADIO->TASKS_TXEN   = 1;

    while (NRF_RADIO->EVENTS_READY == 0U)
    {
        // wait
    }
    NRF_RADIO->EVENTS_END  = 0U;
    NRF_RADIO->TASKS_START = 1U;

    while (NRF_RADIO->EVENTS_END == 0U)
    {
        // wait
    }

    NRF_RADIO->EVENTS_DISABLED = 0U;
    // Disable radio
    NRF_RADIO->TASKS_DISABLE = 1U;

    while (NRF_RADIO->EVENTS_DISABLED == 0U)
    {
        // wait
    }
}

This function may lead my board to freeze somewhere

And:

void send_packet() {
	// send the radioTxBuffer:
	//	if (radioTxBuffer[1] == COLLECT_REPLY) {
	//		//printf("%d: Transmitting: %x %x %x %x\r\n", __LINE__, radioTxBuffer[0], radioTxBuffer[1], radioTxBuffer[2], radioTxBuffer[3]);
	//		copyThis(radioTxBuffer);
	//	}
	NRF_RADIO->EVENTS_DISABLED = 0;
	NRF_RADIO->TASKS_DISABLE = 1;
	while (!NRF_RADIO->EVENTS_DISABLED);		//wait for radio to be disabled

	NRF_RADIO->EVENTS_READY = 0U;
	NRF_RADIO->TASKS_TXEN	 = 1;

	while (NRF_RADIO->EVENTS_READY == 0U) {	//wait for radio to be in tx mode
		// wait
	}

	NRF_RADIO->PACKETPTR = (uint32_t)&radioTxBuffer;

	NRF_RADIO->EVENTS_END	= 0U;			// clear flag
	NRF_RADIO->TASKS_START = 1U;			// Start sending

	while (NRF_RADIO->EVENTS_END == 0U) {	// wait for radio to finish sending
		// wait
	}

	// Clear event
	NRF_RADIO->EVENTS_DISABLED = 0U;
	NRF_RADIO->EVENTS_END = 0;
	NRF_RADIO->EVENTS_READY = 0;
	// Disable radio
	//NRF_RADIO->TASKS_DISABLE = 1U;


	//	while (NRF_RADIO->EVENTS_DISABLED == 0U)
	//	{
	//		// wait
	//	}
}

This function will return normal as nothing happened, while not sending anything.

I would like some enlightenment on how to implement Radio Send and receive properly. (Proprietary radio, not BLE)

Thank you in advance

Related