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

nrf51822 BLE disconnection problem

Hi, I'm using nrf51822 and ble_app_uart(SDK 12.3.0)

What I want to do is connect my board with nrf51822 and send data over UART

and send data to smartphone over BLE

UART data comes about 50bytes/sec

My problem is BLE connection is keep disconnected.

Actually, Hard to connect BLE at first. Sometimes do, Sometimes don't.

When it connected fortunately, It will disconnected soon.

Disconnecting time is unpredictable.

Sometimes smartphone receive data, sometimes don't.

I didn't changed sample code.

I'm new BLE, please help me..

Thanks!

void uart_event_handle(app_uart_evt_t * p_event){
static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
static uint8_t index = 0;
uint32_t       err_code;

switch (p_event->evt_type)
{
    case APP_UART_DATA_READY:
        UNUSED_VARIABLE(app_uart_get(&data_array[index]));
        index++;
        if ((data_array[index - 1] == '\r') || (index >= (BLE_NUS_MAX_DATA_LEN)))
        {
            err_code = ble_nus_string_send(&m_nus, data_array, index);
					
            if (err_code != NRF_ERROR_INVALID_STATE)
            {
                APP_ERROR_CHECK(err_code);
            }

image description

Parents
  • In addition, in function ble_nus_string_send()

        if ((p_nus->conn_handle == BLE_CONN_HANDLE_INVALID) || (!p_nus->is_notification_enabled))
    {
    		SEGGER_RTT_WriteString(0, "NRF_ERROR_INVALID_STATE\n");
        return NRF_ERROR_INVALID_STATE;
    }
    

    NRF_ERROR_INVALID_STATE occurs because of BLE_CONN_HANDLE_INVALID

    And when BLE connected with my phone, at on_ble_evt() in main.c

    BLE_GAP_EVT_CONNECTED occurs.

    When BLE connection is fine, If I press disconnect button in android app to disconnect on purpose, BLE_GAP_EVT_DISCONNECTED occurs.

    But When BLE disconnected abnormally. BLE_GAP_EVT_DISCONNECTED didn't occurs.

Reply
  • In addition, in function ble_nus_string_send()

        if ((p_nus->conn_handle == BLE_CONN_HANDLE_INVALID) || (!p_nus->is_notification_enabled))
    {
    		SEGGER_RTT_WriteString(0, "NRF_ERROR_INVALID_STATE\n");
        return NRF_ERROR_INVALID_STATE;
    }
    

    NRF_ERROR_INVALID_STATE occurs because of BLE_CONN_HANDLE_INVALID

    And when BLE connected with my phone, at on_ble_evt() in main.c

    BLE_GAP_EVT_CONNECTED occurs.

    When BLE connection is fine, If I press disconnect button in android app to disconnect on purpose, BLE_GAP_EVT_DISCONNECTED occurs.

    But When BLE disconnected abnormally. BLE_GAP_EVT_DISCONNECTED didn't occurs.

Children
No Data
Related