This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem facing with RSSI value in nRF51822

Hi,

I am new to nRF microcontroller and communication . currently, I am working on nRF51822 microcontroller. I am able to communicate between two nRF51822 microcontrollers(without any protocol stack).

I want to measure RSSI value. I got RSSI new 1test.ccode from the nordic website. When I integrated RSSI code with my code, I got constant RSSI value that is 46. I didn't know what is the mistake. I have attached my code with this.

  • Try to use this code:

    uint8_t radio_rssi_get (void){
    	
    uint8_t sample;
    NRF_RADIO->TASKS_RSSISTART = 1;
    while (NRF_RADIO->EVENTS_RSSIEND == 0){}
    NRF_RADIO->EVENTS_RSSIEND = 0;
    sample = NRF_RADIO->RSSISAMPLE;
    NRF_RADIO->TASKS_RSSISTOP = 1;
    return sample;
    }
    
  • Hi Sigurd,

    I try the same function in my code.

    I am getting constant value 46 every time.

    This is my code:

    #include <stdint.h>
    #include <stdbool.h>
    #include <stdio.h>
    #include "radio_config.h"
    #include "nrf_gpio.h"
    #include "boards.h"
    #include "bsp.h"
    #include "app_timer.h"
    #include "nordic_common.h"
    #include "nrf_error.h"
    #include "nrf_delay.h"
    
    #define APP_TIMER_PRESCALER      0                     /**< Value of the RTC1 PRESCALER register. */
    #define APP_TIMER_OP_QUEUE_SIZE  2                     /**< Size of timer operation queues. */
    
    #define UART_TX_BUF_SIZE 256                           /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE 1                             /**< UART RX buffer size. */
    
    static uint32_t                   packet;              /**< Packet to transmit. */
    
    void uart_error_handle(app_uart_evt_t * p_event)
    {
       // No implementation needed.
    }
    
    /**@brief Function for initialization oscillators.
     */
    void clock_initialization()
    {
        /* Start 16 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)
        {
            // Do nothing.
        }
    
        /* Start low frequency crystal oscillator for app_timer(used by bsp)*/
        NRF_CLOCK->LFCLKSRC            = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_LFCLKSTART    = 1;
    
        while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
        {
            // Do nothing.
        }
    }
    
    
    /**@brief Function for reading packet.
     */
    uint32_t read_packet()
    {
        uint32_t result = 0;
    
        NRF_RADIO->EVENTS_READY = 0U;
        // Enable radio and wait for ready
        NRF_RADIO->TASKS_RXEN = 1U;
    
        while (NRF_RADIO->EVENTS_READY == 0U)
        {
            // wait
        }
        NRF_RADIO->EVENTS_END = 0U;
        // Start listening and wait for address received event
        NRF_RADIO->TASKS_START = 1U;
    
        // Wait for end of packet or buttons state changed
        while (NRF_RADIO->EVENTS_END == 0U)
        {
            // wait
        }
    
        if (NRF_RADIO->CRCSTATUS == 1U)
        {
            result = packet;
        }
        NRF_RADIO->EVENTS_DISABLED = 0U;
        // Disable radio
        NRF_RADIO->TASKS_DISABLE = 1U;
    
        while (NRF_RADIO->EVENTS_DISABLED == 0U)
        {
            // wait
        }
        return result;
    }
    
    uint8_t radio_rssi_get (void) {
    
    uint8_t sample;
    NRF_RADIO->TASKS_RSSISTART = 1;
    while (NRF_RADIO->EVENTS_RSSIEND == 0){}
    NRF_RADIO->EVENTS_RSSIEND = 0;
    sample = NRF_RADIO->RSSISAMPLE;
    NRF_RADIO->TASKS_RSSISTOP = 1;
    return sample;
    
    }
    
    
    /**
     * @brief Function for application main entry.
     * @return 0. int return type required by ANSI/ISO standard.
     */
    int main(void)
    {
        uint32_t err_code = NRF_SUCCESS;
    	//nrf_gpio_cfg_output(23); // Making LED port pin to output
    	uint8_t rssi = 0; 
    
        clock_initialization();
        APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL);
    
        const app_uart_comm_params_t comm_params =  
        {
            RX_PIN_NUMBER, 
            TX_PIN_NUMBER, 
            RTS_PIN_NUMBER, 
            CTS_PIN_NUMBER, 
            APP_UART_FLOW_CONTROL_DISABLED, 
            false, 
            UART_BAUDRATE_BAUDRATE_Baud115200
        };   
        APP_UART_FIFO_INIT(&comm_params, 
                           UART_RX_BUF_SIZE, 
                           UART_TX_BUF_SIZE, 
                           uart_error_handle, 
                           APP_IRQ_PRIORITY_LOW,
                           err_code);
        APP_ERROR_CHECK(err_code);
        err_code = bsp_init(BSP_INIT_LED, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
        APP_ERROR_CHECK(err_code);
    
        // Set radio configuration parameters
        radio_configure();
        NRF_RADIO->PACKETPTR = (uint32_t)&packet;
    
        err_code = bsp_indication_text_set(BSP_INDICATE_USER_STATE_OFF, "Wait for first packet\n\r");
        APP_ERROR_CHECK(err_code);
    
        while (true)
        {
    		uint32_t received = read_packet();
    		
            nrf_delay_ms(500);
            printf("The contents of the package is %u\n\r", (unsigned int)received);
    		
    		rssi = radio_rssi_get();
    		 printf("RSSI = %d\n\r", rssi);
    		
        }
    }
    
  • You will need to start the RSSI in while (NRF_RADIO->EVENTS_END == 0U), and then read the RRSI in if(NRF_RADIO->CRCSTATUS == 1U) in read_packet().

    Code:

    /**@brief Function for reading packet.
     */
    uint32_t read_packet()
    {
        uint32_t result = 0;
        uint8_t rssi_sample;
        
        NRF_RADIO->EVENTS_READY = 0U;
        // Enable radio and wait for ready
        NRF_RADIO->TASKS_RXEN = 1U;
    
        while (NRF_RADIO->EVENTS_READY == 0U)
        {
            // wait
        }
        
        NRF_RADIO->EVENTS_END = 0U;
        // Start listening and wait for address received event
        
        NRF_RADIO->TASKS_START = 1U;
            
        // Wait for end of packet or buttons state changed
        
        while (NRF_RADIO->EVENTS_END == 0U)
        {
            NRF_RADIO->TASKS_RSSISTART = 1;
            // wait
        }
    
        if (NRF_RADIO->CRCSTATUS == 1U)
        {
            result = packet;
            rssi_sample = NRF_RADIO->RSSISAMPLE;
            NRF_RADIO->TASKS_RSSISTOP = 1;
        }
        
        //NRF_LOG_INFO("rssi is: %d\r\n", (unsigned int)rssi_sample);
        printf("rssi is: %d\r\n", (unsigned int)rssi_sample);
        
        NRF_RADIO->EVENTS_DISABLED = 0U;
        // Disable radio
        NRF_RADIO->TASKS_DISABLE = 1U;
    
        while (NRF_RADIO->EVENTS_DISABLED == 0U)
        {
            // wait
        }
        return result;
    }
    
  • Hi Sigurd,

    It is working properly. Thank you for your help.

    It's very informative support.

    Thank you once again.

  • Hi Krvb & Sigurd,

    I am developing one of the code for the application for the custom board.

    In which I need to develop the code for the receiving signal RSSI value of the selected channel for board testing.

    I was just gone through your code and tried to understand the code thoroughly, what I understand that we are getting the RSSI value right ?? but for which channel ?? 

    Can we define the channel or select the channel on which we need to the get RSSI on the particular channel (channel entered by user).

    I need to pass the channel and read the RSSI value for the same channel. Is there any modification in above code through which I can add or pass the channel and receive the RSSI value.

    Looking forward for kind support and valuable responses ...

    Thanks

Related