Hi !
I am working with a NRF52832 and with SDK 15.2.
For my application, I need sometimes to deactivate the Softdevice to begin some radio tests.
So I have programmed it, using the Radio Test and the Radio Emetter examples. have mainly used the radio_test library.
The part of my program handling the Rx mode is the following :
printf("radio_test_handler: RX\n");
err_code = radio_test_init();
//Clear the rx radio buffer
memset(g_rx_packet, 0, sizeof(g_rx_packet));
//Clear the frame counter
radio_frame_rx_counter = 0;
//start a process to manage notifs when we receive data
//activate Interruption when END event
NRF_RADIO->INTENSET |= RADIO_INTENSET_END_Msk;
//Enable Radio interruptions
NVIC_ClearPendingIRQ(RADIO_IRQn);
//NVIC_SetPriority(RADIO_IRQn, RADIO_IRQ_PRIORITY);
NVIC_EnableIRQ(RADIO_IRQn);
radio_rx_enabled = true;
g_pattern = (transmit_pattern_t) uart_rx_data->p_data[TRANSMISSION_PATTERN_ID];
radio_rx( uart_rx_data->p_data[DATA_RATE_ID], uart_rx_data->p_data[CHANNEL_ID]);
The radio_test_init function is the following :
static ret_code_t radio_test_init(void)
{
ret_code_t ret;
//disable softdevice
ret = ble_stack_stop();
while(nrf_sdh_is_enabled()){};
//check for nrf_sdh_is_enabled false => need to be in non-blocking mode
/* All the following part is from the radio_test example, need to be updated */
//init the clock
if(!nrf_drv_clock_init_check())
{
ret = nrf_drv_clock_init();
if(ret != NRF_SUCCESS) printf("Radio test: clock driver init error code %d\n", ret);
}
// Request Low frequency clock to re-enable the clock after the softdevice stops it.
if(!nrf_drv_clock_lfclk_is_running())
{
nrf_drv_clock_lfclk_request(NULL);
}
ret = app_timer_init();
if(ret != NRF_SUCCESS) printf("Radio test: app_timer_init error code %d\n", ret);
//APP_ERROR_CHECK(err_code);
//configuration of all peripherals used here
NRF_RNG->TASKS_START = 1;
#ifndef NRF52810_XXAA
NRF_NVMC->ICACHECNF = NVMC_ICACHECNF_CACHEEN_Enabled << NVMC_ICACHECNF_CACHEEN_Pos;
#endif // NRF52810_XXAA
// Start 64 MHz crystal oscillator.
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
NRF_CLOCK->TASKS_HFCLKSTART = 1;
// Wait for the external oscillator to start up.
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) //need to be in non blocking mode
{
// Do nothing.
}
NVIC_EnableIRQ(TIMER0_IRQn);
__enable_irq();
return ret;
}
And the radio_handler is the following :
/*Handler called when there is a Radio event */
void RADIO_IRQHandler(void)
{
NVIC_ClearPendingIRQ(RADIO_IRQn);
if(radio_rx_enabled)
{
//we enter if the radio event is the END event
if(NRF_RADIO->EVENTS_END !=0U)
{
/*
size_t size_data_received;
size_data_received = sizeof(g_rx_packet);
uint8_t data_buffer[size_data_received];
*/
//Prepare the data to send to the host
/*
for (uint32_t i = 0; i < size_data_received; i++)
{
printf("Data received through RX : %d\r\n", g_rx_packet[i]);
}
uart_tx_request_set(uint8_t * p_tx_data, uint8_t p_len);
*/
ret_code_t err_code;
/*payload to send */
uint8_t p_tx_data[RADIO_NOTIF_LEN];
// set response SOF
p_tx_data[0] = SOF_VALUE;
// set response type
p_tx_data[1] = ID_BLE_TEST_MODE_NOTIF;
// set payload length
p_tx_data[2] = 4;
//set Production test ID
p_tx_data[3] = RADIO_TEST_NOTIFICATION;
//set Radio Test ID
p_tx_data[4] = RX;
//set RX status
p_tx_data[5] = 1; // A new frame have been received
//set Radio frame counter
if(radio_frame_rx_counter >= BYTE_MAX_VALUE) radio_frame_rx_counter = 0;
else radio_frame_rx_counter++;
p_tx_data[6] = radio_frame_rx_counter;
// compute CRC
uint8_t crc_sent = crc8_u8CalcComplete(0x00, p_tx_data + UART_HOST_SOF, RADIO_NOTIF_LEN - 1 - UART_HOST_SOF);
p_tx_data[RADIO_NOTIF_LEN-1] = crc_sent;
err_code = uart_tx_request_set(p_tx_data, RADIO_NOTIF_LEN);
if(err_code != NRF_SUCCESS) printf("RADIO_IRQHandler : Unable to send request to the host, error code : %d\n", err_code);
NRF_RADIO->EVENTS_END ==0U;
memset(g_rx_packet, 0, sizeof(g_rx_packet));
}
}
}
After being entered in the Rx mode state, and began a modulated carrier transmission with another board with the Radio Test example, I receive the data and enters in the radio handler but I enter in it continuously even after deactivation of the transmitter. I don't know why, do you have ideas ?