Other Parts Discussed in Thread: CC2652RSIP, CC2651R3SIPA
Tool/software:
how to calculate the rssi value in cc2652rsip example rfuartbridge_lp_cc2652rsip_nortos_gcc
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software:
how to calculate the rssi value in cc2652rsip example rfuartbridge_lp_cc2652rsip_nortos_gcc
Hi Kumaravel,
Here is the rfc_CMD_PROP_RX_s Struct Reference. If you set RF_cmdPropRx.rxConf.bAppendRssi to 1 during initialization in mainThread before calling RF_postCmd then the RSSI will be appended to the data packet which you receive in the RF queue during ReceivedOnRFcallback.
Regards,
Ryan
Units of the single byte received representing RSSI is a signed integer. You can reference the rfPacketErrorRate example for a usage example of recording and reporting RSSI values. See also rfc_CMD_GET_RSSI_s & RF_getRSSI
Regards,
Ryan
rfpacketerrorrate example i am not able to understand can you please give only a simple code for rssi i am unfamiliar using api RF_getrssi and lib you have refered I feel better if you provide a propper example using that API my goal is to write a rssi value in rfpackect rx_lp_cc2651r3sipa example code
From rx.c of the rfPacketErrorRate example:
static int8_t* rssi; rfc_propRxOutput_t rxStatistics_prop; static RF_CmdHandle rxCmdHndl = 0; //... rfc_CMD_PROP_RX_t *pRxCmd = NULL; pRxCmd = &RF_cmdPropRx; pRxCmd->pOutput = (uint8_t*)&rxStatistics_prop; //... rxCmdHndl = RF_postCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, &rx_callback, RF_EventRxEntryDone); rssi = &rxStatistics_prop.lastRssi;
These are excerpts from the parts that concern the RSSI, which can be evaluated upon the reception of each packet. You can use this example from rfPacketErrorRate for your rfPacketRx version.
Regards,
Ryan
i have attached my code ,here when rf received the data i need to calculate the rssi value then i need to transmit the packet along with rssi . I used cc2651rsipaLP i got -45 dbm for some data other data i am getting different rssi .I dont know whether my rssi code is working or not. in smart rf "f0 03 07 fe" is the received rssi it shows -46 . please guid me
I could not access the attachments, however you should monitor the RSSI between two devices at varying distances to confirm that it is changing as expected.
Regards,
Ryan
/***** Includes *****/ /* Standard C Libraries */ #include <stdlib.h> #include <unistd.h> #include <string.h> /* TI Drivers */ #include <ti/drivers/rf/RF.h> #include <ti/drivers/GPIO.h> #include <ti/drivers/UART2.h> /* Driverlib Header files */ #include DeviceFamily_constructPath(driverlib/rf_prop_mailbox.h) /* Board Header files */ #include "ti_drivers_config.h" #include "RFQueue.h" #include <ti_radio_config.h> /***** Defines *****/ #define DATA_ENTRY_HEADER_SIZE 8 #define MAX_LENGTH 30 #define NUM_DATA_ENTRIES 2 #define NUM_APPENDED_BYTES 2 //#define PAYLOAD_LENGTH 7 #define PAYLOAD_LENGTH 6 #define PACKET_INTERVAL 500000 // RSSI offset correction - adjusted to match SmartRF consistent reading // SmartRF shows consistent -47dBm, so we need to match that //#define RSSI_OFFSET 32 // Increased to get closer to -47dBm target #define RSSI_OFFSET 31 // Increased to get closer to -47dBm target // RSSI averaging for stable readings like SmartRF #define RSSI_SAMPLES 4 static int8_t rssiBuffer[RSSI_SAMPLES]; static uint8_t rssiIndex = 0; static bool rssiBufferFull = false; /***** Global Variables *****/ static RF_Object rfObject; static RF_Handle rfHandle; /* RX Data Entry Buffer */ #if defined(__TI_COMPILER_VERSION__) #pragma DATA_ALIGN(rxDataEntryBuffer, 4); static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)]; #elif defined(__IAR_SYSTEMS_ICC__) #pragma data_alignment = 4 static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)]; #elif defined(__GNUC__) static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)] __attribute__((aligned(4))); #else #error This compiler is not supported. #endif static dataQueue_t dataQueue; static rfc_dataEntryGeneral_t* currentDataEntry; static uint8_t packetLength; static uint8_t* packetDataPointer; static uint8_t rxPacket[MAX_LENGTH + NUM_APPENDED_BYTES - 1]; static uint8_t txPacket[MAX_LENGTH + NUM_APPENDED_BYTES - 1]; static UART2_Handle uart; /* RSSI tracking - corrected approach */ static rfc_propRxOutput_t rxStatistics_prop; static int8_t currentRssi = 0; /***** Function Prototypes *****/ static void rxCallback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e); static int8_t calculateRssi(int8_t rawRssi); /***** RSSI Calculation Function *****/ static int8_t calculateRssi(int8_t rawRssi) { // Add to rolling average buffer rssiBuffer[rssiIndex] = rawRssi; rssiIndex = (rssiIndex + 1) % RSSI_SAMPLES; if (rssiIndex == 0) rssiBufferFull = true; // Calculate average if we have enough samples if (rssiBufferFull) { int16_t sum = 0; for (int i = 0; i < RSSI_SAMPLES; i++) { sum += rssiBuffer[i]; } rawRssi = (int8_t)(sum / RSSI_SAMPLES); } // Apply offset correction int8_t correctedRssi = rawRssi + RSSI_OFFSET; return correctedRssi; } /***** Main Thread *****/ void *mainThread(void *arg0) { RF_Params rfParams; RF_Params_init(&rfParams); UART2_Params uartParams; UART2_Params_init(&uartParams); uartParams.baudRate = 115200; uart = UART2_open(CONFIG_UART2_0, &uartParams); UART2_write(uart, "\r\nUART OPEN - RSSI Corrected Version\r\n", strlen("\r\nUART OPEN - RSSI Corrected Version\r\n"), NULL); GPIO_setConfig(CONFIG_GPIO_RLED, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); GPIO_setConfig(CONFIG_GPIO_GLED, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); GPIO_write(CONFIG_GPIO_RLED, CONFIG_GPIO_LED_OFF); GPIO_write(CONFIG_GPIO_GLED, CONFIG_GPIO_LED_OFF); if (RFQueue_defineQueue(&dataQueue, rxDataEntryBuffer, sizeof(rxDataEntryBuffer), NUM_DATA_ENTRIES, MAX_LENGTH + NUM_APPENDED_BYTES)) { while (1); // RF Queue allocation failed } /* Set up RX command */ RF_cmdPropRx.pQueue = &dataQueue; RF_cmdPropRx.rxConf.bAutoFlushIgnored = 1; RF_cmdPropRx.rxConf.bAutoFlushCrcErr = 1; RF_cmdPropRx.maxPktLen = MAX_LENGTH; RF_cmdPropRx.pOutput = (uint8_t*)&rxStatistics_prop; /* Set up TX command */ RF_cmdPropTx.pktLen = PAYLOAD_LENGTH; RF_cmdPropTx.pPkt = txPacket; RF_cmdPropTx.startTrigger.triggerType = TRIG_NOW; #if defined(DeviceFamily_CC26X0R2) rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioSetup, &rfParams); #else rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams); #endif RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0); while (1) { RF_EventMask rxTermination = RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, &rxCallback, RF_EventRxEntryDone); if (rxTermination & RF_EventLastCmdDone) { // RX done - RSSI is now available and processed in callback } else { // Handle timeout/abort if needed } /* Prepare TX packet in response */ txPacket[2] = 0xf0; txPacket[3] = 0x03; txPacket[4] = rxPacket[4]; // Echo received data txPacket[5] = 0xfe; //txPacket[5] = (uint8_t)(currentRssi); // Embed corrected RSSI value // txPacket[6] = 0xfe; RF_EventMask txTermination = RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropTx, RF_PriorityNormal, NULL, 0); if (txTermination & RF_EventLastCmdDone) { GPIO_toggle(CONFIG_GPIO_GLED); // TX successful } usleep(PACKET_INTERVAL); } } /***** RX Callback - WITH RSSI AVERAGING *****/ static void rxCallback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) { if (e & RF_EventRxEntryDone) { GPIO_toggle(CONFIG_GPIO_RLED); // RX success currentDataEntry = RFQueue_getDataEntry(); packetLength = *(uint8_t*)(¤tDataEntry->data); packetDataPointer = (uint8_t*)(¤tDataEntry->data + 1); memcpy(rxPacket, packetDataPointer, packetLength); // Get raw RSSI from statistics (most reliable) int8_t rawRssi = rxStatistics_prop.lastRssi; // Calculate instantaneous corrected RSSI (matches SmartRF) int8_t instantRssi = rawRssi + RSSI_OFFSET; // Calculate averaged RSSI for stability int8_t averagedRssi = calculateRssi(rawRssi); // Calculate averaged and corrected RSSI currentRssi = calculateRssi(rawRssi); RFQueue_nextEntry(); // Print both instantaneous and averaged RSSI char rssiStr[80]; snprintf(rssiStr, sizeof(rssiStr), "Raw: %d, Instant: %d, Averaged: %d dBm\r\n", rawRssi, rawRssi + RSSI_OFFSET, currentRssi); UART2_write(uart, rssiStr, strlen(rssiStr), NULL); } }