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:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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) {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

And here's my send_packet function:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

This function may lead my board to freeze somewhere

And:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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