Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

sd_ble_gattc_write not working

Hi,

I am currently trying send value to a write characteristic of the server of a custom central device with a nrf52832 peripheral device. I have been able to connect with NRFConnect to the central device and write the characteristic and connect to NRFConnect with my peripheral device and write the characteristic of the NRFConnect server. I am using custom uuid, so i have based my code on the Nordic UART Service Client example.

To get things more clear, here is a screenshot of my NRFConnect configuration:

 

My problem is that when I connect the two devices together and not to nrfConnect. When I write the characteristic with the peripheral device, it doesn't seem's to be receive by the central device. I am using the ble_uts_c_string_send function and I am not getting any return error. I also try to check the BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE callback, but the gatt_status return me success  and the error_handle is not giving me any error to. I really what else I could verify to find my problem. 

I am using the 15.2.0 SDK. 

Parents
  • Hi.

    Have you tried to debug when you attempt to write?

    If ble_nus_c_string_send is unsuccessful it should trigger an error

    uint32_t ble_nus_c_string_send(ble_nus_c_t * p_ble_nus_c, uint8_t * p_string, uint16_t length)
    {
        VERIFY_PARAM_NOT_NULL(p_ble_nus_c);
    
        if (length > BLE_NUS_MAX_DATA_LEN)
        {
            NRF_LOG_WARNING("Content too long.");
            return NRF_ERROR_INVALID_PARAM;
        }
        if (p_ble_nus_c->conn_handle == BLE_CONN_HANDLE_INVALID)
        {
            NRF_LOG_WARNING("Connection handle invalid.");
            return NRF_ERROR_INVALID_STATE;
        }
    
        ble_gattc_write_params_t const write_params =
        {
            .write_op = BLE_GATT_OP_WRITE_CMD,
            .flags    = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE,
            .handle   = p_ble_nus_c->handles.nus_rx_handle,
            .offset   = 0,
            .len      = length,
            .p_value  = p_string
        };
    
        return sd_ble_gattc_write(p_ble_nus_c->conn_handle, &write_params);
    }
    

    As you can see in ble_nus_c.c, check if you get either NRF_ERROR_INVALID_PARAM or NRF_ERROR_INVALID_STATE when you try to debug.

    - Andreas

  • I am using the APP_ERROR_CHECK macro to make sure there is no error returned by the ble_nus_c_string_send function. The function is always returning NRF_SUCCESS.

  • Hi.

    Sorry for the late reply.

    I did not notice you tried to write from the peripheral to the central, the API ble_nus_c_string_send() is for the central UART. Can you try the equivalent API for the peripheral UART, ble_nus_string_send().

    There is more documentation on the Nordic UART Service API here.

    Best regards.

    Andreas

Reply Children
No Data
Related