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.

CC2541 Advertising not working

I have looked for any other forum post with this problem but I could not find anything.  Maybe someone has seen a similar issue.

Currently in my application, which is a modification of the KeyFobDemo, I set initial_advertising_enable = TRUE and I can see the device in BTool.  I have the button toggle advertising on/off so when I press the button the advertising turns off.  

However upon another button press the gapProfileState will be set to GAPROLE_ADVERTISING and it does go through the code that should set up advertising.  But I can not see the device in BTool or other on other Bluetooth devices.  

After some testing it also seems that if I do not start advertising on initialization I can not start advertising at all.  

Any help or insight would be appreciated.  I can post code snippets if needed, I did not change much from the basic KeyFobDemo code though.  

  • Hi David,

    So you are saying when you press the "Scan" button on Btool, you do not see any advertisements? Do you see it with our smartphone apps like SensorTag or BLE Multitool? Code snippets might help as well.

  • Zahid,

    Until I toggle advertising on  my device I can see it in BTool and on an iphone and an android device.  After toggling then no other master device can see advertisements from my device.  

    There is also no Bluetooth signals readable by a spectrum analyzer either.  But all code that I can see shows that advertisements are happening and no errors are returned.  

    This is the routine that happens on key press:

        if( gapProfileState != GAPROLE_CONNECTED )
        {
        
          uint8 current_adv_enabled_status;
          uint8 new_adv_enabled_status;
    
          //Find the current GAP advertisement status
          GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, &current_adv_enabled_status );
    
          if( current_adv_enabled_status == FALSE )
          {
            new_adv_enabled_status = TRUE;
          }
          else
          {
            new_adv_enabled_status = FALSE;
          }
    
          //change the GAP advertisement status to opposite of current status
          GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status );
        }

    Through debugging I can see that both gapProfileState and current_adv_enabled_status toggle correctly.  

    Here is the KeyFobApp_Init. 

    void KeyFobApp_Init( uint8 task_id )
    {
      keyfobapp_TaskID = task_id;
        
      VOID GAP_SetParamValue( TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL );  
      
      {
        uint8 initial_advertising_enable = TRUE;                                                            
    
        uint16 gapRole_AdvertOffTime = 0;
      
        uint8 enable_update_request = DEFAULT_ENABLE_UPDATE_REQUEST;
        uint16 desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
        uint16 desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL;
        uint16 desired_slave_latency = DEFAULT_DESIRED_SLAVE_LATENCY;
        uint16 desired_conn_timeout = DEFAULT_DESIRED_CONN_TIMEOUT;
       
        GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable );
        GAPRole_SetParameter( GAPROLE_ADVERT_OFF_TIME, sizeof( uint16 ), &gapRole_AdvertOffTime );
      
        GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( deviceName ), deviceName );
        GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData );
      
        GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_ENABLE, sizeof( uint8 ), &enable_update_request );
        GAPRole_SetParameter( GAPROLE_MIN_CONN_INTERVAL, sizeof( uint16 ), &desired_min_interval );
        GAPRole_SetParameter( GAPROLE_MAX_CONN_INTERVAL, sizeof( uint16 ), &desired_max_interval );
        GAPRole_SetParameter( GAPROLE_SLAVE_LATENCY, sizeof( uint16 ), &desired_slave_latency );
        GAPRole_SetParameter( GAPROLE_TIMEOUT_MULTIPLIER, sizeof( uint16 ), &desired_conn_timeout );
      }
      
      GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName );
    
      {
        uint32 passkey = 000000;
        uint8 pairMode = GAPBOND_PAIRING_MODE_INITIATE;
        uint8 mitm = TRUE;
        uint8 ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;
        uint8 bonding = TRUE;
        GAPBondMgr_SetParameter( GAPBOND_DEFAULT_PASSCODE, sizeof ( uint8 ), &passkey );
        GAPBondMgr_SetParameter( GAPBOND_PAIRING_MODE, sizeof ( uint8 ), &pairMode );
        GAPBondMgr_SetParameter( GAPBOND_MITM_PROTECTION, sizeof ( uint8 ), &mitm );
        GAPBondMgr_SetParameter( GAPBOND_IO_CAPABILITIES, sizeof ( uint8 ), &ioCap );
        GAPBondMgr_SetParameter( GAPBOND_BONDING_ENABLED, sizeof ( uint8 ), &bonding );
      }
    
      VOID GATT_InitClient(); 
      GATT_RegisterForInd( keyfobapp_TaskID );
      
      
      // Initialize GATT attributes
      GGS_AddService( GATT_ALL_SERVICES );         // GAP
      GATTServApp_AddService( GATT_ALL_SERVICES ); // GATT attributes
      DevInfo_AddService();   // Device Information Service
      ProxReporter_AddService( GATT_ALL_SERVICES );  // Proximity Reporter Profile
      Batt_AddService( );     // Battery Service
      SimpleProfile_AddService( GATT_ALL_SERVICES );
      SK_AddService( GATT_ALL_SERVICES );         // Simple Keys Profile
    
      keyfobProximityState = KEYFOB_PROXSTATE_INITIALIZED;
    
      // Initialize Tx Power Level characteristic in Proximity Reporter
      {
        int8 initialTxPowerLevel = 0;
        
        ProxReporter_SetParameter( PP_TX_POWER_LEVEL, sizeof ( int8 ), &initialTxPowerLevel );
      }
    
      keyfobAlertState = ALERT_STATE_OFF;
    
      // make sure buzzer is off
      buzzerStop();
      
      P0SEL = 0x08; // Configure Port 0 as GPIO, except P0.3 PWM
      P1SEL = 0; // Configure Port 1 as GPIO
      P2SEL = 0; // Configure Port 2 as GPIO
    
      P0DIR = 0xFF; // Port 0 pins output,
      P1DIR = 0xF2; // All port 1 pins (P1.0-P1.7) as output, except P1_0 button, P1_2/3 for STAT
      P2DIR = 0x1F; // All port 1 pins (P2.0-P2.4) as output
    
      P0 = 0; // All pins on port 0 to low 
      P1 = 0x01;   // All pins on port 1 to low except for P1.0 (buttons)
      P2 = 0;   // All pins on port 2 to low
      
      
      // initialize the ADC for battery reads
      HalAdcInit();
    
      // Register for all key events - This app will handle all key events
      RegisterForKeys( keyfobapp_TaskID );
    
    #if defined ( DC_DC_P0_7 )
    
      // Enable stack to toggle bypass control on TPS62730 (DC/DC converter)
      HCI_EXT_MapPmIoPortCmd( HCI_EXT_PM_IO_PORT_P0, HCI_EXT_PM_IO_PORT_PIN7 );
    
    #endif // defined ( DC_DC_P0_7 )
        
      // Setup a delayed profile startup
      osal_start_timerEx( keyfobapp_TaskID, KFD_START_DEVICE_EVT, STARTDELAY );
    }

    Is there any more code snippets that would be useful?  

  • This is strange. This works fine with unmodified code and hardware.

    I believe the issue is with setting port 0 as output high:

    P0 = 0x03; // All pins on port 0 to low except for P0.0 and P0.1 (buttons)

    If you look at the schematic of the keyfob, when the button is pressed, it pulls down the GPIO to gnd.

  • Zahid,

    Firstly, I am using my own hardware.  However i see the same problem on both the keyfob and my own board. 

    Second, please explain how the pin status would effect advertising. 

    I can set the pins back to the default keyfob settings and the issue still persists.   

  • Zahid,

    I found the issue.  I removed the lines that deal with LED functions from Hal_Sleep.  When I un-comment them and use the original Hal_sleep then my code works fine.  

    Can you explain why those lines are critical to Hal_Sleep?  I do not have LED's on my custom board and I would like to remove unused code.

  • I would need to see which lines were uncommented. I don't recommend changing the low level drivers unless necessary.

  • Hi i have similar Problem,

    I am shifted My project from ble stack 1.3.2 to ble stack 1.4. Now every things are working properly.

    My problem is:

    I am trying to connect my device with app. During that same sec i pressed key(which will work for 5 sec program). At this movement device changed into connected mode, but actually its not connected with my app.

    Device will maintaining this connected state for one min. After one minute device will automatically changed to advertising mode.

    My requirement is, device should advertise immediately(which is not happening at this movement).  

    I welcome your's suggestions.

    Best wishes with thanks.

    MANO MM