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

Get RSSI through DTM routines

Hi

   I want to get the RSSI value of the received packet through the DTM test routine. Here is my DTM test routine, where I changed it

/**@brief Function for preparing the radio. At start of each test: Turn off RF, clear interrupt flags of RF, initialize the radio
 *        at given RF channel.
 *
 *@param[in] rx     boolean indicating if radio should be prepared in rx mode (true) or tx mode.
 */
static void radio_prepare(bool rx)
{
    dtm_turn_off_test();
    NRF_RADIO->CRCPOLY      = m_crc_poly;
    NRF_RADIO->CRCINIT      = m_crc_init;
    NRF_RADIO->FREQUENCY    = (m_phys_ch << 1) + 2;                  // Actual frequency (MHz): 2400 + register value
    NRF_RADIO->PACKETPTR    = (uint32_t)&m_pdu;                      // Setting packet pointer will start the radio
    NRF_RADIO->EVENTS_READY = 0;
    NRF_RADIO->SHORTS       = (1 << RADIO_SHORTS_READY_START_Pos) |  // Shortcut between READY event and START task
                              (1 << RADIO_SHORTS_END_DISABLE_Pos)|   // Shortcut between END event and DISABLE task
							  (1 << RADIO_SHORTS_DISABLED_RSSISTOP_Pos);  // Shortcut between END event and DISABLE task 

    if (rx)
    {
        NRF_RADIO->EVENTS_END = 0;
        NRF_RADIO->TASKS_RXEN = 1;  // shorts will start radio in RX mode when it is ready
		//changed
		NRF_RADIO->EVENTS_RSSIEND = 0;
		NRF_RADIO->TASKS_RSSISTART =1;
    }
    else // tx
    {
        NRF_RADIO->TXPOWER = m_tx_power;
    }
}



uint32_t dtm_wait(void)
{
    // Enable wake-up on event
    SCB->SCR |= SCB_SCR_SEVONPEND_Msk;

    for (;;)
    {
        // Event may be the reception of a packet -
        // handle radio first, to give it highest priority:
        if (NRF_RADIO->EVENTS_END != 0)
        {
            NRF_RADIO->EVENTS_END = 0;
            NVIC_ClearPendingIRQ(RADIO_IRQn);

            if (m_state == STATE_RECEIVER_TEST)
            {
                NRF_RADIO->TASKS_RXEN = 1;
                if ((NRF_RADIO->CRCSTATUS == 1) && check_pdu())
                {
                    // Count the number of successfully received packets	
                    m_rx_pkt_count++;  	
                }
                //changed
                // Note that failing packets are simply ignored (CRC or contents error).
				if(NRF_RADIO->EVENTS_RSSIEND != 0)
				{
					NRF_RADIO->EVENTS_RSSIEND = 0;
					int8_t RSSI_RE = -1 * NRF_RADIO->RSSISAMPLE;
					NRF_RADIO->TASKS_RSSISTOP = 1;
					printf(">> RSSI: %d\r\n",RSSI_RE);
				
				}
				
                // Zero fill all pdu fields to avoid stray data
                memset(&m_pdu, 0, DTM_PDU_MAX_MEMORY_SIZE);
            }
            // If no RECEIVER_TEST is running, ignore incoming packets (but do clear IRQ!)
        }
		
       
	   
        // Check for timeouts:
        if (mp_timer->EVENTS_COMPARE[0] != 0)
        {
            mp_timer->EVENTS_COMPARE[0] = 0;
        }
        else if (mp_timer->EVENTS_COMPARE[1] != 0)
        {
            // Reset timeout event flag for next iteration.
            mp_timer->EVENTS_COMPARE[1] = 0;
            NVIC_ClearPendingIRQ(m_timer_irq);
            return ++m_current_time;
        }

        // Other events: No processing
    }
}

I got the result

>> RSSI: -127
>> RSSI: -127
>> RSSI: -127
>> RSSI: -127
>> RSSI: -127
>> RSSI: -127
>> RSSI: -127
>> RSSI: -127
>> RSSI: -127
>> RSSI: -127
>> RSSI: -127
>> RSSI: -127
>> RSSI: -127
>> RSSI: -127

Thank you for your reply

Parents Reply Children
  • Einar Thorsrud ,Thank you very much for your response.

    As I tried before, I made the following changes and met my expectations.

    /**@brief Function for preparing the radio. At start of each test: Turn off RF, clear interrupt flags of RF, initialize the radio
     *        at given RF channel.
     *
     *@param[in] rx     boolean indicating if radio should be prepared in rx mode (true) or tx mode.
     */
    static void radio_prepare(bool rx)
    {
        dtm_turn_off_test();
        NRF_RADIO->CRCPOLY      = m_crc_poly;
        NRF_RADIO->CRCINIT      = m_crc_init;
        NRF_RADIO->FREQUENCY    = (m_phys_ch << 1) + 2;                  // Actual frequency (MHz): 2400 + register value
        NRF_RADIO->PACKETPTR    = (uint32_t)&m_pdu;                      // Setting packet pointer will start the radio
        NRF_RADIO->EVENTS_READY = 0;
        NRF_RADIO->SHORTS       = (1 << RADIO_SHORTS_READY_START_Pos) |  // Shortcut between READY event and START task
                                  (1 << RADIO_SHORTS_END_DISABLE_Pos)|
    	                          //changed
    							  RADIO_SHORTS_ADDRESS_RSSISTART_Msk  |
                                  RADIO_SHORTS_DISABLED_RSSISTOP_Msk;   // Shortcut between END event and DISABLE task
        if (rx)
        {
            NRF_RADIO->EVENTS_END = 0;
            NRF_RADIO->TASKS_RXEN = 1;  // shorts will start radio in RX mode when it is ready
        }
        else // tx
        {
            NRF_RADIO->TXPOWER = m_tx_power;
        }
    }
    
    
    uint32_t dtm_wait(void)
    {
        // Enable wake-up on event
        SCB->SCR |= SCB_SCR_SEVONPEND_Msk;
    
        for (;;)
        {
            // Event may be the reception of a packet -
            // handle radio first, to give it highest priority:
            if (NRF_RADIO->EVENTS_END != 0)
            {
                NRF_RADIO->EVENTS_END = 0;
                NVIC_ClearPendingIRQ(RADIO_IRQn);
    
                if (m_state == STATE_RECEIVER_TEST)
                {
                    NRF_RADIO->TASKS_RXEN = 1;
                    if ((NRF_RADIO->CRCSTATUS == 1) && check_pdu())
                    {
                        // Count the number of successfully received packets	
                        m_rx_pkt_count++;  	
    					//NRF_RADIO->TASKS_RSSISTART = 1;
                    }
                    // Note that failing packets are simply ignored (CRC or contents error).
    				
                    // Zero fill all pdu fields to avoid stray data
                    memset(&m_pdu, 0, DTM_PDU_MAX_MEMORY_SIZE);
                }
                // If no RECEIVER_TEST is running, ignore incoming packets (but do clear IRQ!)
            }
    		
            if(NRF_RADIO->EVENTS_RSSIEND != 0)
    		{
    			rssi_pkt_count++;
    			NRF_RADIO->EVENTS_RSSIEND = 0;
    			int8_t rssi_c =  -1 * NRF_RADIO->RSSISAMPLE;
    			rssi_result += rssi_c;
    			printf(">> RSSI: %d pkt=%d\r\n",rssi_c,rssi_pkt_count);
    		
    		}
    		
            // Check for timeouts:
            if (mp_timer->EVENTS_COMPARE[0] != 0)
            {
                mp_timer->EVENTS_COMPARE[0] = 0;
            }
            else if (mp_timer->EVENTS_COMPARE[1] != 0)
            {
                // Reset timeout event flag for next iteration.
                mp_timer->EVENTS_COMPARE[1] = 0;
                NVIC_ClearPendingIRQ(m_timer_irq);
                return ++m_current_time;
            }
    
            // Other events: No processing
        }
    }
    
    

    I got the result:

    Thank you once again.

Related