CC2340R5: I don't get any notifications when i write the value from central(cc1352) to peripheral(cc2340)

Part Number: CC2340R5
Other Parts Discussed in Thread: CC1352R, SYSCONFIG

Tool/software:

Dear experts,
Currently i am working with CC2340 based instrument with CC1352R(Central), i have modified the code in simplecentral.c i got the following log

DEV_IDENTIFIED
Connecting to DEV_ADDR...
Connected to 0x40791213A330, scConnHandle=0x0000
Num Conns: 1
Encryption success
DISCOVERY_CASE_CALLED
DISCOVERY_FUNCTION_CALLED (conn=0x0000)
ExchangeMTU sent on conn=0x0000, status=0x00
GATT Msg: method=0x03 status=0x00 state=1
DiscEvt: method=0x03, status=0x00, state=1
MTU rsp OK → Discover All Services
Sent DiscAllPrimaryServices on conn=0x0000, status=0x00
MTU Size: 65
GATT Msg: method=0x11 status=0x00 state=2
DiscEvt: method=0x11, status=0x00, state=2
Service Found: start=0x0001 end=0x000B UUID=0x1800
Service Found: start=0x000C end=0x0010 UUID=0x180A
UUID BE (rsp): f000c0c0-0451-4000-b000-000000000000
Target SVC matched @ [0x0011..0x0016]
UUID BE (rsp): f000ffd0-0451-4000-b000-000000000000
GATT Msg: method=0x11 status=0x1a state=2
DiscEvt: method=0x11, status=0x1a, state=2
DiscAllChars [0x0011..0x0016] status=0x00
GATT Msg: method=0x09 status=0x00 state=3
DiscEvt: method=0x09, status=0x00, state=3
Char: declH=0x0012 valH=0x0013 props=0x08 uuid128=f000c0c1-0451-4000-b000-000000000000 (WRITE)
Char: declH=0x0014 valH=0x0015 props=0x10 uuid128=f000c0c2-0451-4000-b000-000000000000 (NOTIFY)
GATT Msg: method=0x09 status=0x1a state=3
DiscEvt: method=0x09, status=0x1a, state=3
Char discovery complete
CCCD fallback -> 0x0016
Writing CCCD @0x0016 (enable NOTIFY)

If needed, I can share my code via private message. Please guide me on how to resolve the issue.

Note: The device in question is a CC2340-based peripheral. I am unable to check the connection log, but the device works perfectly with the nRF Connect application. I have a question: when connecting via the nRF Connect application, it prompts for a passkey, but in the process described above, the device does not trigger the passkey function. Why is this happening?



regards
Surya

  • Hi !

    If this works fine with the nRFConnect app, then the issue is probably from the CC1352 central. Did you use an example from the SDK to kickstart your project ? The chapter about GATT for user guide for the CC13XX_CC26XX SDK mentions that you need two things :
    - Call GATT_RegisterForInd(selfEntity) initially (this is done in the SimpleCentral_init function in the SimpleCentral example of the SDK) 
    - Add a filter for ATT_HANDLE_VALUE_NOTI events in your GATT handler (this is done in SimpleCentral_processGATTMsg in the SimpleCentral example of the SDK)
    - Enable notifications by writing to the CCCD characteristic of the peripheral.

    I would advise you to check if those steps are done in your project.

    Additionally, the reason why the nRFConnect app may be because the nRF app tries to read all characteristics upon a connection to cache its value. If some characteristics have a authentication requirement, this will prompt the passkey. 

    Kind regards,
    Maxence

  • Dear  
    Thanks for the quick response,

    1. I am working with:
      • Code Composer Studio: 12.0.0
      • SDK: simplelink_cc13xx_cc26xx_sdk_7_40_00_77
      • Example project: simple_central_CC1352R1_LAUNCHXL_tirtos7_ticlang
    2. GATT_RegisterForMsgs(selfEntity);
      This function is available in SimpleCentral_init.

    3. ATT_HANDLE_VALUE_NOTI is not handled in the default simple_central example, but I have modified
      static void SimpleCentral_processGATTMsg(gattMsgEvent_t *pMsg) as follows:
    else if (pMsg->method == ATT_HANDLE_VALUE_NOTI)
        {
          attHandleValueNoti_t *n = &pMsg->msg.handleValueNoti;
          char line[3*ATT_MTU_SIZE+32];
          uint16_t off = 0;
          off += snprintf(line+off, sizeof(line)-off, "NOTI h=0x%04x len=%u: ", n->handle, n->len);
          for (uint16_t i = 0; i < n->len && off+3 < sizeof(line); i++)
            off += snprintf(line+off, sizeof(line)-off, "%02X ", n->pValue[i]);
          Display_printf(dispHandle, 0, 0, "%s", line);
        }
        else if (pMsg->method == ATT_HANDLE_VALUE_IND)
        {
          attHandleValueInd_t *ind = &pMsg->msg.handleValueInd;
          char line[3*ATT_MTU_SIZE+32];
          uint16_t off = 0;
          off += snprintf(line+off, sizeof(line)-off, "IND  h=0x%04x len=%u: ", ind->handle, ind->len);
          for (uint16_t i = 0; i < ind->len && off+3 < sizeof(line); i++)
            off += snprintf(line+off, sizeof(line)-off, "%02X ", ind->pValue[i]);
          Display_printf(dispHandle, 0, 0, "%s", line);
          ATT_HandleValueCfm(pMsg->connHandle);
        }

    Please guide me find the mistake if i made.

    regards
    Surya

  • Hi !

    Do you enable notifications by writing 0x01 0x00 to the CCCD of your notification characteristic ?

    Kind regards,
    Maxence

  • Hi  
    yes, i do as follows 

    Function

    SimpleCentral_processGATTDiscEvent


    if case is 
    else if (discState == BLE_DISC_STATE_CHAR)

      {


    logic is 

    // Auto-enable notifications when CCCD available
          if (gCCCDHdl != 0)
          {
            uint8_t cccdVal[2] = { 0x01, 0x00 }; // NOTIFY enable

            attWriteReq_t req;
            req.handle = gCCCDHdl;
            req.len    = sizeof(cccdVal);
            req.pValue = cccdVal;
            req.sig    = 0;
            req.cmd    = 0;

            connList[connIndex].lastWriteKind = WRITE_KIND_CCCD;

            status_t s = GATT_WriteCharValue(scConnHandle, &req, selfEntity);
            if (s != SUCCESS)
            {
              connList[connIndex].lastWriteKind = WRITE_KIND_NONE;
              Display_printf(dispHandle, SC_ROW_CUR_CONN, 0, "CCCD write queue failed (status=0x%02x)", s);
            }
            else
            {
              gLastWriteHdl = gCCCDHdl; // <— critical so WriteRsp path knows
              Display_printf(dispHandle, SC_ROW_CUR_CONN, 0, "Writing CCCD @0x%04x (enable NOTIFY)", req.handle);
            }
          }

    Regards
    Surya
  • Hi,

    Do you have access to a sniffer ? That would be very useful for us to know if the notification is actually being sent by the peripheral.

    If you don't have a sniffer, you can also send me the project folder for your central and peripheral, assuming that they can both be flashed on a launchpad so that I can reproduce your issue.

    If your code for the peripheral and central cannot run on 2 launchpads, then you could try making a minimum reproducible example that I can have a look at.

    Kind regards,
    Maxence

  • Dear  

    Thank you for your continued support. I tested with a third-party peripheral device, so I don’t have the peripheral’s code. They suggested using only the nRF application, which works fine. However, I’m trying to implement the same functionality on a CC1352-based board (our own device). I can share my full project files for your review—please go through them and point out any mistakes or anything I may have missed.

    Regards,
    Surya

  • Hi,

    You add me as a friend in the E2E forums and then you'll be able to send me your code in private messages once I accept your request.
    I will test your code on the basic ble example of a CC2340 and see if I can reproduce your issue.

    Kind regards,
    Maxence

  • Hi,
    Please accept the friend request.

    regards
    Surya

  • Hi, sorry but I did not receive a friend request. Could you re-try ?

  • Hi  

    i have resend the request, please check...



    regards
    Surya

  • Hi,

    I added you

    KR, Max

  • Hi,
    Please check the personal message, i have shared my complete project file for your review.

    regards
    Surya

  • Hello Surya,

    Unfortunately, Maxence is out of office for the next few weeks. However, I can help you out. If you could send me your project I can attempt to review it myself!

    Best Regards,

    Tarek D

  • Hello  
    Please accept the friend request.

    regards
    Surya

  • Hello Surya,

    I've accepted your friend request. Please attach your project so that we can further debug this!

    Best Regards,

    Tarek D

  • Hi Tarek D,
    Please review the shared project file in personal message and let me know if I’ve made any mistakes, and advise me on how to resolve the issue.

    Regards
    Surya

  • Hello Surya,

    Sounds good! i will take a look at it and get back to you. Expect an update by Tuesday!

    Best Regards,

    Tarek D

  • Hi  
    I hope you checked the shared code, please let me know the status.

    Regards
    Surya

  • Hello  

    Any update on my request???

    Regards

    Surya

  • Hello Surya,

    Apologies for the delay here! I was able to take a look at your code, however I'm afraid the code has been modified too much to work with our generic basic_ble peripheral and will require a custom peripheral.

    Since you mentioned that you don't have the peripheral project, could you send me .hex or .out file that I can flash the CC2340 with to be able to further analyze this code?

    Best Regards,

    Tarek D

  • Hello  

    • Please ignore the code I previously shared. I need the CC1352 to start scanning automatically on power-up, list all discovered devices with their addresses, send a connection request, perform passkey pairing, and then read the advertising data. You may provide a working example in your own style or guide me step by step to achieve this.

    • I don’t have the CC2340 peripheral code. The instrument is from a third party, and their company policy does not allow them to share the firmware in any format.



      Regards
      Surya

  • Hi   

    Any Update????



    Regards
    Surya

  • Hello Surya,

    My apologies for the delay on this! Here's a complete explanation on how to subscribe to notifications. In this example, we are attempting to subscribe to the notifications of characteristic 0xFFF4 of the simple GATT profile found in the basic ble example. Here are the steps to accomplishing this:

    1. Discover the primary service by UUID:
      To do this, call the GATT_DiscPrimaryServiceByUUID() API once a link has been established. This will result in receiving the event ATT_FIND_BY_TYPE_VALUE_RSP

      uint8_t uuid[2] = {0xF0, 0xFF};
      GATT_DiscPrimaryServiceByUUID(gapEstMsg->connectionHandle, uuid, 2, BLEAppUtil_getSelfEntity());



    2. Discover all characteristics:
      Once we receive the ATT_FIND_BY_TYPE_VALUE_RSP event, we will need to parse the data received. Using this data, we will call 
      GATT_DiscAllChars, so that we find the start and end handles, which will be used later to find the CCCD. Calling this API will result in receiving the event ATT_READ_BY_TYPE_RSP.

          case ATT_FIND_BY_TYPE_VALUE_RSP:
          {
              uint16_t lastStart;
              uint16_t lastEnd;
        
              attFindByTypeValueRsp_t att = (attFindByTypeValueRsp_t)gattMsg->msg.findByTypeValueRsp;
             
              /* We need to build the 16-bit handles that we received when we discovered the service. */
              for (uint8_t i = 0; i < att.numInfo; i++)
              {
                  /* NOTE: We are in little endian, but the BUILD_UINT16 macro accounts for this */
      
                  /* The first two bytes will be start handle */
                  uint16_t attHandle = BUILD_UINT16(att.pHandlesInfo[i * 4], att.pHandlesInfo[i * 4 + 1]);
                  /* The second two bytes will be the end handle */
                  uint16_t endHandle = BUILD_UINT16(att.pHandlesInfo[i * 4 + 2], att.pHandlesInfo[i * 4 + 3]);
                  
                  lastStart = attHandle;
                  lastEnd = endHandle;
              }
      
              
              ClockP_sleep(2);
      
              bStatus_t bstatus = GATT_DiscAllChars(gattMsg->connHandle, lastStart, lastEnd, BLEAppUtil_getSelfEntity());
             
              if (bstatus == SUCCESS)
              {
                  MenuModule_printf(APP_MENU_PROFILE_STATUS_LINE , 0,"Call to DiscAllChars  SUCCEDDED");
      
              }else{
                  MenuModule_printf(APP_MENU_PROFILE_STATUS_LINE + display_index++, 0,"Call to DiscAllChars FAILED!!!");
              }
          }
          break;



    3. Discover all descriptors of the characteristic:
      Once we receive the ATT_READ_BY_TYPE_RSP event, we'll also need to parse the data received and find the handle of the characteristic we are looking for (in this case 0xFFF4), and the handle of the characteristic that follows it (in this case 0xFFF5). The reason we need the handle of the next characteristic is because when calling the API GATT_DiscAllCharDescs, the end handle is typically the next characteristics handle -1. Calling GATT_DiscAllCharDescs will result in receiving the event ATT_FIND_INFO_RSP.

          case ATT_READ_BY_TYPE_RSP:
          {
            att = (attReadByTypeRsp_t)gattMsg->msg.readByTypeRsp;
            uint16_t startHandle;
            uint16_t endHandle1;
      
      
              for (uint8_t i = 0; i < att.numPairs; i++)
              {
                  /* This is the Attribute Handle */
                  uint16_t attHandle = BUILD_UINT16(att.pDataList[i * att.len + 0], att.pDataList[i * att.len + 1]);
                  MenuModule_printf(APP_MENU_PROFILE_STATUS_LINE + display_index++, 0,"ATT Handle: %x", attHandle);
              
      
                  /* This is the index to the beginning of the value data AFTER the attribute handle */
                  uint8_t index = i * att.len + 2;
      
                  /* The characteristic value data */
                  uint8_t data1 = att.pDataList[index];     // Bit field of characteristic properties
      
                  uint8_t data2 = att.pDataList[index + 1]; // Second Byte of Characteristic Value Handle
                  uint8_t data3 = att.pDataList[index + 2]; // First Byte of Characteristic Value Handle
      
                  /* If we were using 128-bit Bluetooth UUIDs, then we would have 16 of these instead of 2. */
                  uint8_t data4 = att.pDataList[index + 3]; // Second byte of UUID
                  uint8_t data5 = att.pDataList[index + 4]; // First byte of UUID
                  uint16_t UUID=(uint16_t)(data5<<8)+data4;
      
                  /* Since we are in little endian, we have to reverse the order to make the values make sense. */
                  MenuModule_printf(APP_MENU_PROFILE_STATUS_LINE + display_index++, 0,"UUID: [%x]  %x%x Val Handle: %x%x Properties: %x",UUID, data5, data4, data3, data2, data1);
                  
                if(UUID==0xFFF4){
                  MenuModule_printf(APP_MENU_PROFILE_STATUS_LINE + display_index++, 0,"CHAR 0xFFF4 Discovered" );
      
                  // Get the handle of the 0xFFF4 char
                  startHandle = BUILD_UINT16(data2, data3);            
                }
      
                else if(UUID==0xFFF5)
                {
                  MenuModule_printf(APP_MENU_PROFILE_STATUS_LINE + display_index++, 0,"CHAR 0xFFF5 Discovered" );
      
                  // Get the handle fo the 0xFFF5 char
                  endHandle1 = BUILD_UINT16(data2, data3);
                  
                  // Call the GATT_DiscAllCharDesc()
                  ClockP_sleep(2);
                  tstatus = GATT_DiscAllCharDescs(gattMsg->connHandle, startHandle +1, endHandle1 - 1, BLEAppUtil_getSelfEntity());
                } 
              
              }
          }
          break;


    4. Subscribe to notifications:
      Once we receive the ATT_FIND_INFO_RSP event, we will need to parse the data one more time to find the handle of the CCCD whose uuid is 0x2902. Once we find it, we will call GATT_WriteCharValue to write a 1 to the CCCD and officially subscribe to the notification. Please note that you need to use GATT_bm_alloc to use this API.
          case ATT_FIND_INFO_RSP:
          {
            rsp = (attFindInfoRsp_t)gattMsg->msg.findInfoRsp;
            MenuModule_printf(APP_MENU_PROFILE_STATUS_LINE + display_index++, 0,"Event ATT_FIND_INFO_RSP Recieved");
      
              for (uint8_t i = 0; i < rsp.numInfo; i++)
              {
                  /* This is the Attribute Handle */
                  // uint16_t attHandle = BUILD_UINT16(att.pDataList[i * att.len + 0], att.pDataList[i * att.len + 1]);
                  uint16_t attHandle = BUILD_UINT16(rsp.pInfo[0], rsp.pInfo[1]);
      
                  MenuModule_printf(APP_MENU_PROFILE_STATUS_LINE + display_index++, 0,"ATT Handle: %x", attHandle);
              
      
                  /* This is the index to the beginning of the value data AFTER the attribute handle */
                  uint8_t index = i * rsp.numInfo + 2;
      
                  /* The characteristic value data */
                  uint8_t data1 = rsp.pInfo[index];     // UUID LSB
                  uint8_t data2 = rsp.pInfo[index + 1]; // UUID MSB
                  
                  uint16_t UUID = BUILD_UINT16(data1,  data2);
      
                  
                if(UUID==0x2902){
                  MenuModule_printf(APP_MENU_PROFILE_STATUS_LINE + display_index++, 0,"CCCD Discovered");
      
                  // Write to the CCCD
                  ClockP_sleep(3);
                  uint8_t val[2] = {0x01, 0x00};
                  attWriteReq_t writeReq;
      
                  writeReq.cmd = 0;
                  writeReq.handle = attHandle;
                  writeReq.len = 2;
                  writeReq.sig = 0;
                  connn = gattMsg->connHandle;
                  
                  writeReq.pValue = GATT_bm_alloc(gattMsg->connHandle, ATT_WRITE_REQ, writeReq.len, NULL);
                  if (writeReq.pValue) {
                    writeReq.pValue[0] = 0x01;   // notifications = 0x0001 (little-endian)
                    writeReq.pValue[1] = 0x00;
                    bStatus_t s = GATT_WriteCharValue(gattMsg->connHandle, &writeReq, BLEAppUtil_getSelfEntity());
                    if (s != SUCCESS) {
                      GATT_bm_free((gattMsg_t *)&writeReq, ATT_WRITE_REQ);
                    }
                  } 
                  
                } 
              
              }
          }
          break;



    5. Receive Notifications:
      If what we did earlier was successful, we should receive the event ATT_HANDLE_VALUE_NOTI, inside which will be the value of the notification sent.
          case ATT_HANDLE_VALUE_NOTI:
          {
             MenuModule_printf(APP_MENU_PROFILE_STATUS_LINE + display_index++, 0,"Received Notification");
          }

    Please note that all data is typically in little endian notation. Also, for the structure of the packets received, please refer to the official BLE specification, which outlines what to expect inside the data packets received.

    I hope this helps! Please let me know if you have any more questions or need any clarifications!

    Best Regards,

    Tarek D

  • Dear  
    It's okay — I didn't get a response for the last 10 days, so I thought to move the CC1352 peripheral to a Raspberry Pi and ordered one online; it's currently in transit. Thanks for your reply. You shared the steps for a 16-bit UUID, but my device uses a 128-bit UUID. I'll try to modify the code for the 128-bit UUID and let you know the result. Thanks again for the suggestions.

    Regards
    Surya

  • Hello,

    Understood! The changes needed for a 128-bit UUID should be minimal, but please let me know if you have any questions. Again, my apologies for the delay here!

    Best Regards,

    Tarek D

  • Hello  
    As instructed, I attempted to change the following macro in ti_ble_config.h:

    // TRUE to filter discovery results on desired service UUID
    #define DEFAULT_DEV_DISC_BY_SVC_UUID    false

    I changed it from false to true, but the change is automatically reverted when I build the project. I checked the SysConfig file for this setting but could not find it, so I redefined the macro in simple_central.c:

    #undef DEFAULT_DEV_DISC_BY_SVC_UUID
    #define DEFAULT_DEV_DISC_BY_SVC_UUID  true

    I called the scan function at the end of SimpleCentral_init() and added an else branch to handle devices without the target UUID:

    if (SimpleCentral_findSvcUuid128(pAdvRpt->pData, pAdvRpt->dataLen))
    {
        SimpleCentral_addScanInfo(pAdvRpt->addr, pAdvRpt->addrType);
        Display_printf(dispHandle, SC_ROW_NON_CONN, 0,
                       "Discovered: %s", Util_convertBdAddr2Str(pAdvRpt->addr));
    }
    else
    {
        char bdAddrStr[18];
        snprintf(bdAddrStr, sizeof(bdAddrStr), "%s", Util_convertBdAddr2Str(pAdvRpt->addr));
        Display_printf(dispHandle, 0, 0,
                       "NON_UUID_Discovered: %s:%s\r\n",
                       Util_convertBdAddr2Str(pAdvRpt->addr),
                       bdAddrStr);
    }
    

    The output prints only addresses. The cleaned log (control sequences removed) is below.

    Initialized
    Num Conns: 0
    ID Addr: 0xFCA89BECB290
    RP Addr: 0x46D282B625F4
    *Simple Central*
    Stop Discovering
    Discovering...
    NON_UUID_Discovered: 0x4340E9CD877A:0x4340E9CD877A
    NON_UUID_Discovered: 0x49724D900285:0x49724D900285
    NON_UUID_Discovered: 0x40791213A330:0x40791213A330
    NON_UUID_Discovered: 0x707F5D1604C8:0x707F5D1604C8
    NON_UUID_Discovered: 0x77FA82DD2698:0x77FA82DD2698
    NON_UUID_Discovered: 0x50DAE68BE6AC:0x50DAE68BE6AC
    RP Addr: 0x424704CFDBEE

    Note: In previous code, after finding a known device address we call the following to connect and get UUID details:

    if (knownPeerFound)
    {
        knownPeerFound = false;
    
        uint8_t pairMode = GAPBOND_PAIRING_MODE_INITIATE;
        GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode);
        uint8_t bondingEnabled = TRUE;
        GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bondingEnabled);
    
        eraseBondByAddr(knownPeerAddrType, knownPeerAddr);
    
        status_t status = GapInit_connect(knownPeerAddrType & MASK_ADDRTYPE_ID,
                                          knownPeerAddr,
                                          DEFAULT_INIT_PHY,
                                          CONNECTION_TIMEOUT);
    
        if (status == SUCCESS)
        {
            Display_printf(dispHandle, 0, 0, "Connecting to FM_ADDR...");
        }
        else
        {
            Display_printf(dispHandle, 0, 0, "Connect failed");
        }
    
        break;
    }
    

    Please check and let me know what I should do next. my known device address is 

    0x40791213A330, it's listed in the log.



    Regards
    Surya

  • Hello Surya,

    I apologize but I don't think I understood your question very well. If you are looking for the sequence of events for subscribing to a notification, it'll look like the following:

    1. Connect to the peripheral
    2. Initiate a service discovery using GATT_DiscPrimaryServiceByUUID().
    3. The previous function will result in receiving ATT_FIND_BY_TYPE_VALUE_RSP event. Inside this event, initiate a characteristic discovery using GATT_DiscAllChars.
    4. The previous function will result in receiving  ATT_READ_BY_TYPE_RSP. Inside this event, discover all the descriptors of your desired characteristic using GATT_DiscAllCharDescs
    5. The previous function will result in receiving ATT_FIND_INFO_RSP. Here, you'll use GATT_WriteCharValue to write 0x0001 to the CCCD to subscribe to the notification

    I included all relevant code in my previous response. Please use it as a starting point and make the necessary changes to interact with your GATT profile. The BLE spec will also be a very valuable resource here.

    Best Regards,

    Tarek D

  • Dear  

    Thanks for your suggestions. I’ll explain what I need.

    I am trying to connect to a CC2340-based flowmeter that uses a secure connection with a passkey.

    I call GapScan_enable(0, 0, 0); at the end of SimpleCentral_init() so devices are listed when the system powers up. The advertisements are handled in SimpleCentral_processAppMsg() under case SC_EVT_ADV_REPORT:.

    Because I couldn't find the macro in SysConfig, I redefined it as follows:

    #undef DEFAULT_DEV_DISC_BY_SVC_UUID
    #define DEFAULT_DEV_DISC_BY_SVC_UUID true

    With that change I discover devices and handle them like this:

    if (SimpleCentral_findSvcUuid128(pAdvRpt->pData, pAdvRpt->dataLen))
    {
      SimpleCentral_addScanInfo(pAdvRpt->addr, pAdvRpt->addrType);
      Display_printf(dispHandle, SC_ROW_NON_CONN, 0, "Discovered: %s", Util_convertBdAddr2Str(pAdvRpt->addr));
    }
    else
    {
      char bdAddrStr[18];
      snprintf(bdAddrStr, sizeof(bdAddrStr), "%s", Util_convertBdAddr2Str(pAdvRpt->addr));
      Display_printf(dispHandle, 0, 0, "NON_UUID_Discovered: %s:%s\r\n", Util_convertBdAddr2Str(pAdvRpt->addr), bdAddrStr);
    
      if (strcmp(bdAddrStr, FM_ADDR) == 0)
      {
        GapScan_disable();
        GapInit_connect(pAdvRpt->addrType & MASK_ADDRTYPE_ID, pAdvRpt->addr, DEFAULT_INIT_PHY, 0);
        Display_printf(dispHandle, SC_ROW_NON_CONN, 0, "Auto connecting to %s", bdAddrStr);
        SimpleCentral_addScanInfo(pAdvRpt->addr, pAdvRpt->addrType);
      }
    }
    

    I manually call the connect API as shown above. I then get GAP_LINK_ESTABLISHED_EVENT and see the connected message (Num Conns: 1).

    The code then goes into SimpleCentral_processPairState() and reaches the GAPBOND_PAIRING_STATE_ENCRYPTED branch:

    else if (state == GAPBOND_PAIRING_STATE_ENCRYPTED)
    {
      if (status == SUCCESS)
      {
        Display_printf(dispHandle, SC_ROW_CUR_CONN, 0, "Encryption success");
        uint16_t pairConn = pPairData->connHandle;
        bStatus_t pairStatus = GAPBondMgr_Pair(pairConn);
    
        if (pairStatus == SUCCESS)
        {
          Display_printf(dispHandle, SC_ROW_CUR_CONN, 0, "Pairing initiated on connHandle=0x%04x", pairConn);
        }
        else
        {
          Display_printf(dispHandle, SC_ROW_CUR_CONN, 0, "Pairing initiation failed, GAPBondMgr_Pair returned=0x%02x", pairStatus);
        }
    
        Display_printf(dispHandle, SC_ROW_CUR_CONN, 0, "pPairData->connHandle=0x%04x pPairData->status=0x%02x",
                       pPairData->connHandle, pPairData->status);
      }
      else
      {
        Display_printf(dispHandle, SC_ROW_CUR_CONN, 0, "Encryption failed: %d", status);
      }
    
      GAPBondMgr_GetParameter(GAPBOND_PAIRING_MODE, &pairMode);
    
      if ((autoConnect) && (pairMode == GAPBOND_PAIRING_MODE_INITIATE))
      {
        SimpleCentral_autoConnect();
      }
    }
    


    I modified this function to handle pairing, but pairing fails.

    Could you please guide me on how to initiate the connection with a passkey and complete pairing with the CC2340 flowmeter? Specifically, I need recommendations on:

    • Where/how to supply the passkey during the pairing process.

    • Any required GAPBondMgr configuration or callbacks to implement.

    • Typical mistakes that cause pairing to fail in this flow (e.g., wrong pairing mode, missing IO-capability settings, address type mismatches).

    Thanks in advance for your help.

    Best regards,
    Surya

  • Dear Team,
    Please respond to my quires!!!!

    regards
    Surya

  • Hello Surya,

    I'm a bit confused here, as the default examples should support pairing out of box. Please make sure that in sysconfig, inside the GapBondMgr settings, to check the "Bonding" box, and to make sure that one of the devices is initiating a pairing request.

    Best Regards,

    Tarek D

  • Dear  

    I enabled GAPBondMgr in SysConfig, but it did not initiate automatically. please advise how I can manually initiate pairing. Also, how can I obtain the connection handle (connHandle) required by the GAPBondMgr_Pair() function?

    Please review my previous reply where I explained, step by step, what I tried and where it failed.



    regards
    Surya

  • Hello Surya,

    Each connection typically has 1 connHandle. These are typically found and extracted from the data received when a GATT event occurs or when a connection even occurs. Please reference the code I provided earlier as example.

    As for initiating pairing, I have tested this on my end and it works fine. Please make sure that the other device can accept pairing requests.

    Best Regards,

    Tarek D

  • Dear  ,

    I received a GAP_LINK_ESTABLISHED_EVENT and can see numConn = 1 and the device address from the handler below. However, I’m unsure how to retrieve the connHandle for that connection. Could you please confirm the proper way to obtain or map the connection handle for the device (or point out where I should read it from in the event structure)?

    Connected to 0x40791213A330
    Num Conns: 1

    For reference, the handler I’m using is the GAP_LINK_ESTABLISHED_EVENT case in SimpleCentral_processAppMsg().

    Thanks,
    Surya

  • Hello Surya,

    There is only 1 connection handle for each BLE connection. As seen in the out of box simple_central example, here's how the connHandle is retrieved.

    I believe you accidently took it out when making changes.

    Best Regards,

    Tarek D