I am running ble_uart_app in SDK_11 s130 on nRF51-dk
I am trying to detect certain pattern received in the UART Rx.
Here is my code.
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 >= (BLE_NUS_MAX_DATA_LEN)))
{
//search for beginning bytes "AB,"
if (data_array[0] == 'A' && data_array[1] == 'B' && data_array[2] == ',')
{
//process commands
//If below line is commented, firmware will crash when code enters here
//err_code = ble_nus_string_send(&m_nus, data_array, index);
}
else
{
err_code = ble_nus_string_send(&m_nus, data_array, index);
}
if (err_code != NRF_ERROR_INVALID_STATE)
{
APP_ERROR_CHECK(err_code);
}
index = 0;
}
break;
To prevent the code from crashing, for some reason, ble_nus_string_send() has to be run all the time inside the if ((data_array[index - 1] == '\n') || (index >= (BLE_NUS_MAX_DATA_LEN))) statement. Otherwise, code will crash. I am very puzzled. Why is it necessary to run ble_nus_string_send()?