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: After the Bluetooth connection, call the HCI_EXT_SetTxPowerDbmCmd function, the Bluetooth connection is disconnected and does not broadcast.

Part Number: CC2340R5

Hi team,

SDK version :7.40.00.64 

Version REV B chip

The customer uses the service to modify the power after Bluetooth connection, and also directly uses the function HCI_EXT_SetTxPowerDbmCmd to set it. It was found that when the program ran this function, it ran away (Bluetooth disconnected and there was no broadcast). So it can't be modified after Bluetooth connection?

case ADVERTISING_POWER_CHAR_UUID:
        if ( offset == 0 )
        {
        if ( len != 1 )
        {
        status = ATT_ERR_INVALID_VALUE_SIZE;
        }
        }
        else
        {
        status = ATT_ERR_ATTR_NOT_LONG;
        }
        if ( status == SUCCESS )
        {
            uint8 *pCurValue = (uint8 *)pAttr->pValue;

            if(pValue[0]<= ADVERTISING_POWER_8dB)
            {
              *pCurValue = pValue[0];
                switch (*pCurValue)
                {
                    case ADVERTISING_POWER_0dB:
                       Advertising_Power=0;
                       HCI_EXT_SetTxPowerDbmCmd(0,0);
                       break;

                    case ADVERTISING_POWER_1dB:
                       Advertising_Power=1;
                       HCI_EXT_SetTxPowerDbmCmd(1,0);
                       break;

                    case ADVERTISING_POWER_2dB:
                       Advertising_Power=2;
                       HCI_EXT_SetTxPowerDbmCmd(2,0);
                       break;

                    case ADVERTISING_POWER_3dB:
                       Advertising_Power=3;
                       HCI_EXT_SetTxPowerDbmCmd(3,0);
                       break;

                    case ADVERTISING_POWER_4dB:
                       Advertising_Power=4;
                       HCI_EXT_SetTxPowerDbmCmd(4,0);
                       break;

                    case ADVERTISING_POWER_5dB:
                       Advertising_Power=5;
                       HCI_EXT_SetTxPowerDbmCmd(5,0);
                       break;

                    case ADVERTISING_POWER_6dB:
                       Advertising_Power=6;
                       HCI_EXT_SetTxPowerDbmCmd(6,0);
                       break;

                    case ADVERTISING_POWER_7dB:
                       Advertising_Power=7;
                       HCI_EXT_SetTxPowerDbmCmd(7,0);
                       break;

                    case ADVERTISING_POWER_8dB:
                       Advertising_Power=8;
                       HCI_EXT_SetTxPowerDbmCmd(8,0);
                       break;

                    default:
                       Advertising_Power=0;
                       HCI_EXT_SetTxPowerDbmCmd(0,0);
                       break;
                }
                if(Last_Advertising_Power!=Advertising_Power)
                {
                   Last_Advertising_Power=Advertising_Power;
                   sysParas.advertisementPower=Advertising_Power;
                   BLEAppUtil_invokeFunction(do_para_save,NULL);
                }
            }
        }

And I also reappear the customer's problem. 

I added HCI_EXT_SetTxPowerDbmCmd(8,0); here, and found that the connection between the board and the mobile phone was disconnected, and the mobile phone could not scan the device.

In addition, I would like to know where this function is generally used. Is there any relevant routine description?

Thanks & Best regards,

Yolande

  • Hi Yolande,

    Thank you for reaching out. We will look into your thread and get back to you as soon as possible.

    Best Regards,

    Jan

  • Yolande, 

    Using the function HCI_EXT_SetTxPowerDbmCmd to set the power is the correct way to modify the power after a Bluetooth connection is made. One thing you want to ensure you do when using this function is to add the function before enabling advertisements. You can look at the TI BLE5-Stack API Documentation for more information on the command but there is not any relevant routine description I have to share. 

    Is the project this is being implemented in a custom project or one of the examples modified from the SDK?

    Best regards, 

    Luke

  • Hi Luke,

    The project is being implemented is the example basic_ble from the SDK.

    Thanks & Best regards,

    Yolande

  • Yolande,

    Looking at the screenshot you provided, moving the HCI_EXT_SetTxPowerDbmCmd(8,0) command before the BLEAppUtil_advStart() will likely give you more success as I mentioned before. You should do this prior to enabling advertisements for it to function as expected. 

    Thanks,

    Luke

  • Hi Luke,

    Modifying and adding functions during Peripheral_start() is indeed not dead, but after the connection, stop broadcasting, modify the  TX power, and turn on broadcasting, it will die.

    In addition, if the customer needs his own function to run all the time, is there any other way besides creating a task?

    Thanks & Best regards,

    Yolande

  • Yolande,

    Okay, I understand the issue you are seeing now. Let me bring this issue up with the internal team and see if there is an easy resolution.

    For creating a new function, the easiest way to implement this is by creating a task. There is more detail in the User's Guide within the Creating Additional ICall Enabled Tasks section as well as the additionally linked Tasks section.

    Best regards,

    Luke

  • Hi Luke,

    The customer creates a task to call the BLE API,he refer to the method in this link:https://dev.ti.com/tirex/explore/content/simplelink_lowpower_f3_sdk_7_40_00_64/docs/ble5stack/ble_user_guide/html/ble-stack-5.x/the-application-cc23xx.html#icall-initialization-and-registration

    void *threadFxn0(void *arg0)
    {
        // ******************************************************************
        // N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp
        // ******************************************************************
        // Register the current thread as an ICall dispatcher application
        // so that the application can send and receive messages.
        ICall_registerApp(&selfEntity1, &syncEvent1);
    
        // Register the current thread as an ICall dispatcher application
        // so that the application can send and receive messages.
    //    bleStack_createTasks();
    
    
        for(;;)
        {
            GPIO_write(CONFIG_GPIO_Red,0);
            vTaskDelay(500);
            GPIO_write(CONFIG_GPIO_Red,1);
            vTaskDelay(500);
        }
    }
    
    void *threadFxn1(void *arg0)
    {
        // ******************************************************************
        // N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp
        // ******************************************************************
        // Register the current thread as an ICall dispatcher application
        // so that the application can send and receive messages.
        ICall_registerApp(&selfEntity1, &syncEvent1);
    
        // Register the current thread as an ICall dispatcher application
        // so that the application can send and receive messages.
    //    bleStack_createTasks();
    
    
        for(;;)
        {
            GPIO_write(CONFIG_GPIO_Green,0);
            vTaskDelay(500);
            GPIO_write(CONFIG_GPIO_Green,1);
            vTaskDelay(500);
        }
    }
    
    void *mainThread(void *arg0)
    {
        pthread_t thread0,thread1;
        pthread_attr_t attrs;
        struct sched_param priParam;
        int retc;
        int detachState;
    
        /* Create application threads */
        pthread_attr_init(&attrs);
    
        detachState = PTHREAD_CREATE_DETACHED;
        /* Set priority and stack size attributes *///设置优先级和堆栈大小属性
        retc        = pthread_attr_setdetachstate(&attrs, detachState);//设置线程分离状态
        if (retc != 0)
        {
            /* pthread_attr_setdetachstate() failed */
            while (1) {}
        }
    
        retc |= pthread_attr_setstacksize(&attrs, THREADSTACKSIZE);
        if (retc != 0)
        {
            /* pthread_attr_setstacksize() failed */
            while (1) {}
        }
    
        /* Create threadFxn0 thread */
        priParam.sched_priority = 0;
        pthread_attr_setschedparam(&attrs, &priParam);
    
        retc = pthread_create(&thread0, &attrs, &threadFxn0, NULL);
        if (retc != 0)
        {
            /* pthread_create() failed */
            while (1) {}
        }
        priParam.sched_priority = 1;
        pthread_attr_setschedparam(&attrs, &priParam);
        retc = pthread_create(&thread1, &attrs, &threadFxn1, NULL);
        if (retc != 0)
        {
            /* pthread_create() failed */
            while (1) {}
        }
        // Register the current thread as an ICall dispatcher application
        // so that the application can send and receive messages.
        bleStack_createTasks();
        
        return (NULL);
    }

    All three functions were called, but the task could not run and did not enter the task loop. Please help me see if there is something wrong with this call, or is there something missing?

    Thanks & Best regards,

    Yolande

  • Yolande, 

    Let me look through the code you provided and get back to you on what may be causing you issues. 

    Thanks,

    Luke

  • Yolande, 

    I am not noticing any obvious issues in the code snippet provided. Could you provide any more context onto where this section of code is being added?

    Additionally, have you/the customer tried using the BLEAppUtil_invokeFunction() command yet to try and call these functions and enter the task loop? 

    Best regards,

    Luke