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

the problem of data sending by indication between s120 and and s110

hello everyone the softdevice used in my system are s110_nrf51822_7.1.0 and s120_nrf51822_1.0.1 the connect interval i set is 40ms.

my system refers the ble_app_hrs(s110) and ble_app_hrs_c(s120) example project. in the example ,data was sent by notification ,but in my project ,I want to use indication to send ecg data,for avoiding data missing during the transmition. So i replace the notification settings with indication as followed. in the ble_app_hrs_c(s120) ,I just change the cccd_configure function set cccd_val = enable ? BLE_GATT_HVX_NOTIFICATION : 0;

static uint32_t cccd_configure(uint16_t conn_handle, uint16_t handle_cccd, bool enable)
{
    LOG("[HRS_C]: Configuring CCCD. CCCD Handle = %d, Connection Handle = %d\r\n",      handle_cccd,conn_handle);

    tx_message_t * p_msg;
    uint16_t       cccd_val = enable ? BLE_GATT_HVX_INDICATION : 0;

    p_msg              = &m_tx_buffer[m_tx_insert_index++];
    m_tx_insert_index &= TX_BUFFER_MASK;

    p_msg->req.write_req.gattc_params.handle   = handle_cccd;
    p_msg->req.write_req.gattc_params.len      = WRITE_MESSAGE_LENGTH;
    p_msg->req.write_req.gattc_params.p_value  = p_msg->req.write_req.gattc_value;
    p_msg->req.write_req.gattc_params.offset   = 0;
    p_msg->req.write_req.gattc_params.write_op = BLE_GATT_OP_WRITE_REQ;
    p_msg->req.write_req.gattc_value[0]        = LSB(cccd_val);
    p_msg->req.write_req.gattc_value[1]        = MSB(cccd_val);
    p_msg->conn_handle                         = conn_handle;
    p_msg->type                                = WRITE_REQ;

    tx_buffer_process();
    return NRF_SUCCESS;
}

in the ble_app_hrs(s110) project i set char_md.char_props.indicate = 1 ,and in the ble_hrs_heart_rate_measurement_send fuction i set hvx_params.type = BLE_GATT_HVX_indication; the code was here:

memset(&cccd_md, 0, sizeof(cccd_md));

BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
cccd_md.write_perm = p_hrs_init->hrs_hrm_attr_md.cccd_write_perm;
cccd_md.vloc       = BLE_GATTS_VLOC_STACK;

memset(&char_md, 0, sizeof(char_md));

char_md.char_props.indicate = 1;
char_md.p_char_user_desc  = NULL;
char_md.p_char_pf         = NULL;
char_md.p_user_desc_md    = NULL;
char_md.p_cccd_md         = &cccd_md;
char_md.p_sccd_md         = NULL;

BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_HEART_RATE_MEASUREMENT_CHAR);

a

uint32_t ble_hrs_heart_rate_measurement_send(ble_hrs_t * p_hrs, uint8_t * ECG_data)
{
uint32_t err_code;

// Send value if connected and notifying
if (p_hrs->conn_handle != BLE_CONN_HANDLE_INVALID)
{
    uint8_t *               encoded_hrm;
    //uint16_t               len;
    uint16_t               hvx_len;
    ble_gatts_hvx_params_t hvx_params;
    //uint8_t                encoded_hrm1[MAX_HRM_LEN];
    //len     = hrm_encode(p_hrs, heart_rate, encoded_hrm1);
    hvx_len = MAX_HRM_LEN;
			encoded_hrm=ECG_data;	
    //encoded_hrm[1]=(uint8_t)len;
    memset(&hvx_params, 0, sizeof(hvx_params));
    
    hvx_params.handle   = p_hrs->hrm_handles.value_handle;
    hvx_params.type     = BLE_GATT_HVX_NOTIFICATION;
    hvx_params.offset   = 0;
    hvx_params.p_len    = &hvx_len;
    hvx_params.p_data   = encoded_hrm;
    
    err_code = sd_ble_gatts_hvx(p_hrs->conn_handle, &hvx_params);
    
}
else
{
    err_code = NRF_ERROR_INVALID_STATE;
}

return err_code;
}

the problem is when i use the central device enable the indication of hrm ,the ble_app_hrs(s110) device would disconnect and break down,even i couldn't do a system_reset by an external key interruput .But when i change the indication settings with notification ,the system works on succesfully. Does somebody come up with the same problem or konw the reason causing this? thank u very much.

Parents Reply Children
Related