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: Required Reference to develope BLE Central+Peripheral Mode

Part Number: CC2340R5
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

Hello Experts,

I'm implementing BLE central +peripheral mode firmware for CC2340R5 with the data_stream example and I need to switch the mode form central to peripheral as per the signal read at gpio pin of BLE module. 

After switching the mode to central I need to connect to the peripheral by identifying the MAC address or UUID.

Please provide me the reference.

Thank you.

  • Hello Aman,

    Thanks for reaching out.

    Could you please confirm the SDK version as well as if you are using the Peripheral + Central configuration from SysConfig?

    BR,

    David.

  • Thanks for the response.

    The SDK version is - simplelink_lowpower_f3_sdk_8_10_01_02 and using the SysConfig.

  • Hello Aman,

    Could you please confirm if you are using the Peripheral + Central configuration from SysConfig or if you are configuring both roles in a different approach? Regarding the connection based on MAC address or UUID, I would suggest to use the Advertisement Report. I think this training material can be useful to understand how to retrieve the advertisement report: Bluetooth Low Energy Scanning and Advertising (See task 2: Scanning Task 2 – Print Scanning Results). See that the bleStk_GapScan_Evt_AdvRpt_t structure contains the pData. This two threads give more detail about how to do it:

    1. Using MAC address: https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1278585/cc2340r5-central-to-peripheral-automatically-connect
    2. Using UUID: https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1417988/cc2340r5-is-there-a-way-to-get-the-primary-services-uuid-from-a-server-without-connecting-to-it

    Hope it helps.

    David.

  • Hello David,

    Thank you for the input.

    I'm using the Peripheral+Central mode. And I want to switch the role as per the DIO input on the CC2340R5, The bluetooth should be in Peripheral mode when DIO pin is low and when the dio pin goes low then bluetooth should switch to the Central mode and start scanning for the nearby peripherals.

    I'm creating application over data_stream example when the bluetooth is in the peripheral mode. And when It switches mode from peripheral to central then It'll connect with the peripheral of data_stream service uuid. Now Central UART to Peripheral UART communication should be stablisehd. 

    In the central how can I write data  coming on UART to data_stream characteristic of peripheral and how to write data to central UART, data coming from peripheral?

    Please guide me about this, what references and approach I need to take.

    Thank you.

  • Hello Aman,

    Regarding your last question about how to do UART with BLE, I would suggest to take a look at our example here: data_stream_UART_over_BLE (this example is to demonstrate a UART over BLE example using the data_stream example as a base. The project is designed to allow the actual data sink and source to be easily exchanged for the purpose of creating a generic simple stream application), you can also check basic_ble_GATT_client for the central device however this one is based on basic_ble example.

    Regarding exchanging between peripheral + central, are you planing on also having two roles: server and client in the same device or is it only advertising and scanning features you want to enable/change through the GPIO button? If you can share with me a bit more of the application or use case that would be helpful.

    BR,

    David.

  • Hi, I'm using the data_stream with my application. Now I want to change the role to peripheral+central and then implement the client feature in it. So that I can change mode server to client and client to server as per the GPIO input. 

    Please help me with this. 

    Thank you.

  • Hello Aman,

    I would suggest to take a look at how the peripheral+central coexist in a multi-role example. You can enable this through SysConfig.

    I will check with the team of with have an example to change roles based on a interrupt, let me get back to you on this one.

    BR,

    David.

  • Hello David,

    I hope this message finds you well. I am currently working on implementing a client application within the data_stream project and aim to set up UART-BLE communication similar to the server setup in the same project.

    My objective is for the central device to transmit UART data to the data_stream's dataOut characteristic. Simultaneously, I need to ensure that any incoming data on the dataIn characteristic triggers a notification, allowing the central device to write this data to UART. I've attached screenshots to confirm if my current approach is correct.

    Could you please review the attached screenshots and confirm if this is the proper way to handle the communication? Additionally, could you provide any references or guidance on how to implement seamless point-to-point communication between two CC2340R5 devices configured in both Peripheral and Central roles with the data_stream project?

    Lastly, I need some assistance with where and how to register the callbacks necessary for notifying and writing to the data_stream characteristics.

    Thank you for your guidance and support.

  • Hello, 

    At first sight, and only looking at the content you have shared, it seems you are heading in the right direction. 

    If you were not already aware, you can consider the following resources to help you implement your solution: 

    https://github.com/TexasInstruments/ble_examples/tree/simplelink_low_power_f3_sdk-7.40.01/examples/rtos/LP_EM_CC2340R5/ble5stack/data_stream_UART_over_BLE - showcasing how to interface the data_stream example with UART

    https://github.com/TexasInstruments/ble_examples/tree/simplelink_low_power_f3_sdk-7.40.01/examples/rtos/LP_EM_CC2340R5/ble5stack/basic_ble_GATT_client - showcasing the implementation of a GATT client

    https://github.com/TexasInstruments/ble_examples/tree/simplelink_cc13xx_26xx_sdk-6.40/examples/rtos/LP_CC2651R3SIPA/ble5apps - showcasing both the UART over BLE client and server implemented on a different chipset

    I hope this will help,

    Best regards, 

  • Hello experts,

    I'm working on implementing a server-client feature with the CC2340R5 in a data stream project that involves both Peripheral and Central roles.

    As a Central device, I successfully connected to a Peripheral and obtained the connection handle. Now, I need to discover the specific service and characteristic handles available on the server.

    I have implemented the code for service discovery and am receiving the service discovery event. However, I am having difficulty retrieving the correct characteristic handles, as well as I'm not sure if start and end handles for the services are correct, Below I have added screenshot of logs printed on UART terminal

    Could you please provide reference code or guidance on how to correctly retrieve the service and characteristic handles? I am sharing the code here, and would appreciate any suggestions on improvements or changes that may be necessary.

    void discoverServices(void) {
        uint8_t serviceUuid[ATT_UUID_SIZE] = {TI_BASE_UUID_128(SIMPLESTREAMSERVER_SERV_UUID)};
        bStatus_t status;
        // Initiate service discovery
        vTaskDelay(pdMS_TO_TICKS(20));
        status = GATT_DiscPrimaryServiceByUUID(connHandle, serviceUuid, ATT_UUID_SIZE, BLEAppUtil_getSelfEntity());
        if (status != SUCCESS) {
            logError("Failed to initiate service discovery.");
        } else {
            UART2_write(uartHandle, "Service discovery initiated\n", strlen("Service discovery initiated\n"), NULL);
            vTaskDelay(pdMS_TO_TICKS(10));
        }
    
    
    }
    
    void discoverCharacteristics(void) {
        bStatus_t status;
        vTaskDelay(pdMS_TO_TICKS(20));
        status = GATT_DiscAllChars(connHandle, serviceStartHandle, serviceEndHandle, BLEAppUtil_getSelfEntity());
        if (status != SUCCESS) {
            logError("Failed to initiate characteristic discovery.");
        } else {
            UART2_write(uartHandle, "Characteristic discovery initiated\n", strlen("Characteristic discovery initiated\n"), NULL);
            vTaskDelay(pdMS_TO_TICKS(10));
        }
    }
    
    
    
    static void GATT_EventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
    {
      gattMsgEvent_t *gattMsg = ( gattMsgEvent_t * )pMsgData;
    
      char buffer[40]; // Adjust the size if needed
    
      switch ( gattMsg->method )
      {
       case ATT_FIND_BY_TYPE_VALUE_RSP:
          {
              if(gattMsg->msg.findByTypeValueRsp.numInfo > 0){
                  serviceStartHandle = ATT_ATTR_HANDLE(gattMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);
                  serviceEndHandle = ATT_GRP_END_HANDLE(gattMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);
                  if(serviceStartHandle != 0 && serviceEndHandle != 0){
                      snprintf(buffer, sizeof(buffer), "Start: 0x%x, End: 0x%x\n", serviceStartHandle, serviceEndHandle);
                      UART2_write(uartHandle, buffer, strlen(buffer), NULL);
                      vTaskDelay(pdMS_TO_TICKS(10));
                  }
              }
              else{
                  UART2_write(uartHandle, "No Service handle found\n", strlen("No handle found\\n"), NULL);
                  vTaskDelay(pdMS_TO_TICKS(20));
              }
          }
          discoverCharacteristics();
          break;
    
       case ATT_READ_BY_TYPE_RSP:
           if(gattMsg->msg.findInfoRsp.numInfo > 0)
               for (uint8_t i = 0; i < gattMsg->msg.readByTypeRsp.numPairs; i++)
               {
                   uint8_t *attrData = gattMsg->msg.readByTypeRsp.pDataList + (i * gattMsg->msg.readByTypeRsp.len);
                   uint16_t handle = BUILD_UINT16(attrData[0], attrData[1]);
                   uint16_t uuid = BUILD_UINT16(attrData[2], attrData[3]);
    
                   // Print the UUID and handle for each discovered characteristic
                   snprintf(buffer, sizeof(buffer), "UUID: 0x%x, Handle: 0x%x\n", uuid, handle);
                   UART2_write(uartHandle, buffer, strlen(buffer), NULL);
                   vTaskDelay(pdMS_TO_TICKS(10));
    
                   if (uuid == SIMPLESTREAMSERVER_DATAIN_UUID)
                   {
                       dataInCharHandle = handle;
                       UART2_write(uartHandle, "DataIn characteristic found\n", strlen("DataIn characteristic found\n"), NULL);
                       vTaskDelay(pdMS_TO_TICKS(10));
                   }
                   else if (uuid == SIMPLESTREAMSERVER_DATAOUT_UUID)
                   {
                       dataOutCharHandle = handle;
                       UART2_write(uartHandle, "DataOut characteristic found\n", strlen("DataOut characteristic found\n"), NULL);
                       vTaskDelay(pdMS_TO_TICKS(10));
                   }
               }
    
           else{
               UART2_write(uartHandle, "No Characteristics Handle Found\n", strlen("No Characteristics Handle Found\n"), NULL);
               vTaskDelay(pdMS_TO_TICKS(10));
           }
           break;
    
  • Hello Aman,

    Thanks for reaching out. I would kindly ask you to open a new thread with this question so that we can track it properly and so that others can also benefit from the answers.

    That being said, I would suggest to take a look at this training material in the meantime: https://dev.ti.com/tirex/explore/node?node=A__ATSMDAXx5vlu5FGTUknofQ__com.ti.SIMPLELINK_ACADEMY_CC13XX_CC26XX_SDK__AfkT0vQ__LATEST. Please consider it has been developed for a different family of devices, however the process should be similar. In addition, this thread can be of help: https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1396486/cc2340r5-how-to-handle-blepending-0x16-return-code/5354215#5354215

    BR,

    David.