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

nRF52840 SDK 16 Peripheral Blinky with CODED PHY

What all do I need to modify in the Blinky peripheral (from SDK 16) with in order for the 840 DK to advertise and connect with CODED PHY in long range mode?

My code compiles but the advertising LED hasn't lit and I get a fatal error in the advertising parameters. The error I get is NRF_ERROR_INVALID_PARAM when calling sd_ble_gap_adv_set_configure. 

So far I've changed the primary and secondary phys to PHY_CODED and the properties type to BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_UNDIRECTED. 

Thank you for your time, 

Sam

  • Hi Sam

    The following advertising flag is necessary for your Coded PHY application to be discovered: adv_data.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

    What device is the central that you're trying to connect to? Are you sure that the central supports Coded PHY?

    Best regards,

    Simon

  • Simon,

    I already have that flag set to the value you described as I believe that's how it's set in the Nordic Blinky example fresh from SDK16. I haven't changed too much in the example code out of the box. 

    Don't really need to worry about the central right now because, as I mentioned, the peripheral example is still throwing an error. And therefore not advertising anyway. 

  • Hi Sam

    Can you upload a snippet of your advertising_init() function so I can take a proper look, it seems like one of the advertising parameters are not set correctly, but it's hard to guess which one without seeing it myself.

    Best regards,

    Simon

  • After some more digging I found this code snippet that modifies the scan response data as well as the advertising init function. This code does actually compile, does not throw any errors, I can observe the advertising LED is lit, and the I can see NRF_SUCCESS displayed in my debugging log. (where before I found NRF_INVALID_PARAM). However, still don't see the "Nordic_Blinky" in the nRF Connect App device queue and it won't connect to the Central Blinky example either. 

    Not totally sure why this works? Think it has something to do with setting the scan_req_notification = 1 ? But I'm not sure, can you explain what's going on here?

    static ble_gap_adv_data_t m_adv_data =
    {
        .adv_data =
        {
            .p_data = m_enc_advdata,
            .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX
        },
        .scan_rsp_data =
        {
    
    		.p_data = NULL,
            .len    = 0
            //.p_data = m_enc_scan_response_data,
            //.len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX			
    
        }
    };
    
    
    //...other init functions....
    //...skip to advertising init...
    
    static void advertising_init(void)
    {
    	
        ret_code_t    err_code;
    
        ble_advdata_t advdata =
        {
            .name_type          = BLE_ADVDATA_FULL_NAME,
            .flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE,
            .include_appearance = false,
        };	
    
        ble_advdata_t srdata;
    
        ble_uuid_t adv_uuids[] = {{LBS_UUID_SERVICE, m_lbs.uuid_type}};
    
        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);
    
    	ble_gap_adv_params_t adv_params =
        {
            .properties    =
            {
              .type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED,
            },
            .p_peer_addr   = NULL,
            .filter_policy = BLE_GAP_ADV_FP_ANY,
            .interval      = APP_ADV_INTERVAL,
            .duration      = 0,
    
            .primary_phy   = BLE_GAP_PHY_1MBPS, // Must be changed to connect in long range. (BLE_GAP_PHY_CODED)
            .secondary_phy = BLE_GAP_PHY_1MBPS,
            .scan_req_notification = 1,
        };
    
        adv_params.primary_phy     = BLE_GAP_PHY_CODED;
        adv_params.secondary_phy   = BLE_GAP_PHY_CODED;
    	adv_params.properties.type = BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_UNDIRECTED;
    	NRF_LOG_INFO("set adv to CODED PHY.");
    
        adv_params.duration        = APP_ADV_DURATION;    
        adv_params.p_peer_addr     = NULL;
        adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
        adv_params.interval        = APP_ADV_INTERVAL;
    
        err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &adv_params);
        APP_ERROR_CHECK(err_code);
    		
    }

  • Yes, I can explain! I'm sorry I didn't mention that initially, but extended advertising (which is necessary to run Coded PHY) does not support scan response packets, as it transfers extra data in the secondary channels instead. Setting the scan response data length to 0 will fix this. 

    Best regards,

    Simon

Related