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