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.

SimpleBLECentral CC2540 Read Advertising Data

Other Parts Discussed in Thread: CC2540, CC2541

I am using the CC2540 Mini DK and have the USB dongle as the central device and the KeyFob as the peripheral. I have the KeyFob update the advertisement data with the accelerometer positions as it is moved. I would like the USB to scan for these values and then print them to a file somewhere so I can track the movement. In order to do this, I want to start just by figuring out how to read the address of the connecting device (in this case, the peripheral device). How would I go about doing that?

I'm using the SimpleBLECentral code on the dongle . I know that a series of  "GAP_DEVICE_INFO_EVENT" events are added to the stack and that these have a type gapDeviceInfoevent_t. Inside this struct there is a pEvtData array which holds the advertisement data. However, when I flash the code to the dongle and have the KeyFob advertising, it doesn't recognize it and doesn't reach any of the GAP_DEVICE_INFO_EVENTS. 

If you have any specifics about reading the address of the peripheral device, writing this value to a file, or reading the advertising data, that would be helpful.

Thanks!

  • Hello. What you are describing is exactly what the simpleBLECentral does. One source of problem could be that you did not configure the simpleBLECentral project correctly for the USB dongle (i.e. using the correct HAL files).

    Also note that, by default, simpleBLECentral filters out all devices that don't advertise that they have the simpleGATTprofile. To remove this filtering, set DEFAULT_DEV_DISC_BY_SVC_UUID in simpleBLEcentral.c to FALSE.

    Assuming all goes well, you will receive advetisements in the application in the GAP_DEVICE_DISCOVERY_EVENT case of the simpleBLECentralEventCB.

  • Hey Tim,

    Thanks for the response! What is the proper file to flash the USB dongle with? I've been using:

    C:\Texas Instruments\BLE-CC254x-1.4.1.43908\Projects\ble\SimpleBLECentral\CC2541\CC2541EM\Exe\SimpleBLECentral.hex

    How/ Where can I write the advertising data to a file?
    Thanks so much!
  • By the way, I do not have the display or the HAL_KEY. I'm looking at the simpleBLECentral_HandleKeys() function and notice that this triggers the scanning to begin (or end). Is there a specific way to trigger scanning other than just calling;

    GAPCentralRole_StartDiscovery( DEFAULT_DISCOVERY_MODE,
    DEFAULT_DISCOVERY_ACTIVE_SCAN,
    DEFAULT_DISCOVERY_WHITE_LIST );

    Thanks!
  • Hello. There is no simpleBLEcentral USB configuation. You will need to create one. FYI a similar problem is being tackled here: e2e.ti.com/.../428291
  • Hey Tim,

    Thanks for getting back to me. Just to confirm, are you saying that I can't use the simpleBLECentral sample project as a starting point to program the USB dongle to scan for advertisements and then read the advertisement data? If not, would you recommend using the HostTestApp as a jumping point?

    Thanks for all your help!
  • As configured, no you can not use the default simpleBLECentral project. You would need to create a USB configuration. I now see your point from your previous post that you don't have keys or LCD so yes, you would need to embed this in the project.

    If you don't want to do this you can use the HostTestApp project and use the device as a network processor with HCI commands. I'm not really sure which approach would be easier. They both have their advantages and disadvantages.
  • Hey Tim,

    Thanks for the info! I now understand all that would be required to scan and read the advertisement data. However, I'm a little confused about the USB configuration. Would this be for the purpose of writing the incoming advertisement data? Is this USB configuration build into the HostTestApp and if so, could I just skim it off that? If not, how would I go about starting to creating the USB configuration
  • The USB configuration has nothing to do with transporting data over USB. It is only required so that the project will run correctly on the USB hardware. Yes, there is a USB configuration in the CC2540 HostTestApp project and I think that would be a good idea.
  • Thanks so much!
  • Hey Tim,

    I've updated the project with the same HAL files as in the HostTestApp in order to configure it properly with the USB hardware. However, the GAP_DEVICE_INFO_EVENT(s) are still never triggered. After GAP_DeviceDiscoveryRequest() is called, a SUCCESS (0x00) is returned so I believe that scanning is beginning properly. Any other ideas why the Device info events aren't getting triggered? I'm at a loss.

    Thanks so much
  • You may be doing this already but I would recommend using the GAPRole command GAPCentralRole_StartDiscovery().  GAP_DeviceDiscoveryRequest() is one layer down at the GAP layer. GAPRole handles some configuration, i.e.

    bStatus_t GAPCentralRole_StartDiscovery( uint8 mode, uint8 activeScan, uint8 whiteList )
    {
      gapDevDiscReq_t params;
    
      params.taskID = gapCentralRoleTaskId;
      params.mode = mode;
      params.activeScan = activeScan;
      params.whiteList = whiteList;
    
      return GAP_DeviceDiscoveryRequest( &params );
    }
    

    This is all explained in detail in the software developer guide included with the 1.4.1 stack (http://www.ti.com/blestack)

    If you are already doing this, than there could be a few possible problems:

    1. SimpleBLECentral, by default, filters out any devices that aren't advertising with the simpleGATTProfile in their advertising data. You can remove this by setting DEFAULT_DEV_DISC_BY_SVC_UUID in simpleBLEcentral.c to FALSE

    2. No devices are advertising. You can check this with a sniffer or a smartphone app.

  • Hey Tim,

    Thanks for the response. The way I'm starting the scanning is by triggering a discovery event at the beginning right after the START_DEVICE_EVT:


    // Setup a delayed profile startup
    osal_set_event( simpleBLETaskId, START_DEVICE_EVT );

    osal_set_event( simpleBLETaskId, START_DISCOVERY_EVT);


    I've updated the START_DISOVERY_EVENT so that it is:


    SimpleBLECentral_PerformAction ( START_SCAN );

    return ( events ^ START_DISCOVERY_EVT );



    As a side note, SimpleBLECentral_PerformAction is defined as:

    switch( action )
    {
    case START_SCAN:
    simpleBLEState = BLE_STATE_IDLE;
    simpleBLEScanning = FALSE; //make sure not scanning
    OnBoard_SendKeys( HAL_KEY_UP, 1); //start scanning
    break;
    case STOP_SCAN:
    simpleBLEScanning = TRUE; //make sure scanning
    simpleBLECentral_HandleKeys( 0, HAL_KEY_UP );
    break;
    default:
    break;
    }

    You'll notice that the OnBoard_SendKeys() function is called which triggers a Joystick up event (I don't physically have the joystick) and the joystick up event triggers the function:

    GAPCentralRole_StartDiscovery( DEFAULT_DISCOVERY_MODE,
    DEFAULT_DISCOVERY_ACTIVE_SCAN,
    DEFAULT_DISCOVERY_WHITE_LIST );


    I've set breakpoints and the code is reaching the StartDiscovery function and also I set the DEFAULT_DEV_DISC_BY_SVC_UUID in simpleBLEcentral.c to FALSE just in case. I set a breakpoint in the GAP_DEVICE_INFO_EVENT as well as triggered the LED, neither of which occur.

    Right before, I tested with BTool and found 6 devices advertising (including the KeyFob which I programmed with the KeyFob demo).

    Is what I've done a valid way to trigger that event? If not, how would you recommend starting scanning immediately?

    I really appreciate this help since I've tried almost everything and looked through previous forum posts and haven't found a solution yet.

    Thanks!
  • I think the best thing you can do is compare your initialization steps and events / return values received to the known working simpleBLECentral project for the SmartRF EM
  • Hey Tim,

    Thanks for the tip. The only tough part is that the simpleBLECentral is designed to start scanning when the Joystick is pushed up and since I don't have the Joystick I have no way to trigger this event with the code as it is given (out of the box). However, the only thing that I added to the provided code was the event to trigger the _StartDiscovery() function. Do you know of any way to test the original code without the Joystick?

    Thanks!
  • You can implement a state machine using something like a timer to start the original scanning.
  • Hey Tim,

    Thanks for the response. How would I go about doing that? I was trying to do that by setting the event directly after the device is started. Could you let me know how to start the original scanning with a timer?

    Thanks!
  • You can osal_set_event or osal_start_timer with a state machine. For more info, see the OSAL section from the SDG or the OSAL API guide included with the stack.