How to Change data rate to 500kbps/125kbps

I am using nrf connect SDK version 2.0

Here, I have a option to change data rate to 1Mbps and 2Mbps,

I'm thinking by using  "CONFIG_BT_CTLR_PHY_CODED" we can change to 125 or 500 kbps, i'm not sure which one its going use as PHY Data rate?.

(by changing this one I can increase range(LOS) of BLE devices) 

Parents
  • Hi Amanda thanks for the reply,

    I'm trying to update the data rate using "bt_conn_le_phy_update" API in connected callback but returning error

    "failed to update = -5" like this and its updating 2Mbps as a data rate.

    here is a code snippet regarding that

    static void connected(struct bt_conn *conn, uint8_t conn_err)
    {
    
    	int err;
    	char addr[30];
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	if (conn_err)
    	{
    		LOG_INF("Failed to connect to %s (%d)", addr, conn_err);
    
    		if (default_conn == conn)
    		{
    			bt_conn_unref(default_conn);
    			default_conn = NULL;
    
    			err = bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE);
    			if (err)
    			{
    				LOG_ERR("Scanning failed to start (err %d)",
    						err);
    			}
    		}
    
    		return;
    	}
    
    	LOG_INF("Connected: %s", addr);
    
    	#if PHY_UPDATE
    	// TODO: need to remove
    	err = bt_conn_le_phy_update(&conn, &phy);
    	if (err) {
    		sprintf(bufff_data, "failed to update = %d\r\n", err);
    		send_through_uart(bufff_data);
    		// return err;
    	}
    	#endif
    
    	static struct bt_gatt_exchange_params exchange_params;
    
    	exchange_params.func = exchange_func;
    	err = bt_gatt_exchange_mtu(conn, &exchange_params);
    	if (err)
    	{
    		LOG_WRN("MTU exchange failed (err %d)", err);
    	}
    
    	err = bt_conn_set_security(conn, BT_SECURITY_L0); // BT_SECURITY_L2  ->  BT_SECURITY_L0
    	if (err)
    	{
    		LOG_WRN("Failed to set security: %d", err);
    
    		gatt_discover(conn);
    	}
    
    	// TODO: theja newly added
    	gatt_discover(conn);
    
    	err = bt_scan_stop();
    	if ((!err) && (err != -EALREADY))
    	{
    		LOG_ERR("Stop LE scan failed (err %d)", err);
    	}
    }
    
    static void disconnected(struct bt_conn *conn, uint8_t reason)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    	int err;
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	LOG_INF("Disconnected: %s (reason %u)", addr, reason);
    
    	if (default_conn != conn)
    	{
    		return;
    	}
    
    	bt_conn_unref(default_conn);
    	default_conn = NULL;
    
    	err = bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE);
    	if (err)
    	{
    		LOG_ERR("Scanning failed to start (err %d)",
    				err);
    	}
    }
    
    static void security_changed(struct bt_conn *conn, bt_security_t level,
    							 enum bt_security_err err)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	if (!err)
    	{
    		LOG_INF("Security changed: %s level %u", addr, level);
    	}
    	else
    	{
    		LOG_WRN("Security failed: %s level %u err %d", addr,
    				level, err);
    	}
    
    	gatt_discover(conn);
    }
    
    #if PHY_UPDATE
    uint8_t data_buff[50] = {'\0'};
    static const char *phy2str(uint8_t phy)
    {
    	switch (phy) {
    	case 0: return "No packets";
    	case BT_GAP_LE_PHY_1M: return "LE 1M";
    	case BT_GAP_LE_PHY_2M: return "LE 2M";
    	case BT_GAP_LE_PHY_CODED: return "LE Coded";
    	default: return "Unknown";
    	}
    }
    
    static void le_phy_updated(struct bt_conn *conn,
    			   struct bt_conn_le_phy_info *param)
    {
    	printk("LE PHY updated: TX PHY %s, RX PHY %s\n",
    	       phy2str(param->tx_phy), phy2str(param->rx_phy));
    
    	// TODO: need to remove
    	sprintf(data_buff, "LE PHY updated: TX PHY %s, RX PHY %s\n",phy2str(param->tx_phy), phy2str(param->rx_phy));
    	send_through_uart(data_buff);
    }
    #endif
    
    BT_CONN_CB_DEFINE(conn_callbacks) = {
    	.connected = connected,
    	.disconnected = disconnected,
    	.security_changed = security_changed,
    	#if PHY_UPDATE
    	.le_phy_updated = le_phy_updated
    	#endif
    	};

    I,m trying to change with this parameters

    static struct bt_conn_le_phy_param phy = {
        .options = BT_CONN_LE_PHY_OPT_CODED_S2,
        .pref_rx_phy = BT_GAP_LE_PHY_CODED,
        .pref_tx_phy = BT_GAP_LE_PHY_CODED
    };
  • Hi, 

    Do you also get <wrn> bt_hci_core: bt_hci_cmd_send_sync: opcode 0x2032 status 0x11 like this post? If so, try in prj.conf:
    CONFIG_BT_CTLR_PHY_CODED=y

    Does this help?

    -Amanda H.

  • Hi,

    I am already included it in prj.cofig file still i'm getting same error?

    CONFIG_BT_CTLR_PHY_CODED=
  • Are you using nRF52833DK or a custom board?

    Does the central board support coded phy and updating phy(CONFIG_BT_USER_PHY_UPDATE=y)? What HW does the central board use?

    -Amanda H.
     

Reply Children
Related