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.

CC2640R2F-Q1: AdverData updating through GapAdv_prepareLoadByHandle & GapAdv_loadByHandle

Part Number: CC2640R2F-Q1

Hi TI experts,

I am trying to update one part(actually rear part with 5 bytes long) of the AdvData array at any time when needed by using  GapAdv_prepareLoadByHandle & GapAdv_loadByHandle.

As usual, it works well, but sometimes, the AdvData has a little bit what I didn't mean, that is, the rear part of the AdvData has garbage data I didn't update.

This case happened where 125Kbps PHY packet is being used, while 1Mbps PHY packet didn't.

    case GAP_EVT_ADV_START:
      //Display_printf(dispHandle, SP_ROW_ADVSTATE, 0, "GAP_EVT_ADV_START");
      
      static uint8 button_pressed = KEYFOB_NO_BUTTON;

      if ( (which_button_pressed > KEYFOB_NO_BUTTON) && (button_pressed != which_button_pressed) )
        button_pressed = which_button_pressed;
      which_button_pressed = KEYFOB_NO_BUTTON;   
      
      if ( button_pressed )
      {
        if (++block_count > 12)
        {           
          block_count = 0;
          button_pressed = KEYFOB_NO_BUTTON;
          //Display_printf(dispHandle, SP_ROW_STATUS_1, 0, "advertising data for #1 is stopped");         
        }   

        advertData[19] = button_pressed;      
        advertData[20] = block_count;         
        Display_print2(dispHandle, 0, 0, "button value: %d updated to AdvData: %d", button_pressed, block_count);
       
        bStatus_t status = FAILURE;

        status = GapAdv_prepareLoadByHandle(advHandleLongRange, GAP_ADV_FREE_OPTION_DONT_FREE);
        //Display_print1(dispHandle, 0, 0, "GapAdv_prepareLoadByHandle: %x", status); ==> showed 0.
        HUFPERIPHERAL_ASSERT(status == SUCCESS);    
        //Display_printf(dispHandle, SP_ROW_STATUS_1, 0, "advertising data for #1 is freed");
        
        // Load advertising data for set #2 that is statically allocated by the app
        status = GapAdv_loadByHandle(advHandleLongRange, GAP_ADV_DATA_TYPE_ADV,
                                     sizeof(advertData), advertData);
        //Display_print1(dispHandle, 0, 0, "GapAdv_loadByHandle: %x", status);  ==> showed 0
        HUFPERIPHERAL_ASSERT(status == SUCCESS);    

        //Display_printf(dispHandle, SP_ROW_STATUS_1, 0, "advertising data for #1 is updated");
      }  

The below log is what I captured when a button is pushed.

Initialized
Set legacy scannable only advertising mode to #0
Set extended advertising parameters command to #1
loadByHandle advertising data for #1
Adv Set 0 enabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 1(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 2(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 3(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 4(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 5(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 6(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 7(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 8(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 9(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 10(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 11(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 12(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 0 updated to AdvData: 0(block count)
Adv Set 1 disabled
Adv Set 1 enabled

The below shows a wrong case I didn't want.

 \\

The below shows the normal case I expect.

// Advertisement data
static uint8_t advertData[] =
{
  // Flags: this field sets the device to use general discoverable
  // mode (advertises indefinitely) instead of general
  // discoverable mode (advertise for 30 seconds at a time)
  0x02,   // length of this data
  GAP_ADTYPE_FLAGS,
  DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,

  // service UUID, to notify central devices what services are included
  // in this peripheral
  0x03,   // length of this data
  GAP_ADTYPE_16BIT_MORE,      // some of the UUID's, but not all
  LO_UINT16(XXXPROFILE_SERV_UUID),
  HI_UINT16(XXXPROFILE_SERV_UUID),

  // service UUID, to notify central devices what services are included
  // in this peripheral
  0x03,   // length of this data
  GAP_ADTYPE_16BIT_MORE,      // some of the UUID's, but not all
  LO_UINT16(THROUGHPUT_SERVICE_SERV_UUID),
  HI_UINT16(THROUGHPUT_SERVICE_SERV_UUID),

  0x03,   // length of this data
  GAP_ADTYPE_16BIT_MORE,      // some of the UUID's, but not all
  LO_UINT16(TEMPERATURE_SERVICE_SERV_UUID),
  HI_UINT16(TEMPERATURE_SERVICE_SERV_UUID),  

  0x05,   // length of this data
  GAP_ADTYPE_MANUFACTURER_SPECIFIC,
  0xFF,
  0xFF,
  0x00,   // which_button_pressed adverData[19]
  0x00    // count (0 to 12)       adverData[20]
};

BR,

Ji Won Lee

  • Hi,

    How consistently does this happen? Can you try using GAP_EVT_ADV_END to see if the same issue occurs?

    Best wishes
  • Hi,

    At first, I used GAP_EVT_ADV_END case, but as far as I remember, it was worse than GAP_EVT_ADV_START. So, I moved my code to there.

    Thanks,
    JI Won

  • When using GAP_EVT_ADV_END case, no more GAP_EVT_ADV_START & GAP_EVT_ADV_END events after updating the advertising data.

    Initialized
    Set legacy scannable only advertising mode to #0
    Set extended advertising parameters command to #1
    loadByHandle advertising data for #1
    Adv Set 0 enabled
    Adv Set 1 enabled
    GAP_EVT_ADV_END
    GAP_EVT_ADV_START
    GAP_EVT_ADV_END
    GAP_EVT_ADV_START
    GAP_EVT_ADV_END
    GAP_EVT_ADV_START
    GAP_EVT_ADV_END
    GAP_EVT_ADV_START
    GAP_EVT_ADV_END
    GAP_EVT_ADV_START
    GAP_EVT_ADV_END
    GAP_EVT_ADV_START
    GAP_EVT_ADV_END
    GAP_EVT_ADV_START
    GAP_EVT_ADV_END
    GAP_EVT_ADV_START
    GAP_EVT_ADV_END
    GAP_EVT_ADV_START
    GAP_EVT_ADV_END
    GAP_EVT_ADV_START
    GAP_EVT_ADV_END
    GAP_EVT_ADV_START
    GAP_EVT_ADV_END
    GAP_EVT_ADV_START
    GAP_EVT_ADV_END
    button value: 2 updated to AdvData: 1
    Adv Set 1 disabled <-- generated by "GapAdv_prepareLoadByHandle"
    Adv Set 1 enabled <-- generated by "GapAdv_loadByHandle".

    BR,
    Ji Won
  • Hi TI experts,

    Could I have any updates?

    Thanks in advance,
    Ji Won
  • Hi Ji,

    Please use the attached file as an example to change ADV data:

    1067.simple_peripheral.c

    Best wishes

  • Thanks Zahid,

    Even though I utilized what you posted, but the result is the same one as I had.

    Please refer to the below captured picture.

    In normal case, there is no CRC issue and the manufacturer specific data is right.


    But, in wrong case, it has the CRC error and garbage data.


    Thanks a lot for your support.

    And sometimes, the below function call doesn't return. So, status didn't show anything.

           status = GapAdv_loadByHandle(advHandleLongRange, GAP_ADV_DATA_TYPE_ADV,  sizeof(advertData), advertData);

            if(status != SUCCESS)
            {
              Display_printf(dispHandle, SP_ROW_ADVSTATE+3, 0, "ADV change error: %d ", status);
            }
            else
            {
              Display_printf(dispHandle, SP_ROW_ADVSTATE+3, 0, "ADV change SUCCESS");
            } 

    BR,

    Ji Won

     

     

     

  • Hi TI experts,

    There is no touching from peripheral device, just non-connectable advertising with long range (with 125kbps PHY) started and GAP_EVT_ADV_START event is issued, but no more GAP_EVT_ADV_START event after some time.

    POWER_SAVING is not related with this issue. Even though it is disabled, but still no more event happens.


    Can you guide me what to monitor?

    BR,
    Ji Won