Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Coded PHY for blinky peripheral and central

nRF52840 DKs with SDK 17.0.2, SoftDevice 7.2.0

The resources on this are starting to get a little scattered and possibly outdated. My long range use case is non-scannable, connectable blinky example without having to switch to 1MBPs to connect. Since I don't need to scan it, I'm assuming I can establish a connection at long range if the advertising and scan parameters are set correctly for the peripheral and central applications, respectively?

I believe I have these parameters and the config file set correctly but still not able to establish a connection at all, at any range. Looking through past posts, there's some conflicting solutions that have to do with the connectable, non-scannable scenario. 

Is there a better and more updated list of parameters to modify from a blinky application out-of-the-box (both peripheral and central) with in order to configure CODED PHY correctly and as the only PHY in use?

Thanks in advance,

Sam

  • Hi Sam,

    Yes, you can establish a connection with CODED PHY.  Please go over the 'diff' file below and let me know if you have done anything differently in your two projects. The diff is from a CODED PHY version of the blinky projects I made with SDK 16 a while ago.

    diff --git a/examples/ble_central/ble_app_blinky_c_coded_phy/main.c b/examples/ble_central/ble_app_blinky_c_coded_phy/main.c
    index 1b6a63a..788c3b9 100644
    --- a/examples/ble_central/ble_app_blinky_c_coded_phy/main.c
    +++ b/examples/ble_central/ble_app_blinky_c_coded_phy/main.c
    @@ -459,13 +459,25 @@ static void power_management_init(void)
     
     static void scan_init(void)
     {
    -    ret_code_t          err_code;
    +    ret_code_t err_code;
         nrf_ble_scan_init_t init_scan;
    +    ble_gap_scan_params_t params;
    +
    +    memset(&params, 0, sizeof(params));
    +
    +    params.active  = 1;
    +    params.interval = NRF_BLE_SCAN_SCAN_INTERVAL;
    +    params.window = NRF_BLE_SCAN_SCAN_WINDOW;
    +    params.timeout = NRF_BLE_SCAN_SCAN_DURATION;
    +    params.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL;
    +    params.scan_phys = NRF_BLE_SCAN_SCAN_PHY;
    +    params.extended = true;
     
         memset(&init_scan, 0, sizeof(init_scan));
     
         init_scan.connect_if_match = true;
         init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;
    +    init_scan.p_scan_param     = &params;
     
         err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
         APP_ERROR_CHECK(err_code);
    @@ -501,6 +513,8 @@ static void idle_state_handle(void)
     
     int main(void)
     {
    +    uint32_t err_code; 
    +
         // Initialize.
         log_init();
         timer_init();
    @@ -512,6 +526,10 @@ int main(void)
         gatt_init();
         db_discovery_init();
         lbs_c_init();
    +    
    +    /* Optional: set max tx output power */
    +    err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_SCAN_INIT, 0, 8); 
    +    APP_ERROR_CHECK(err_code);
     
         // Start execution.
         NRF_LOG_INFO("Blinky CENTRAL example started.");
    @@ -525,4 +543,4 @@ int main(void)
         {
             idle_state_handle();
         }
    -}
    +}
    \ No newline at end of file
    diff --git a/examples/ble_central/ble_app_blinky_c_coded_phy/pca10056/s140/config/sdk_config.h b/examples/ble_central/ble_app_blinky_c_coded_phy/pca10056/s140/config/sdk_config.h
    index 07e9848..9a06666 100644
    --- a/examples/ble_central/ble_app_blinky_c_coded_phy/pca10056/s140/config/sdk_config.h
    +++ b/examples/ble_central/ble_app_blinky_c_coded_phy/pca10056/s140/config/sdk_config.h
    @@ -154,7 +154,7 @@
     #endif
     // <o> NRF_BLE_SCAN_BUFFER - Data length for an advertising set. 
     #ifndef NRF_BLE_SCAN_BUFFER
    -#define NRF_BLE_SCAN_BUFFER 31
    +#define NRF_BLE_SCAN_BUFFER 1650
     #endif
     
     // <o> NRF_BLE_SCAN_NAME_MAX_LEN - Maximum size for the name to search in the advertisement report. 
    @@ -211,7 +211,7 @@
     // <255=> BLE_GAP_PHY_NOT_SET 
     
     #ifndef NRF_BLE_SCAN_SCAN_PHY
    -#define NRF_BLE_SCAN_SCAN_PHY 1
    +#define NRF_BLE_SCAN_SCAN_PHY 4
     #endif
     
     // <e> NRF_BLE_SCAN_FILTER_ENABLE - Enabling filters for the Scanning Module.
    
     
     // <q> NRF_FPRINTF_DOUBLE_ENABLED  - Enable IEEE-754 double precision formatting.
    @@ -7735,7 +7735,7 @@
     // <e> NRF_LOG_BACKEND_RTT_ENABLED - nrf_log_backend_rtt - Log RTT backend
     //==========================================================
     #ifndef NRF_LOG_BACKEND_RTT_ENABLED
    -#define NRF_LOG_BACKEND_RTT_ENABLED 0
    +#define NRF_LOG_BACKEND_RTT_ENABLED 1
     #endif
     // <o> NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE - Size of buffer for partially processed strings. 
     // <i> Size of the buffer is a trade-off between RAM usage and processing.
    diff --git a/examples/ble_peripheral/ble_app_blinky_coded_phy/main.c b/examples/ble_peripheral/ble_app_blinky_coded_phy/main.c
    index c698a48..fa89d59 100644
    --- a/examples/ble_peripheral/ble_app_blinky_coded_phy/main.c
    +++ b/examples/ble_peripheral/ble_app_blinky_coded_phy/main.c
    @@ -103,9 +103,8 @@ NRF_BLE_QWR_DEF(m_qwr);
     
     static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID;                        /**< Handle of the current connection. */
     
    -static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;                   /**< Advertising handle used to identify an advertising set. */
    -static uint8_t m_enc_advdata[BLE_GAP_ADV_SET_DATA_SIZE_MAX];                    /**< Buffer for storing an encoded advertising set. */
    -static uint8_t m_enc_scan_response_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX];         /**< Buffer for storing an encoded scan data. */
    +static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;                                      /**< Advertising handle used to identify an advertising set. */
    +static uint8_t m_enc_advdata[BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_MAX_SUPPORTED];         /**< Buffer for storing an encoded scan data. */
     
     /**@brief Struct that contains pointers to the encoded advertising data. */
     static ble_gap_adv_data_t m_adv_data =
    @@ -113,12 +112,12 @@ static ble_gap_adv_data_t m_adv_data =
         .adv_data =
         {
             .p_data = m_enc_advdata,
    -        .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX
    +        .len    = BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_MAX_SUPPORTED
         },
         .scan_rsp_data =
         {
    -        .p_data = m_enc_scan_response_data,
    -        .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX
    +        .p_data = NULL,
    +        .len    = 0
     
         }
     };
    @@ -223,29 +222,30 @@ static void advertising_init(void)
     
     
         memset(&srdata, 0, sizeof(srdata));
    -    srdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    -    srdata.uuids_complete.p_uuids  = adv_uuids;
    +    advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    +    advdata.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_1MBPS;
    +    adv_params.primary_phy     = BLE_GAP_PHY_CODED;
    +    adv_params.secondary_phy   = BLE_GAP_PHY_CODED;
         adv_params.duration        = APP_ADV_DURATION;
    -    adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
    +    adv_params.properties.type = BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_UNDIRECTED;
         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);
    +    /* Optional: set max tx output power */
    +    err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_adv_handle, 8);
    +    APP_ERROR_CHECK(err_code);
     }

    Best regards,

    Vidar

  • Thank you Vidar! This is great, I will sift through these later today. I can already see where I went wrong. Curious though, what would values be for NRF_BLE_SCAN_SCAN_INTERVAL, WINDOW, and DURATION? Are they unchanged from the default values the SDK gives?

    UPDATED: After making sure the above parameters were set correctly, I'm getting sporadic behavior from the DKs. They are constantly connecting and disconnecting. Apologies for not mentioning earlier but my central device is using the multilink example but configured for long range per diff file you sent. Could this behavior be cause by something in the multilink_c example? My only other thought is a difference from SDK 16 to 17 that is disrupting the long range configuration. 

    Your help is much appreciated. 

  • I left the scan paramaters unchanged, but you are free to adjust these if you want. The trade-off is discovery time vs power consumption.

    SRall said:
    I'm getting sporadic behavior from the DKs. They are constantly connecting and disconnecting

    This could be a symptom of an assertion in your code. Are you able to debug the multilink project and see if the program ends up in the app error handler function (see Error module)?

    Debugging with Assert with SES

  • Hey Vidar, 

    After some debugging I was able to resolve this behavior that was caused by an unrelated bug. Successfully able to make connections in CODED PHY now with the parameters you listed in your reply. 

    Many Thanks!

Related