I want to monitor NRF radio channell's RSSI to switch on "free" channel. How to make it properly?
This is my code:
if(rx_q_flag == true){
err_code = esb_init(RX, radio_channel);
APP_ERROR_CHECK(err_code);
err_code = nrf_esb_start_rx();
APP_ERROR_CHECK(err_code);
//NVIC_DisableIRQ(RADIO_IRQn);
//NRF_RADIO->EVENTS_DISABLED = 1;
//NRF_RADIO->TASKS_RXEN = 1;
for(int i=0; i<10; i++)
{
NRF_RADIO->TASKS_RSSISTART = 1;
rssi_average[i] = (uint16_t)(NRF_RADIO->RSSISAMPLE);
while(NRF_RADIO->EVENTS_RSSIEND == 0);
NRF_RADIO->TASKS_RSSISTOP = 1;
nrf_delay_us(500);
}
max = rssi_average[0];
for(int i = 0; i < 10; ++i)
{
if(rssi_average[i] < max)
{
max = rssi_average[i];
}
}
RSSSI_BUF[radio_channel] = max;
if(RSSSI_BUF[radio_channel] < 50){
sprintf((char*)textbuff, "CH: %d RSSI: -%d dBm\r\n", radio_channel, RSSSI_BUF[radio_channel] );
Serial_Print(textbuff);
}
NRF_RADIO->TASKS_RXEN = 0;
if(radio_channel++ >=125)
{
radio_channel=0;
rx_q_flag = false;
}
}
I take an array with max negative RSSI but it always looks like garbadge.