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.

CC2564C: Read RSSI values without Golden Threshold

Part Number: CC2564C
Other Parts Discussed in Thread: CC2564

I have the following code that returns a number which is above or below the Golden Receive Power Range.

int8_t BT_GetRSSI(void)
{
	SByte_t rssi;
        Byte_t Status;
	Word_t Connection_Handle, Connection_HandleStatus;
       if(GAP_Query_Connection_Handle(BluetoothStackID, dongle_bdaddr, &Connection_Handle) == 0)
       {
                if(HCI_Read_RSSI (BluetoothStackID, Connection_Handle, &Status, &Connection_HandleStatus, &rssi) == 0)
		{
			if(Status != 0 && Connection_HandleStatus != 0)
			{
				BT_Display(("Status: %d\r\n", Status));
				BT_Display(("Connection Handle: %d\r\n", Connection_HandleStatus));
				return 0x7F;
			}
			else
			{
				return rssi;
			}
		}
		else
		{
			BT_Display(("RSSI fail\r\n"));
			return 0x7F;
		}
	}
	
	return 0x7F;
}

This code works fine, but I need the raw value of the RSSI. According to Gigi Joseph the code above should give me the raw RSSI, but it doesn't. So, how do I get the raw RSSI values?

There is absolutely no sample code anywhere for this. Can you please give me some sample code that is working and complete?


  • Sean,

    There are 2 different commands that are mentioned in the linked thread above. I'll try to further clarify the differences.

    1. The HCI_Read_RSSI command - This command is part of the BT core spec and it is generic to all BT controllers (TI or non-TI) that support this command over HCI. The only catch is that it returns the RSSI of an ACL connection in terms of the golden range explained in the BT core spec document. This is the command you are currently using.

    2. The HCI_VS_Read_RSSI command- This command is specific to the TI dual-mode BT controllers (CC256x and WL18xx families). Hence, the vendor specific (VS) command. It returns the raw RSSI value of an ACL connection in dBm. This is the command that is referenced by Gigi in the linked thread above.

    VS command documentation : http://processors.wiki.ti.com/index.php/CC256x_VS_HCI_Commands#HCI_VS_Read_RSSI_.280xFDFC.29

    Please use this command in your implementation and you can get the raw RSSI value instead of the value relative to the golden range returned from the spec command. 

    Additionally, this command does not have an API built into the release, but you can add a new API in the BTVS.c of the TI dual-mode Bluetooth stack to implement this. Let me know if you need additional help with the implementation and I'll loop in the relevant experts to assist you with that.

    Best regards,

    Vihang

  • I got it working. Here is the code in case anybody needs it.

    Paste the following code into BTVS.c

    #define VS_READ_RSSI_OPCODE                         ((Word_t)(0xFDFC))

    int BTPSAPI VS_Read_RSSI(unsigned int BluetoothStackID, Word_t Connection_Handle, SByte_t *rssi)
    {
        int Result;
        Byte_t Length;
        Byte_t Status;
        Byte_t CommandBuffer[sizeof(Word_t)];
        Byte_t Buffer[4];
        Byte_t OGF;
        Word_t OCF;
        Byte_t ReturnLength;

        if((BluetoothStackID) && (HCI_CONNECTION_HANDLE_VALID_CONNECTION_HANDLE(Connection_Handle)))
        {
            OGF     = VS_COMMAND_OGF(VS_READ_RSSI_OPCODE);
            OCF     = VS_COMMAND_OCF(VS_READ_RSSI_OPCODE);
            ASSIGN_HOST_WORD_TO_LITTLE_ENDIAN_UNALIGNED_WORD(&CommandBuffer[0], Connection_Handle);
            Length  = sizeof(Word_t);
            ReturnLength = sizeof(Buffer);

            Result = HCI_Send_Raw_Command(BluetoothStackID, OGF, OCF, Length, CommandBuffer, 
                                                                       &Status, &ReturnLength, Buffer, TRUE);

            if((Result < 0) || (Status != 0))
                Result = BTPS_ERROR_VS_HCI_ERROR;
            else
                rssi[0] = (SByte_t)Buffer[3];
        }
        else
        {
            Result = BTPS_ERROR_INVALID_PARAMETER;
        }

        return Result;
    }

    Paste the prototype header into BTVSAPI.h

    BTPSAPI_DECLARATION int BTPSAPI VS_Read_RSSI(unsigned int BluetoothStackID, Word_t Connection_Handle, SByte_t *rssi);

    Note: You must pass a valid connection handler to the function VS_Read_RSSI(). Below is an example of how to use the function.

    int8_t BT_GetRSSI(void)
    {
        SByte_t rssi;
        Word_t Connection_Handle;

        if(GAP_Query_Connection_Handle(BluetoothStackID, dongle_bdaddr, &Connection_Handle) == 0)
        {
            if(VS_Read_RSSI(BluetoothStackID, Connection_Handle, &rssi) == 0)
            {
                 return rssi;
            }

             return 0x7F;
        }

        return 0x7F;
    }

     

    I use the function GAP_Query_Connection_Handle() that takes the MAC address and finds the corresponding connection handler. Once I have the handler 

    I can pass it into the function VS_Read_RSSI(). There is a better way to do this, however, keep a copy of the connection handler and you won't have to call 

    GAP_Query_Connection_Handle().

    If you're wondering why I use 0x7F, its because that would result in a signed value of 128 dBm, and there is no way for the CC2564 to generate that

    much power, according to the datasheet its maximum transfer power is +12 dBm. So I know if 0x7F is returned it must be wrong and I ignore it.

    Hope it helps