This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Configure the Advertising Channel

Hi all,

I'm programming nRF52833 with SDK17.

I want to use only one channel (for example 37) to broadcast advertising during advertise interval and also one channel of scanning. I have read some questions related to this but I don't know how to config them all. I tried to config them but when I compile it and use nRFconnect, I can't find my device. Here is my code. Can anyone check it for me for any idea?

I really need help for this! Thanks

Best regards,

static void advertising_init(void)
{
    ret_code_t    err_code;
    ble_advdata_t advdata;
    ble_advdata_t srdata;

    ble_uuid_t adv_uuids[] = {{LBS_UUID_SERVICE, m_lbs.uuid_type}};

    // Build and set advertising data.
    memset(&advdata, 0, sizeof(advdata));

    advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    advdata.include_appearance = true;
    advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
		int8_t tx_power = 0;
		advdata.p_tx_power_level = &tx_power;
    

    memset(&srdata, 0, sizeof(srdata));
    srdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    srdata.uuids_complete.p_uuids  = adv_uuids;

    err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
    APP_ERROR_CHECK(err_code);

    err_code = ble_advdata_encode(&srdata, m_adv_data.scan_rsp_data.p_data, &m_adv_data.scan_rsp_data.len);
    APP_ERROR_CHECK(err_code);

    ble_gap_adv_params_t adv_params;

    // Set advertising parameters.
    memset(&adv_params, 0, sizeof(adv_params));

    adv_params.primary_phy     = BLE_GAP_PHY_AUTO;
   // adv_params.duration        = APP_ADV_DURATION;
		adv_params.duration        = 0;
    adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
    adv_params.p_peer_addr     = NULL;
    adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
    adv_params.interval        = APP_ADV_INTERVAL;
    adv_params.channel_mask[0] = 255;
    adv_params.channel_mask[1] = 255;
    adv_params.channel_mask[2] = 255;
    adv_params.channel_mask[3] = 255;
    adv_params.channel_mask[4] = 251;


    err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &adv_params);
    APP_ERROR_CHECK(err_code);
}

  • Hi,

     Note that the definition of the ble_gap_ch_mask_t has the following comment: 

     * Every channel is represented with a bit positioned as per channel index defined in Bluetooth Core Specification v5.0,
     * Vol 6, Part B, Section 1.4.1. The LSB contained in array element 0 represents channel index 0, and bit 39 represents
     * channel index 39. If a bit is set to 1, the channel is not used.
    Which means that each channel is represented by a bit in the array which has in total 40 bits. In addition the BLE Core spec has the following mapping for the channels: 
    Which results in you setting the the last byte to = 0b11111011 to RF channel 37 to be the only channel to be used. However RF channel 37 is not the same as channel index 37 which is the advertising channel which "in reality" is RF channel 0. Try to enable one of the advertising channels. 
    best regards
    Jared
  • oh tks for your reply. I did it. Thank you so much 

    Best regards!!!!

Related