Hello everyone,
I'm working in a ble project that use uart interface. When I sent string data in nrf connect app, the uart_event_handle is not called.
I started my project using ble_app_template, and the uart functions I copied by the ble_app_uart example.
The string that I need send my device using nrf connect app is: "z0,73,137,197,529;0.0,5.02,9.51,13.54,35.50"
I have some parameters that I sent to device, but are one letters, for example: "a" or "c" and it works fine.
Other information is that the ble_app_uart, this string was received correct and works fine, but in my project not.
This is my uart init function:
static void uart_init(void)
{
uint32_t err_code;
app_uart_comm_params_t const comm_params =
{
.rx_pin_no = NRF_UART_PSEL_DISCONNECTED,
.tx_pin_no = NRF_LOG_BACKEND_UART_TX_PIN,
.rts_pin_no = NRF_UART_PSEL_DISCONNECTED,
.cts_pin_no = NRF_UART_PSEL_DISCONNECTED,
.flow_control = APP_UART_FLOW_CONTROL_DISABLED,
.use_parity = false,
#if defined (UART_PRESENT)
.baud_rate = NRF_UART_BAUDRATE_115200
#else
.baud_rate = NRF_UARTE_BAUDRATE_115200
#endif
};
APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_event_handle,
APP_IRQ_PRIORITY_LOWEST,
err_code);
APP_ERROR_CHECK(err_code);
}
My uart_evt_handle 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') ||
(data_array[index - 1] == '\r') ||
(index >= m_ble_nus_max_data_len))
{
if (index > 1)
{
NRF_LOG_DEBUG("Ready to send data over BLE NUS");
NRF_LOG_HEXDUMP_DEBUG(data_array, index);
do
{
uint16_t length = (uint16_t)index;
err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
if ((err_code != NRF_ERROR_INVALID_STATE) &&
(err_code != NRF_ERROR_RESOURCES) &&
(err_code != NRF_ERROR_NOT_FOUND))
{
APP_ERROR_CHECK(err_code);
}
} while (err_code == NRF_ERROR_RESOURCES);
}
index = 0;
}
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;
}
}
Initialize NUS inside the services_init function:
// Initialize NUS. //todo ble_uart-------------------
memset(&nus_init, 0, sizeof(nus_init));
nus_init.data_handler = nus_data_handler;
err_code = ble_nus_init(&m_nus, &nus_init);
APP_ERROR_CHECK(err_code);
NRF_LOG_INFO("NUS inicializado e handler registrado.");
my nus_data_handler funcion:
static void nus_data_handler(ble_nus_evt_t * p_evt)
{
if (p_evt->type == BLE_NUS_EVT_RX_DATA)
{
NRF_LOG_INFO("Dados recebidos via BLE NUS:");
NRF_LOG_HEXDUMP_INFO(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
nus_Uart_control = p_evt->params.rx_data.p_data[0];
if (nus_Uart_control == 'z' || nus_Uart_control == 'y')
{
memset(&m_calib_recebida, 0, sizeof(m_calib_recebida));
if (parse_lut_data(p_evt->params.rx_data.p_data, &m_calib_recebida))
{
wait_for_calibration = true;
m_scale.calibrating = true;
m_scale.calibrating_offset = false;
}
else
{
NRF_LOG_ERROR("Falha no parse dos dados da LUT recebidos.");
}
}
}
}
and finally, my ble_evt_hander function
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
ret_code_t err_code = NRF_SUCCESS;
ble_gatts_rw_authorize_reply_params_t auth_reply;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
APP_ERROR_CHECK(err_code);
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
APP_ERROR_CHECK(err_code);
NRF_LOG_INFO("ble_evt_handler: BLE_GAP_EVT_CONNECTED ");//todo debug
break;
case BLE_GAP_EVT_DISCONNECTED:
m_conn_handle = BLE_CONN_HANDLE_INVALID;
NRF_LOG_INFO("ble_evt_handler: BLE_GAP_EVT_DISCONNECTED ");//todo debug
(void) sd_ble_gap_adv_stop(m_advertising.adv_handle); // <- PARA o advertising
advertising_start(false);
break;
case BLE_EVT_USER_MEM_REQUEST:
NRF_LOG_INFO("BLE_EVT_USER_MEM_REQUEST recebido, ignorado.");
break;
case BLE_GATTS_OP_EXEC_WRITE_REQ_NOW:
//NRF_LOG_INFO("ble_evt_handler: BLE_GATTS_OP_EXEC_WRITE_REQ_NOW ");//todo debug
break;
case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
NRF_LOG_DEBUG("PHY update request.");
ble_gap_phys_t const phys =
{
.rx_phys = BLE_GAP_PHY_AUTO,
.tx_phys = BLE_GAP_PHY_AUTO,
};
err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
APP_ERROR_CHECK(err_code);
break;
//-----------------------------------------------------------------------------------
default:
break;
}
}
if I send one letter "c", the result works:

But if I sent my string "z0,73,137,197,529;0.0,5.02,9.51,13.54,35.50" is ignored.

Anyone can help me to solve it?
Regards
Laerte