Skip to content

Commit

Permalink
Merge pull request #341 from SaidAlvarado/echo-issue
Browse files Browse the repository at this point in the history
bsp/radio: fix TX causing an undesired interrupt + a CRC error
  • Loading branch information
aabadie authored Oct 10, 2024
2 parents ae3fb9f + 23cffa1 commit 5b0cc80
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions bsp/nrf/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,21 @@ void db_radio_tx(const uint8_t *tx_buffer, uint8_t length) {
radio_vars.pdu.length = length;
memcpy(radio_vars.pdu.payload, tx_buffer, length);

NRF_RADIO->SHORTS = RADIO_SHORTS_COMMON | (RADIO_SHORTS_DISABLED_RXEN_Enabled << RADIO_SHORTS_DISABLED_RXEN_Pos);
NRF_RADIO->INTENSET = RADIO_INTERRUPTS;
NRF_RADIO->SHORTS = RADIO_SHORTS_COMMON | (RADIO_SHORTS_DISABLED_RXEN_Enabled << RADIO_SHORTS_DISABLED_RXEN_Pos);

if (radio_vars.state == RADIO_STATE_IDLE) {

// Enable the Radio to send the packet
NRF_RADIO->EVENTS_DISABLED = 0; // We must use EVENT_DISABLED, if we use EVENT_END. the interrupts will be enabled in the time between the END event and the Disable event, triggering an undesired interrupt
NRF_RADIO->TASKS_TXEN = RADIO_TASKS_TXEN_TASKS_TXEN_Trigger << RADIO_TASKS_TXEN_TASKS_TXEN_Pos;
// Wait for transmission to end and the radio to be disabled
while (NRF_RADIO->EVENTS_DISABLED == 0) {}

// We re-enable interrupts AFTER the packet is sent, to avoid triggering an EVENT_ADDRESS and EVENT_DISABLED interrupt with the outgoing packet
// We also clear both flags to avoid insta-triggering an interrupt as soon as we assert INTENSET
NRF_RADIO->EVENTS_ADDRESS = 0;
NRF_RADIO->EVENTS_DISABLED = 0;
_radio_enable();
NRF_RADIO->EVENTS_END = 0;
NRF_RADIO->TASKS_TXEN = RADIO_TASKS_TXEN_TASKS_TXEN_Trigger << RADIO_TASKS_TXEN_TASKS_TXEN_Pos;
// Wait for transmission to end
while (NRF_RADIO->EVENTS_END == 0) {}
}
radio_vars.state = RADIO_STATE_RX;
}
Expand Down

0 comments on commit 5b0cc80

Please sign in to comment.