Hi,
We are using the nrf52833 for development.
The first version of the program can connect to the discovery service normally. But we need to add some new features. And nRF connect will return Error 22 when connecting to the BLE device.
Hi,
We are using the nrf52833 for development.
The first version of the program can connect to the discovery service normally. But we need to add some new features. And nRF connect will return Error 22 when connecting to the BLE device.
This is new version code that I changed .
#define APP_BLE_OBSERVER_PRIO 3 /**< Application's BLE observer priority. You shouldn't need to modify this value. */ #define APP_BLE_CONN_CFG_TAG 1 /**< A tag identifying the SoftDevice BLE configuration. */ #define APP_ADV_INTERVAL_FAST 320 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 200 ms). */ #define APP_ADV_INTERVAL_SLOW 1600 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 1s). */ #define APP_ADV_DURATION 0 /**< The advertising duration in units of 10 milliseconds. 0 is to never stop. */ #define MIN_CONN_INTERVAL MSEC_TO_UNITS(100, UNIT_1_25_MS) //MSEC_TO_UNITS(25, UNIT_1_25_MS) /**< Minimum acceptable connection interval (0.4 seconds). */ #define MAX_CONN_INTERVAL MSEC_TO_UNITS(300, UNIT_1_25_MS)//MSEC_TO_UNITS(250, UNIT_1_25_MS) /**< Maximum acceptable connection interval (0.65 second). */ #define SLAVE_LATENCY 6 /**< Slave latency. */ #define CONN_SUP_TIMEOUT MSEC_TO_UNITS(5000, UNIT_10_MS)//MSEC_TO_UNITS(16000, UNIT_10_MS) /**< Connection supervisory time-out (4 seconds). */ #define FIRST_CONN_PARAMS_UPDATE_DELAY 5000 /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */ #define NEXT_CONN_PARAMS_UPDATE_DELAY 30000 /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */ #define MAX_CONN_PARAMS_UPDATE_COUNT 2 /**< Number of attempts before giving up the connection parameter negotiation. */
static void mk_gap_params_init(void) { static ret_code_t err_code; ble_gap_conn_params_t gap_conn_params; err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_GENERIC_TAG); APP_ERROR_CHECK(err_code); memset(&gap_conn_params, 0, sizeof(gap_conn_params)); gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL; gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL; gap_conn_params.slave_latency = SLAVE_LATENCY; gap_conn_params.conn_sup_timeout = CONN_SUP_TIMEOUT; err_code = sd_ble_gap_ppcp_set(&gap_conn_params); APP_ERROR_CHECK(err_code); }
m_code_t bsp_ble_adv_start(bsp_ble_adv_t * adv) { ret_code_t err_code = NRF_SUCCESS; if(adv == NULL) { return M_ADV_ERROR_ONOFF; } ble_gap_adv_data_t data; ble_gap_adv_params_t param; /*Update advertisement data.*/ data.adv_data.p_data = adv->data.legacy_p; data.adv_data.len = adv->data.legacy_len; if(adv->charact.rsp_enable == false) { data.scan_rsp_data.len = 0; } else { data.scan_rsp_data.p_data = adv->data.rsp_p; data.scan_rsp_data.len = adv->data.rsp_len; } /*Update parameters.*/ memset(¶m, 0, sizeof(ble_gap_adv_params_t)); err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle, adv->charact.tx_power); APP_ERROR_CHECK(err_code); if(adv->charact.connectable == true) { param.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED; } else { if(adv->charact.rsp_enable == true) param.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED; else param.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED; } param.p_peer_addr = NULL; // Undirected advertisement. param.filter_policy = BLE_GAP_ADV_FP_ANY; param.duration = 0; param.interval = BLE_GAP_ADV_INTERVAL_MAX; err_code = sd_ble_gap_adv_set_configure(&m_advertising.adv_handle, &data, ¶m); APP_ERROR_CHECK(err_code); err_code = sd_ble_gap_adv_start(m_advertising.adv_handle, APP_BLE_CONN_CFG_TAG); if(err_code != NRF_SUCCESS) { APP_ERROR_CHECK(err_code); } return M_SUCCESS; }
This is the old version code
#define APP_BLE_OBSERVER_PRIO 3 /**< Application's BLE observer priority. You shouldn't need to modify this value. */ #define APP_BLE_CONN_CFG_TAG 1 /**< A tag identifying the SoftDevice BLE configuration. */ #define APP_ADV_INTERVAL_FAST 320 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 200 ms). */ #define APP_ADV_INTERVAL_SLOW 1600 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 1s). */ #define APP_ADV_DURATION 0 /**< The advertising duration in units of 10 milliseconds. 0 is to never stop. */ #define MIN_CONN_INTERVAL MSEC_TO_UNITS(100, UNIT_1_25_MS) //MSEC_TO_UNITS(25, UNIT_1_25_MS) /**< Minimum acceptable connection interval (0.4 seconds). */ #define MAX_CONN_INTERVAL MSEC_TO_UNITS(300, UNIT_1_25_MS)//MSEC_TO_UNITS(250, UNIT_1_25_MS) /**< Maximum acceptable connection interval (0.65 second). */ #define SLAVE_LATENCY 6 /**< Slave latency. */ #define CONN_SUP_TIMEOUT MSEC_TO_UNITS(5000, UNIT_10_MS)//MSEC_TO_UNITS(16000, UNIT_10_MS) /**< Connection supervisory time-out (4 seconds). */ #define FIRST_CONN_PARAMS_UPDATE_DELAY 5000 /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */ #define NEXT_CONN_PARAMS_UPDATE_DELAY 30000 /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */ #define MAX_CONN_PARAMS_UPDATE_COUNT 2 /**< Number of attempts before giving up the connection parameter negotiation. */
static void gap_params_init(char *gap_name) { static ret_code_t err_code; ble_gap_conn_params_t gap_conn_params; ble_gap_conn_sec_mode_t sec_mode; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)gap_name, strlen(gap_name)); APP_ERROR_CHECK(err_code); err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_GENERIC_TAG); APP_ERROR_CHECK(err_code); memset(&gap_conn_params, 0, sizeof(gap_conn_params)); gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL; gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL; gap_conn_params.slave_latency = SLAVE_LATENCY; gap_conn_params.conn_sup_timeout = CONN_SUP_TIMEOUT; err_code = sd_ble_gap_ppcp_set(&gap_conn_params); APP_ERROR_CHECK(err_code); }
m_code_t bsp_ble_adv_start(void) { ret_code_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_SLOW); if(err_code != NRF_SUCCESS) { APP_ERROR_CHECK(err_code); } return M_SUCCESS; }
This is new version code that I changed .
#define APP_BLE_OBSERVER_PRIO 3 /**< Application's BLE observer priority. You shouldn't need to modify this value. */ #define APP_BLE_CONN_CFG_TAG 1 /**< A tag identifying the SoftDevice BLE configuration. */ #define APP_ADV_INTERVAL_FAST 320 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 200 ms). */ #define APP_ADV_INTERVAL_SLOW 1600 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 1s). */ #define APP_ADV_DURATION 0 /**< The advertising duration in units of 10 milliseconds. 0 is to never stop. */ #define MIN_CONN_INTERVAL MSEC_TO_UNITS(100, UNIT_1_25_MS) //MSEC_TO_UNITS(25, UNIT_1_25_MS) /**< Minimum acceptable connection interval (0.4 seconds). */ #define MAX_CONN_INTERVAL MSEC_TO_UNITS(300, UNIT_1_25_MS)//MSEC_TO_UNITS(250, UNIT_1_25_MS) /**< Maximum acceptable connection interval (0.65 second). */ #define SLAVE_LATENCY 6 /**< Slave latency. */ #define CONN_SUP_TIMEOUT MSEC_TO_UNITS(5000, UNIT_10_MS)//MSEC_TO_UNITS(16000, UNIT_10_MS) /**< Connection supervisory time-out (4 seconds). */ #define FIRST_CONN_PARAMS_UPDATE_DELAY 5000 /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */ #define NEXT_CONN_PARAMS_UPDATE_DELAY 30000 /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */ #define MAX_CONN_PARAMS_UPDATE_COUNT 2 /**< Number of attempts before giving up the connection parameter negotiation. */
static void mk_gap_params_init(void) { static ret_code_t err_code; ble_gap_conn_params_t gap_conn_params; err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_GENERIC_TAG); APP_ERROR_CHECK(err_code); memset(&gap_conn_params, 0, sizeof(gap_conn_params)); gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL; gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL; gap_conn_params.slave_latency = SLAVE_LATENCY; gap_conn_params.conn_sup_timeout = CONN_SUP_TIMEOUT; err_code = sd_ble_gap_ppcp_set(&gap_conn_params); APP_ERROR_CHECK(err_code); }
m_code_t bsp_ble_adv_start(bsp_ble_adv_t * adv) { ret_code_t err_code = NRF_SUCCESS; if(adv == NULL) { return M_ADV_ERROR_ONOFF; } ble_gap_adv_data_t data; ble_gap_adv_params_t param; /*Update advertisement data.*/ data.adv_data.p_data = adv->data.legacy_p; data.adv_data.len = adv->data.legacy_len; if(adv->charact.rsp_enable == false) { data.scan_rsp_data.len = 0; } else { data.scan_rsp_data.p_data = adv->data.rsp_p; data.scan_rsp_data.len = adv->data.rsp_len; } /*Update parameters.*/ memset(¶m, 0, sizeof(ble_gap_adv_params_t)); err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle, adv->charact.tx_power); APP_ERROR_CHECK(err_code); if(adv->charact.connectable == true) { param.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED; } else { if(adv->charact.rsp_enable == true) param.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED; else param.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED; } param.p_peer_addr = NULL; // Undirected advertisement. param.filter_policy = BLE_GAP_ADV_FP_ANY; param.duration = 0; param.interval = BLE_GAP_ADV_INTERVAL_MAX; err_code = sd_ble_gap_adv_set_configure(&m_advertising.adv_handle, &data, ¶m); APP_ERROR_CHECK(err_code); err_code = sd_ble_gap_adv_start(m_advertising.adv_handle, APP_BLE_CONN_CFG_TAG); if(err_code != NRF_SUCCESS) { APP_ERROR_CHECK(err_code); } return M_SUCCESS; }
This is the old version code
#define APP_BLE_OBSERVER_PRIO 3 /**< Application's BLE observer priority. You shouldn't need to modify this value. */ #define APP_BLE_CONN_CFG_TAG 1 /**< A tag identifying the SoftDevice BLE configuration. */ #define APP_ADV_INTERVAL_FAST 320 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 200 ms). */ #define APP_ADV_INTERVAL_SLOW 1600 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 1s). */ #define APP_ADV_DURATION 0 /**< The advertising duration in units of 10 milliseconds. 0 is to never stop. */ #define MIN_CONN_INTERVAL MSEC_TO_UNITS(100, UNIT_1_25_MS) //MSEC_TO_UNITS(25, UNIT_1_25_MS) /**< Minimum acceptable connection interval (0.4 seconds). */ #define MAX_CONN_INTERVAL MSEC_TO_UNITS(300, UNIT_1_25_MS)//MSEC_TO_UNITS(250, UNIT_1_25_MS) /**< Maximum acceptable connection interval (0.65 second). */ #define SLAVE_LATENCY 6 /**< Slave latency. */ #define CONN_SUP_TIMEOUT MSEC_TO_UNITS(5000, UNIT_10_MS)//MSEC_TO_UNITS(16000, UNIT_10_MS) /**< Connection supervisory time-out (4 seconds). */ #define FIRST_CONN_PARAMS_UPDATE_DELAY 5000 /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */ #define NEXT_CONN_PARAMS_UPDATE_DELAY 30000 /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */ #define MAX_CONN_PARAMS_UPDATE_COUNT 2 /**< Number of attempts before giving up the connection parameter negotiation. */
static void gap_params_init(char *gap_name) { static ret_code_t err_code; ble_gap_conn_params_t gap_conn_params; ble_gap_conn_sec_mode_t sec_mode; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)gap_name, strlen(gap_name)); APP_ERROR_CHECK(err_code); err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_GENERIC_TAG); APP_ERROR_CHECK(err_code); memset(&gap_conn_params, 0, sizeof(gap_conn_params)); gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL; gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL; gap_conn_params.slave_latency = SLAVE_LATENCY; gap_conn_params.conn_sup_timeout = CONN_SUP_TIMEOUT; err_code = sd_ble_gap_ppcp_set(&gap_conn_params); APP_ERROR_CHECK(err_code); }
m_code_t bsp_ble_adv_start(void) { ret_code_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_SLOW); if(err_code != NRF_SUCCESS) { APP_ERROR_CHECK(err_code); } return M_SUCCESS; }