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

Errorcode 13313 at sd_ble_gatts_hvx()

Hello, I would like to send an int32 value every 500ms and use for this the same procedure as it is shown in the heart-rate-example. The code for sending is:

// Send value if connected and notifying

if ((p_ad->conn_handle != BLE_CONN_HANDLE_INVALID) 
&& (p_ad->is_notification_supported))

    {
        uint8_t                encoded_adValue[10];
        uint16_t               hvx_len;
        ble_gatts_hvx_params_t hvx_params;

        hvx_len = uint32_encode(SActualValue.i32Value, encoded_adValue);

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

        hvx_params.handle = p_ad->ad_actualValue_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_adValue;

        err_code = sd_ble_gatts_hvx(p_ad->conn_handle, &hvx_params);
        if (err_code == NRF_SUCCESS)
        {
            err_code = NRF_ERROR_DATA_SIZE;
        }
    }
    else
    {
        err_code = NRF_ERROR_INVALID_STATE;
    }

    return err_code;

I suppose having initialized correctly everything (also in services_init()); looking at this forum I tried already the inclusion of

case BLE_GATTS_EVT_SYS_ATTR_MISSING:
       err_code = sd_ble_gatts_sys_attr_set(p_ble_evt->evt.gatts_evt.conn_handle, NULL, 0, 0);
       APP_ERROR_CHECK(err_code);
       break;

in the function on_ble_event() but when debugging with a breakpoint I see that this part of code is never reached... What can I do next?

  • First you are talking about an error code, and then about a part that is not reached. Which part is not reached? The sending part? I don't understand. Which SDK and SoftDevice version are you using? Error code 13313 is 0x3401 which is BLE_ERROR_GATTS_SYS_ATTR_MISSING. For how to handle it, see this.

  • Hello Petter, sorry for my late reply - I was on a business travel.

    What I wanted to say is that I was looking at the forum before posting my problem - I found at the post devzone.nordicsemi.com/.../ the information that the mentioned error code comes from a missing value for the CCCD: In this post a collegue of you recommended as one possible action to use the following code lines case BLE_GATTS_EVT_SYS_ATTR_MISSING: err_code = sd_ble_gatts_sys_attr_set(p_ble_evt->evt.gatts_evt.conn_handle, NULL, 0, 0); APP_ERROR_CHECK(err_code); break; which I have implemented in my code (in switch/case in function on_ble_evt()), but setting a breakpoint on that showed me that this code is never reached and by that can not help solve the problem... In the meantime I made some changes and now it works: One of the changes was to give more RAM to the S132 BLE stack; also some handles had to be changed. Finally I can't say any more which detail brought the solutions, but now it works! Thanks a lot!

  • // I am using SDK v14.2, NRF52832, S132, I have the same issue, too
    // m_nus register a event handler ble_nus_on_ble_evt() by using marco  BLE_NUS_DEF 
    BLE_NUS_DEF(m_nus); 
    // All event will be handled by ble_nus_on_ble_evt(), NOT only NUS related events
    // If BLE_GAP_EVT_CONNECTED event comes,
    // ble_nus_on_ble_evt() calls on_connect() then set p_nus->conn_handle to p_ble_evt->evt.gap_evt.conn_handle;
    // (ble_nus.c LN63)
     
    // That means "Any new connection will set m_nus.conn_handle to be the new connect handle"
    // to resolve this issue, i use following code
    // but this works only if you have only 1 peripheral
    static ble_nus_t m_nus;
    static void wrapper_ble_nus_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
    {
        uint16_t conn_handle;
        uint16_t role;
        ble_nus_t * p_nus = (ble_nus_t *)p_context;

        if ((p_nus == NULL) || (p_ble_evt == NULL)) {
            return;
        }

        conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
        role = ble_conn_state_role(conn_handle);

        if (role == BLE_GAP_ROLE_PERIPH) {
            ble_nus_on_ble_evt(p_ble_evt, p_context);
        }
    }
    NRF_SDH_BLE_OBSERVER(m_nus_obs, BLE_NUS_BLE_OBSERVER_PRIO, wrapper_ble_nus_on_ble_evt, &m_nus);
Related