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.

CC2564 HCI_VS_Read_RSSI Connection Handle is different than ACL Connection Handle?

Other Parts Discussed in Thread: CC2564

Hi,

I'm using CC2564 to check if some of the already paired devices is nearby.

CC2564 is initiating connection and when connection is complete - measuring RSSI.

If only one device is paired, after successful connection it's ACL connection handle is 0x01. Passing this value to HCI_VS_Read_RSSI returns the correct RSSI value.

If two devices are paired with the module, connection attempt is made to both devices simultaneously. If both devices are in range, their connection handles are 0x01 and 0x02. Passing those values to HCI_VS_Read_RSSI returns the correct RSSI values. If first of the devices is out of range, connection to the second device completes successfully with connection handle 0x02 before connection to the first device to timeout.

Passing this connection handle (0x02) to HCI_VS_Read_RSSI will result in error "-2" (no connection), but passing 0x01 will return the correct RSSI.

If both devices are in range and connection to the second device completes before the connection to the first device RSSI values returned by HCI_VS_Read_RSSI are swapped.

Connection handle is the returned by HCI_Event_Data->Event_Data.HCI_Connection_Complete_Event_Data->Connection_Handle

I have double checked the connection handle with GAP_Query_Connection_Handle.

  • Hi,

    Can you confirm which MCU, the SDK release version and the BT service pack version?
    Can you please share a BT Logger log? Please see: processors.wiki.ti.com/.../CC256x_Logger_User_Guide

    Regards,
    Gigi Joseph.
  • Hi,

    Code is running on Stellaris Launchpad. MCU is LM4F120H5QR. BT stack version is CC256XM4BTBLESW-v1.2-R2. Code is built with GCC.

    I will be able to provide log on Monday. I'm attaching test code. In MainThread() function there are 2 BD_ADDR hardcoded. Replace them with BD_ADDR of your devices and switch off the bluetooth of first device.

    #include "HAL.h"                 /* Function for Hardware Abstraction.        */
    #include "HALCFG.h"              /* HAL Configuration Constants.              */
    #include "flash.h"
    #include "Main.h"
    
    #define LED_TOGGLE_RATE_SUCCESS                    (500) /* The LED Toggle    */
                                                             /* rate when the demo*/
                                                             /* successfully      */
                                                             /* starts up.        */
    
    #define MAX_ACL_CONNECTIONS                        (20)  /* Denotes the max   */
                                                             /* number of inquiry */
                                                             /* results.          */
    
    
    static unsigned int        			BluetoothStackID;    /* Variable which holds the Handle */
    														 /* of the opened Bluetooth Protocol*/
    														 /* Stack.                          */
    
       /* User to represent a structure to hold a BD_ADDR return from       */
       /* BD_ADDRToStr.                                                     */
    typedef char BoardStr_t[15];
    
    #define DEVICE_COUNT	2
    BD_ADDR_t BD_ADDRS[DEVICE_COUNT];
    
       /* Internal function prototypes.                                     */
    static void ToggleLED(void *UserParameter);
    
       /* HCI Sleep Mode Callback.                                          */
    //static void BTPSAPI HCI_Sleep_Callback(Boolean_t SleepAllowed, unsigned long CallbackParameter);
    
       /* Application Tasks.                                                */
    static void DisplayCallback(char Character);
    static unsigned long GetTickCallback(void);
    static void MeasureRSSI(void *UserParameter);
    static void MainThread(void);
    
    
       /* The following Toggles an LED at a passed in blink rate.           */
    static void ToggleLED(void *UserParameter)
    {
       HAL_LedToggle(0);
    }
    
       /* Displays a function error.                                        */
    static void DisplayFunctionError(char *Function, int Status)
    {
       Display(("\n%s Failed: %d.\r\n", Function, Status));
    }
    
       /* The following function is responsible for converting data of type */
       /* BD_ADDR to a string.  The first parameter of this function is the */
       /* BD_ADDR to be converted to a string.  The second parameter of this*/
       /* function is a pointer to the string in which the converted BD_ADDR*/
       /* is to be stored.                                                  */
    static void BD_ADDRToStr(BD_ADDR_t Board_Address, BoardStr_t BoardStr)
    {
       BTPS_SprintF((char *)BoardStr, "0x%02X%02X%02X%02X%02X%02X", Board_Address.BD_ADDR5, Board_Address.BD_ADDR4, Board_Address.BD_ADDR3, Board_Address.BD_ADDR2, Board_Address.BD_ADDR1, Board_Address.BD_ADDR0);
    }
    
       /* The following function is registered with the application so that */
       /* it can display strings to the debug UART.                         */
    static void DisplayCallback(char Character)
    {
       while(!HAL_ConsoleWrite(1, &Character))
          ;
    }
    
       /* The following function is registered with the application so that */
       /* it can get the current System Tick Count.                         */
    static unsigned long GetTickCallback(void)
    {
       return(HAL_GetTickCount());
    }
    
    static int connect(BD_ADDR_t BD_ADDR)
    {
       int Result = -1;
       Byte_t Status;
    
       /* First, check that valid Bluetooth Stack ID exists.                */
       if(BluetoothStackID)
       {
    		Result = HCI_Create_Connection(BluetoothStackID, BD_ADDR, (HCI_PACKET_ACL_TYPE_DM1 | HCI_PACKET_ACL_TYPE_DH1
    			| HCI_PACKET_ACL_TYPE_DM3 | HCI_PACKET_ACL_TYPE_DH3 | HCI_PACKET_ACL_TYPE_DM5 | HCI_PACKET_ACL_TYPE_DH5), 0, 0, 0, HCI_ROLE_SWITCH_LOCAL_MASTER_NO_ROLE_SWITCH, &Status);
    		if(!Result && Status)
    		{
    			DisplayFunctionError("Connection failed", Status);
    		}
    	}
    	
    	return Result;
    }
    
       /* The following function is responsible for processing HCI Mode     */
       /* change events.                                                    */
    static void BTPSAPI HCI_Event_Callback(unsigned int BluetoothStackID, HCI_Event_Data_t *HCI_Event_Data, unsigned long CallbackParameter)
    {
    	BoardStr_t					  BluetoothAddress;
    
    	/* Make sure that the input parameters that were passed to us are    */
    	/* semi-valid.                                                       */
    	if((BluetoothStackID) && (HCI_Event_Data))
    	{
    		/* Process the Event Data.                                        */
    		switch(HCI_Event_Data->Event_Data_Type)
    		{
    			case etMode_Change_Event:
    				break;
                
    			case etInquiry_Result_Event:
    				break;
    
    			case etInquiry_Complete_Event:
    				break;
    				
    			case etConnection_Complete_Event:
    				Display(("etConnection_Complete_Event\r\n"));
    				
    				BD_ADDRToStr(HCI_Event_Data->Event_Data.HCI_Connection_Complete_Event_Data->BD_ADDR, BluetoothAddress);
    				Display(("%s Connection handle: %d Status: %02X\r\n", BluetoothAddress, HCI_Event_Data->Event_Data.HCI_Connection_Complete_Event_Data->Connection_Handle, HCI_Event_Data->Event_Data.HCI_Connection_Complete_Event_Data->Status));
    				break;
    
    			case etDisconnection_Complete_Event:
    				Display(("etDisconnection_Complete_Event: %d, %d\r\n",HCI_Event_Data->Event_Data.HCI_Disconnection_Complete_Event_Data->Status, HCI_Event_Data->Event_Data.HCI_Disconnection_Complete_Event_Data->Reason));
    				break;
    				
    			case etAuthentication_Complete_Event:
    				Display(("etAuthentication_Complete_Event\r\n",HCI_Event_Data->Event_Data.HCI_Authentication_Complete_Event_Data->Status));
    				break;
    
    			case etLink_Key_Request_Event:
    				Display(("etLink_Key_Request_Event\r\n"));
    				break;
    				
    			case etLink_Key_Notification_Event:
    				Display(("etLink_Key_Notification_Event\r\n"));
    				break;
    				
    			case etReturn_Link_Keys_Event:
    				Display(("etReturn_Link_Keys_Event\r\n"));
    				break;
    
    			case etPIN_Code_Request_Event:
    				Display(("etPIN_Code_Request_Event\r\n"));
    				break;
    				
    			case etIO_Capability_Request_Event:
    				Display(("etIO_Capability_Request_Event\r\n"));
    				break;
    
    			default:
    				break;
          }
       }
    }
    
       /* The following function is responsible for opening the SS1         */
       /* Bluetooth Protocol Stack.  This function accepts a pre-populated  */
       /* HCI Driver Information structure that contains the HCI Driver     */
       /* Transport Information.  This function returns zero on successful  */
       /* execution and a negative value on all errors.                     */
    static void OpenStack()
    {
    	HCI_DriverInformation_t    HCI_DriverInformation;
    	int                        Result;
    	char                       BluetoothAddress[15];
    	BD_ADDR_t                  BD_ADDR;
    
    	/* First check to see if the Stack has already been opened.          */
    	if(!BluetoothStackID)
    	{
    		/* Configure the UART Parameters.                                    */
    		HCI_DRIVER_SET_COMM_INFORMATION(&HCI_DriverInformation, 1, VENDOR_BAUD_RATE, cpHCILL_RTS_CTS);
    		HCI_DriverInformation.DriverInformation.COMMDriverInformation.InitializationDelay = 100;
    
    		Display(("OpenStack().\r\n"));
    
    		/* Initialize the Stack                                        */
    		Result = BSC_Initialize(&HCI_DriverInformation, 0);
    		//Result = HCITR_COMOpen(HCI_DriverInformation,NULL,NULL);
    
    		/* Next, check the return value of the initialization to see if*/
    		/* it was successful.                                          */
    		if(Result > 0)
    		{
    			/* The Stack was initialized successfully, inform the user  */
    			/* and set the return value of the initialization function  */
    			/* to the Bluetooth Stack ID.                               */
    			BluetoothStackID = Result;
    			Display(("Bluetooth Stack ID: %d\r\n", BluetoothStackID));
    
    			/* Let's output the Bluetooth Device Address so that the    */
    			/* user knows what the Device Address is.                   */
    			if(!GAP_Query_Local_BD_ADDR(BluetoothStackID, &BD_ADDR))
    			{
    				BD_ADDRToStr(BD_ADDR, BluetoothAddress);
    				Display(("BD_ADDR: %s\r\n", BluetoothAddress));
    			}
    
    			/* Attempt to register a HCI Event Callback.          */
    			Result = HCI_Register_Event_Callback(BluetoothStackID, HCI_Event_Callback, (unsigned long)NULL);
    			if(Result <= 0)
    				Display(("HCI_Callback registration failed.\r\n"));
    			
    			/* Disable conections from other devices */
    			Result = GAP_Set_Connectability_Mode(BluetoothStackID, cmNonConnectableMode);
    			if(Result < 0)
    				Display(("GAP_Set_Connectability_Mode failed: %d.\r\n", Result));
    				
    			/* Set to non-discoverable mode */
    			Result = GAP_Set_Discoverability_Mode(BluetoothStackID, dmNonDiscoverableMode, 0);
    			if(Result < 0)
    				Display(("GAP_Set_Discoverability_Mode to dmNonDiscoverableMode failed.\r\n"));
    
    			/* Set to non-pairable mode */
    			Result = GAP_Set_Pairability_Mode(BluetoothStackID, pmNonPairableMode);
    			if(Result < 0)
    				Display(("GAP_Set_Pairability_Mode failed: %d.\r\n", Result));
    		}
    		else
    		{
    			/* The Stack was NOT initialized successfully, inform the   */
    			/* user and set the return value of the initialization      */
    			/* function to an error.                                    */
    			DisplayFunctionError("Stack Init", Result);
    
    			BluetoothStackID = 0;
    		}
    	}
    }
    
       /* The following function is the main user interface thread.  It     */
       /* opens the Bluetooth Stack and then drives the main user interface.*/
    static void MainThread(void)
    {
    	BTPS_Initialization_t         BTPS_Initialization;
    	//HCI_HCILLConfiguration_t      HCILLConfig;
    	//HCI_Driver_Reconfigure_Data_t DriverReconfigureData;
    
    															
    	/* Set up the application callbacks.                                 */
    	BTPS_Initialization.GetTickCountCallback  = GetTickCallback;
    	BTPS_Initialization.MessageOutputCallback = DisplayCallback;
    
    	/* Initialize BTPSKNRl.                                        */
    	BTPS_Init(&BTPS_Initialization);
    	
    	HAL_LedSet(0, 1);
    	
    	BD_ADDRS[1].BD_ADDR5 = 0x68;
    	BD_ADDRS[1].BD_ADDR4 = 0xEB;
    	BD_ADDRS[1].BD_ADDR3 = 0xAE;
    	BD_ADDRS[1].BD_ADDR2 = 0x3F;
    	BD_ADDRS[1].BD_ADDR1 = 0xBF;
    	BD_ADDRS[1].BD_ADDR0 = 0xE5;
    	
    	BD_ADDRS[0].BD_ADDR5 = 0xA0;
    	BD_ADDRS[0].BD_ADDR4 = 0x75;
    	BD_ADDRS[0].BD_ADDR3 = 0x91;
    	BD_ADDRS[0].BD_ADDR2 = 0x51;
    	BD_ADDRS[0].BD_ADDR1 = 0x48;
    	BD_ADDRS[0].BD_ADDR0 = 0xC9;
    	
    	OpenStack();
    	
    	for(int i=0; i<DEVICE_COUNT; i++)
    		connect(BD_ADDRS[i]);
    
    	/* We need to execute Add a function to measure RSSI of existing  */
    	/* connections.			                                        */
    	if(BTPS_AddFunctionToScheduler(MeasureRSSI, NULL, 1000))
    	{
    		Display(("Initialization - complete.\r\n"));
    		
    		/* Loop forever and execute the scheduler.                  */
    		while(1)
    			BTPS_ExecuteScheduler();
    	}
    }
    
       /* The following function is responsible for Measuring RSSI of all   */
       /* connected devices.                                                */
    static void MeasureRSSI(void *UserParameter)
    {
    	BoardStr_t					  BluetoothAddress;
    	int                           Result;
    	Byte_t						  Status;
    			
    	if(BluetoothStackID)
    	{
    		for(int i=0; i<DEVICE_COUNT; i++)
    		{
    
    			BD_ADDRToStr(BD_ADDRS[i], BluetoothAddress);
    
    			Word_t Connection_Handle;
    			Result = GAP_Query_Connection_Handle(BluetoothStackID, BD_ADDRS[i], &Connection_Handle);
    			if(!Result)
    				Display(("%s connection handle: %d\r\n", BluetoothAddress, Connection_Handle));
    			
    			Byte_t BufRSSI[32];
    			Byte_t Length = 32;
    			
    			Byte_t BufConnHandle[2];
    			ASSIGN_HOST_WORD_TO_LITTLE_ENDIAN_UNALIGNED_WORD(BufConnHandle, Connection_Handle);
    			
    			Result = HCI_Send_Raw_Command(BluetoothStackID, 0xFDFC >> 10, 0xFDFC & 0x3FF, 2, BufConnHandle, &Status, &Length, BufRSSI, TRUE);
    
    			if(Result == HCI_ERROR_CODE_NO_ERROR && Status == HCI_ERROR_CODE_NO_ERROR && BufRSSI[0] == HCI_ERROR_CODE_NO_ERROR)
    				Display(("%s RSSI %d -> %d\r\n", BluetoothAddress, Connection_Handle, BufRSSI[3]));
    			else
    				Display(("%s RSSI measurement failed!\r\n", BluetoothAddress));
    		}
    	}
    }
    
       /* The following is the Main application entry point.  This function */
       /* will configure the hardware and initialize the OS Abstraction     */
       /* layer, create the Main application thread and start the scheduler.*/
    int main(void)
    {
       /* Configure the hardware for its intended use.                      */
       HAL_ConfigureHardware(1);
       
       MainThread();
    
       while(1)
       {
          ToggleLED(NULL);
    
          BTPS_Delay(100);
       }
    }
    
    
    

  • Hi,

    I still need help on this. And I believe that there is a bug in HCI_VS_Read_RSSI.
    To summarize:
    1. Code is running on Stellaris Launchpad. MCU is LM4F120H5QR.
    2. BT stack version is CC256XM4BTBLESW-v1.2-R2
    3. Code is built with GCC
    4. I have tried with ServicePack from 1.2 to 1.5 - result is the same. I'm verifying for correct patch applied with HCI_VS_Read_Patch_Version (0xFF22). Build number for SP1.5 is 34.
    5. I could not get a meaningful log from BT Logger. I have tried on 3 different windows systems
    6. Sample code is attached in my previous post. All you need is development board with TIVA and CC2564B and one BT device (mobile phone).
    The problem summary:
    When connection is initiated from CC2564B to 2 BT devices simultaneously using HCI_Create_Connection, but first device to which connection attempt is performed is out of range, then ACL Connection handle assigned to second BT device is "2". Connection to 1-st BT device will timeout.
    Passing this connection handle (2) to HCI_VS_Read_RSSI will result in error "-2" (no connection), but passing "1" will return the correct RSSI for connection handle "2".
  • closing old thread. pls open new thread if issue still persists
    Saurabh
  • Hello,
    The issue is not resolved, please reopen the thread.
    Asking Ivaylo to share the BT Logger log.

    Thanks,
    Mizanur
  • Team,
    Did someone get a chance to look at this issue?
    They say they couldn't get a meaningful log from BT logger, but the sample code should help you to try to reproduce the issue.

    Thanks,
    Mizanur
  • Hello MRC,

    Please reopen in new thread with all relevant information.

    Br,
    Chen Loewy