52840 BLE_GAP_PHY_2MBPS not working

Hi,

Hello, I have a project that's working great but now I want to extend the abilities of the device by using the extended PHYs. I know there are a so many threads on this but I can't make any sense out of any of them.But some changes  i done 52840 BLE_GAP_PHY_1MBPS to BLE_GAP_PHY_2MBPS 

changes done in code 

1. In advertising_init() 

init.config.ble_adv_primary_phy = BLE_GAP_PHY_2MBPS;
init.config.ble_adv_secondary_phy = BLE_GAP_PHY_2MBPS;
2. In ble_evt_handler()
case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
NRF_LOG_DEBUG("PHY update request.");
ble_gap_phys_t const phys =
{
.rx_phys = BLE_GAP_PHY_2MBPS,
.tx_phys = BLE_GAP_PHY_2MBPS,
};
err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
APP_ERROR_CHECK(err_code);
break;
but it return error NRF_ERROR_INVALID_PARAM
how to solve it and run in 2mbps 

Parents Reply Children
  • Ok, that is because you are trying to tell the softdevice to use 2MBPS for it's advertising data. That is not allowed, according to the specification. The normal way to do this is to let it advertise as normal, and then switch over to 2MBPS after connecting to a central. Can you please try this? Just remove everything about the 2MBPS before you start advertising.

    Particularly these two:

    init.config.ble_adv_primary_phy = BLE_GAP_PHY_2MBPS;
    init.config.ble_adv_secondary_phy = BLE_GAP_PHY_2MBPS;

    Removing these may work. 

    Then you can set the BLE_GAP_EVT_PHY_UPDATE_REQUEST event like this:

            case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
            {
                NRF_LOG_DEBUG("PHY update request.");
                ble_gap_phys_t const phys =
                {
                    .rx_phys = BLE_GAP_PHY_AUTO,
                    .tx_phys = BLE_GAP_PHY_AUTO,
                };
                err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
                APP_ERROR_CHECK(err_code);
            } break;

    Note that it uses BLE_GAP_PHY_AUTO, but you can set it to 2MBPS to force it. However, this is not actively requesting 2MBPS. This is only what to reply if the other device requests a phy update.

    Then you can add something similar in your BLE_GAP_EVT_CONNECTED event:

            case BLE_GAP_EVT_CONNECTED:
                NRF_LOG_INFO("Connected");
                err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
                APP_ERROR_CHECK(err_code);
                m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
                err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
                APP_ERROR_CHECK(err_code);
                
                ble_gap_phys_t const phy_request =
                {
                    .rx_phys = BLE_GAP_PHY_2MBPS,
                    .tx_phys = BLE_GAP_PHY_2MBPS,
                };
                err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phy_request);
                APP_ERROR_CHECK(err_code);
                
                break;

    Best regards,

    Edvin

Related