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.

CC2340R5: how can read RSSI value

Part Number: CC2340R5

How can read RSSI value. I have two board(CC2340R5).

I am using basic_ble project.   

  • Hi,

    Thank you for reaching out.

    • On the peripheral side - in app_peripheral.c - Add the following code

    Add an event handler:

    BLEAppUtil_EventHandler_t peripheralConnNotiHandler =
    {
        .handlerType    = BLEAPPUTIL_CONN_NOTI_TYPE,
        .pEventHandler  = Peripheral_GAPConnReportHandler,
        .eventMask      = BLEAPPUTIL_CONN_NOTI_CONN_EVENT_ALL,
    };
    

    Create the handling function for the newly created event:

    void Peripheral_GAPConnReportHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
    {
        switch(event)
        {
    
            case BLEAPPUTIL_CONN_NOTI_CONN_EVENT_ALL:
            {
                Gap_ConnEventRpt_t *report = (Gap_ConnEventRpt_t *)pMsgData;
                int8_t rssi = report->lastRssi;
                //Your code
                break;
            }
    
            default:
            {
                break;
            }
        }
    }

    Under BLEAPPUTIL_LINK_ESTABLISHED_EVENT, ensure you register the connection for the event:

            case BLEAPPUTIL_LINK_ESTABLISHED_EVENT:
            {
                gapEstLinkReqEvent_t *gapEstMsg = (gapEstLinkReqEvent_t *)pMsgData;
                BLEAppUtil_registerConnNotifHandler(gapEstMsg->connectionHandle);
                
                //...

    In Peripheral_start(), register the event handler:

    bStatus_t Peripheral_start()
    {
        bStatus_t status = SUCCESS;
    
        //...
    
        status = BLEAppUtil_registerEventHandler(&peripheralConnNotiHandler);
        if(status != SUCCESS)
        {
            // Return status value
            return(status);
        }
    
        //...

    • On the central side - in app_central.c - Add the following code

    Add an event handler

    BLEAppUtil_EventHandler_t centralConnNotiHandler =
    {
        .handlerType    = BLEAPPUTIL_CONN_NOTI_TYPE,
        .pEventHandler  = Central_GAPConnReportHandler,
        .eventMask      = BLEAPPUTIL_CONN_NOTI_CONN_EVENT_ALL,
    };
    

    Create the handling function of the newly created event:

    void Central_GAPConnReportHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
    {
        switch(event)
        {
    
            case BLEAPPUTIL_CONN_NOTI_CONN_EVENT_ALL:
            {
                volatile Gap_ConnEventRpt_t *report = (Gap_ConnEventRpt_t *)pMsgData;
                int8_t rssi = report->lastRssi;
                //Your code
                break;
            }
    
            default:
            {
                break;
            }
        }
    }

    In Central_start(), register the event handler:

    bStatus_t Central_start()
    {
        bStatus_t status = SUCCESS;
    
        //...
    
        status = BLEAppUtil_registerEventHandler(&centralConnNotiHandler);
        if(status != SUCCESS)
        {
            // Return status value
            return(status);
        }
    
        //...

    In app_connection.c, register the newly formed connection:

    void Connection_ConnEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
    {
        switch(event)
        {
            case BLEAPPUTIL_LINK_ESTABLISHED_EVENT:
            {
                //...
    
                // Register to connection notifications
                BLEAppUtil_registerConnNotifHandler(gapEstMsg->connectionHandle);
    
                //...
                
                break;
            }
            
            //...

    Once these changes are implemented you should receive the RSSI at each connection event!

    I hope this will help,

    Best regards,

  • Thank you so much Sir.

  • So what is happening in  my peripheral side the value is shown but Central side not working.

    I don't known  why the RSSI value is not show in Central side.

    Regards,

    Umesh

  • Hi Umesh,

    Can you confirm the Central_GAPConnReportHandler() is accessed at each connection event? I guess you can add a volatile global counter in the function to verify this.

    Best regards,

  • hello sir,

    Sorry Sir I didn't get you can you please ellaborate.

  • Hi,

    Can you please describe the debugging steps you have taken so far?

    Among others, have you verified whether the code run by Central_GAPConnReportHandler(). This can be checked using a breakpoint.

    If needed, please refer to the debugging guide: https://software-dl.ti.com/simplelink/esd/simplelink_lowpower_f3_sdk/7.20.01.10/exports/docs/ble5stack/ble_user_guide/html/ble-stack-5.x-guide/debugging-index-cc23xx.html 

    Best regards,