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

Why is UART's data not sent to android?

Hello. Devzone engineers I'm testing Nordic_Uart. I have some issues. UART\s data not sent to android. Android app is nRFconneter and Example is nRF5_SDK_14.2.0_17b948a\nRF5_SDK_14.2.0_17b948a\examples\ble_peripheral\ble_app_uart After Notification enabled on the Android app, when data sent to the android through UART, the RF52832 is stopped and does not operate anything.

when debugging code of nRff52832, the part where the device stops are the following function.

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] == '\n') || (index >= (m_ble_nus_max_data_len)))
        {
            NRF_LOG_DEBUG("Ready to send data over BLE NUS");
            //NRF_LOG_HEXDUMP_DEBUG(data_array, index);
							recieved_data=malloc(sizeof(char)*index+1);
							memcpy(recieved_data,data_array,index);
							NRF_LOG_INFO("Recieved Data from TERMIAL %s",data_array);///In here. Receive data from serial Comm of PC terminal
							
						bsp_board_led_on(2);
            do
            {
                uint16_t length = (uint16_t)index;
									
                err_code = ble_nus_string_send(&m_nus, data_array, &length);
                if ( (err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) )
                {
                    APP_ERROR_CHECK(err_code);
                }
            } while (err_code == NRF_ERROR_BUSY);

							bsp_board_led_off(2);
            index = 0;
						recieved_flg=true;
        }
					
        break;

    case APP_UART_COMMUNICATION_ERROR:
        APP_ERROR_HANDLER(p_event->data.error_communication);
        break;

    case APP_UART_FIFO_ERROR:
        APP_ERROR_HANDLER(p_event->data.error_code);
        break;

    default:
        break;
}

}


uint32_t ble_nus_string_send(ble_nus_t * p_nus, uint8_t * p_string, uint16_t * p_length) { ble_gatts_hvx_params_t hvx_params;

VERIFY_PARAM_NOT_NULL(p_nus);
	uint32_t err_code = NRF_SUCCESS;
if ((p_nus->conn_handle == BLE_CONN_HANDLE_INVALID) || (!p_nus->is_notification_enabled))
{
    return NRF_ERROR_INVALID_STATE;
}

if (*p_length > BLE_NUS_MAX_DATA_LEN)
{
    return NRF_ERROR_INVALID_PARAM;
}

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

hvx_params.handle = p_nus->tx_handles.value_handle;
hvx_params.p_data = p_string;
hvx_params.p_len  = p_length;
hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
	
return sd_ble_gatts_hvx(p_nus->conn_handle, &hvx_params);

}

when running the sd_ble_gatts_hvx(p_nus->conn_handle, &hvx_params), device are stopped and disconnected from Android.

What's the reason? I hope to help me. Thank you for reading.

Related