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

RSSI Reading

I am trying to write a program in C to have my central device(nRF52840 dongle) read the RSSI from a peripheral. I have never written C code before and was told to use: 

TASKS_RSSISTART - Start the RSSI and take one single sample of the received signal strength
TASK_RSSISTOP - Stop the RSSI measurement
RSSISAMPLE - changes due to the temperature correction factor

I have copied a few pieces of code that I found online to a file in a project in SEGGER. The code segments are displayed bellow.

I would then like to use PuTTY to read the cli example from nordic and then connect the RSSI code to the command line. 

How should I piece the code together? How should I get the code to connect to the nRF52840 dongle?

 

/*TASKS_RSSISTART - Start the RSSI and take one single sample of the receive signal strength
TASK_RSSISTOP - Stop the RSSI measurement
RSSISAMPLE - changes due to temperature correcton factor

RSSI compensation based on weather:
For TEMP ≤ -30°C, RSSISAMPLE = RSSISAMPLE +3
For TEMP > -30°C and TEMP ≤ -10°C, RSSISAMPLE = RSSISAMPLE +2
For TEMP > -10°C and TEMP ≤ +10°C, RSSISAMPLE = RSSISAMPLE +1
For TEMP > +10°C and TEMP ≤ +30°C, RSSISAMPLE = RSSISAMPLE + 0
For TEMP > +30°C and TEMP ≤ +50°C, RSSISAMPLE = RSSISAMPLE - 1
For TEMP > +50°C and TEMP ≤ +70°C, RSSISAMPLE = RSSISAMPLE - 2
For TEMP > +70°C, RSSISAMPLE = RSSISAMPLE - 3
*/

TASKS_RXEN //enable RADIO in RX mode
TASKS_START //start RADIO
TASKS_STOP //stop RADIO
TASKS_DISABLE //disable RADIO


enum nrf_radio_task_t{
      NRF_RADIO_TASK_RSSISTART=offsetof(NRF_RADIO_Type,TASKS_RSSISTART),
      NRF_RADIO_TASK_RSSISTOP = offsetof(NRF_RADIO_Type,TASKS_RSSISTOP)
}

uint rssi = (*(volatile uint32_t *)NRF_RADIO->RSSISAMPLE)  //using brute force to access register directly

if (p_gap_evt->params.adv_report.scan_rsp)
  NRF_LOG_INFO("RSSI: %d dBm",p_gap_evt->params.rssi_changed.rssi);


NRF_LOG_INFO("RSSI: %d", p_ble_evt->evt.gap_evt.params.adv_report.rssi);  //printing rssi values

  • Marjeris, 

    Thank you! I was using the cli example from peripheral and not BLE. I will change the files to the ble_app_interactive now. How should I change the hex files once my code is changed, so that I can program with the desktop programmer? In the documentation for the CLI, it just states compile code onto the board.

    Ella

  • Hi,

    You don't need to make any changes to the hex file after building your code. If you are using segger to build the project you will find the project hex file under ses/output/release/exe/ble_app_interactive_s140_pca10056.hex

    Using the nRF connect programmer app you should flash both this hex file and the corresponding softdevice -> components\softdevie\s140\hex\s140_nrf52_6.1.1_softdevice.hex

    I recommend testing the programmer app using another example and familiarize yourself with how it works. You can try to build the blinky example located in examples\ble_peripheral\ble_app_blinky\pca10059\s140\ses\ble_app_blinky_pca10059_s140.emProject and flash it together with the softdevice to the dongle using the programmer app.

    Best regards,

    Marjeris

Related