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

Connecting to multiple devices as a central gives error 18 NRF_ERROR_CONN_COUNT

Hi,

I'm using the PCA10040 devkit and pc-ble-driver s132 v5.0 to act as a central to connect to three bluetooth peripherals I have. I've made no edits to the connectivity firmware and I have code based on the heart rate collector I've written on my desktop that uses the sd v5 api.

So far I've been able to connect and disconnect to devices, but when I attempt to connect to a second device while an active connection is still up, I get the error:

Connection Request Failed, reason 18

I've tried to change the role count to 2 in the "ble_cfg_set" function taken from heart rate collector:

  ble_cfg.gap_cfg.role_count_cfg.central_role_count = 2;

And still have this issue. I feel that I'm missing something important here, any ideas?
  • I believe I've found the solution. In the ble_cfg_set function we can add:

      memset(&ble_cfg, 0, sizeof(ble_cfg));
      ble_cfg.conn_cfg.conn_cfg_tag                     = conn_cfg_tag;
      ble_cfg.conn_cfg.params.gap_conn_cfg.conn_count   = MAX_PEER_COUNT;
      ble_cfg.conn_cfg.params.gap_conn_cfg.event_length = EVENT_LENGTH;
    
      error_code = sd_ble_cfg_set(m_adapter, BLE_CONN_CFG_GAP, &ble_cfg, ram_start);

    And this seems to work now. I'm unsure however about an appropriate value for the 'event_length' variable, so I'm just using BLE_GAP_EVENT_LENGTH_DEFAULT.

  • Hi, have you connected two or more devices? it doesnt work. 

    static uint32_t ble_cfg_set(uint8_t conn_cfg_tag)
    {
    const uint32_t ram_start = 0; // Value is not used by ble-driver
    uint32_t error_code;
    ble_cfg_t ble_cfg;

    // Configure the connection roles.
    memset(&ble_cfg, 0, sizeof(ble_cfg));

    ble_cfg.gap_cfg.role_count_cfg.adv_set_count = 1;//BLE_GAP_ADV_SET_COUNT_DEFAULT;
    ble_cfg.gap_cfg.role_count_cfg.periph_role_count = 0;
    ble_cfg.gap_cfg.role_count_cfg.central_role_count = MAX_PEER_COUNT; // MAX_PEER_COUNT = 3
    ble_cfg.gap_cfg.role_count_cfg.central_sec_count = 0;

    error_code = sd_ble_cfg_set(tuya_ble_port_adapter, BLE_GAP_CFG_ROLE_COUNT, &ble_cfg, ram_start);
    if (error_code != NRF_SUCCESS)
    {
    tuya_printf("sd_ble_cfg_set() failed when attempting to set BLE_GAP_CFG_ROLE_COUNT. Error code: 0x%02X\n", error_code);
    return error_code;
    }

    memset(&ble_cfg, 0x00, sizeof(ble_cfg));
    ble_cfg.conn_cfg.conn_cfg_tag = conn_cfg_tag;
    ble_cfg.conn_cfg.params.gap_conn_cfg.conn_count = MAX_PEER_COUNT;
    ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu = 247;
    ble_cfg.conn_cfg.params.gap_conn_cfg.event_length = 6;

    error_code = sd_ble_cfg_set(tuya_ble_port_adapter, BLE_CONN_CFG_GATT, &ble_cfg, ram_start);
    if (error_code != NRF_SUCCESS)
    {
    tuya_printf("sd_ble_cfg_set() failed when attempting to set BLE_CONN_CFG_GATT. Error code: 0x%02X\n", error_code);
    return error_code;
    }

    return NRF_SUCCESS;
    }

Related