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

serial library errors while using BLE

Hi,
I'm working on project using nRF52840-DK board with nRF5_SDK_15.2.0_9412b96.
The program collects data from two UARTs, process data and
sends results to Android over BLE. The program also collect some data from
3 I2C devices every second.
I'm using serial library and serial_uartes as starting point.
Both UARTs receiving about 900 characters/sec and UART speed is 115,200.
The main program call uarts_process() routine every second to process
received characters.
It works fine if there is no connection to Android, but I soon
as Android gets connected and program starts sending data over BLE
errors NRF_SERIAL_EVENT_DRV_ERR occurs sporadically.
The only way to recover from the error is to uninint and re-init UART
using calls:
nrf_serial_uninit(&serial0_uarte);
and
ret = nrf_serial_init(&serial1_uarte, &m_uarte1_drv_config, &serial1_config);

It works for a while, but after few minutes program hangs.

Thank you for your help.


Here are fragrments of my code:

#define OP_QUEUES_SIZE 3
#define APP_TIMER_PRESCALER NRF_SERIAL_APP_TIMER_PRESCALER

static void sleep_handler(void)
{
__WFE();
__SEV();
__WFE();
}

bool uart0_reinit = false;
bool uart1_reinit = false;

static void serial_event_handler( struct nrf_serial_s const *p_serial, nrf_serial_event_t event );

static const nrf_serial_t serial0_uarte;
static const nrf_serial_t serial1_uarte;

static void serial_event_handler( struct nrf_serial_s const *p_serial, nrf_serial_event_t event )
{
switch (event)
{
case NRF_SERIAL_EVENT_DRV_ERR:
{
nrf_serial_t const * p_ser = p_serial;
if(p_ser == &serial0_uarte)
{
uart0_reinit = true;
}
if(p_ser == &serial1_uarte)
{
uart1_reinit = true;
}
break;
}
default:
break;
}
}

NRF_SERIAL_DRV_UART_CONFIG_DEF(m_uarte0_drv_config,
PTI_UART0_RX_PIN_NUMBER, PTI_UART0_TX_PIN_NUMBER,
PTI_UART0_RTS_PIN_NUMBER, PTI_UART0_CTS_PIN_NUMBER,
NRF_UART_HWFC_DISABLED, NRF_UART_PARITY_EXCLUDED,
NRF_UART_BAUDRATE_115200,
UART_DEFAULT_CONFIG_IRQ_PRIORITY);

NRF_SERIAL_DRV_UART_CONFIG_DEF(m_uarte1_drv_config,
PTI_UART1_RX_PIN_NUMBER, PTI_UART1_TX_PIN_NUMBER,
PTI_UART1_RTS_PIN_NUMBER, PTI_UART1_CTS_PIN_NUMBER,
NRF_UART_HWFC_DISABLED, NRF_UART_PARITY_EXCLUDED,
NRF_UART_BAUDRATE_115200,
UART_DEFAULT_CONFIG_IRQ_PRIORITY);

#define SERIAL_FIFO_TX_SIZE 128
#define SERIAL_FIFO_RX_SIZE 4096

NRF_SERIAL_QUEUES_DEF(serial0_queues, SERIAL_FIFO_TX_SIZE, SERIAL_FIFO_RX_SIZE);
NRF_SERIAL_QUEUES_DEF(serial1_queues, SERIAL_FIFO_TX_SIZE, SERIAL_FIFO_RX_SIZE);

#define SERIAL_BUFF_TX_SIZE 1
#define SERIAL_BUFF_RX_SIZE 1

NRF_SERIAL_BUFFERS_DEF(serial0_buffs, SERIAL_BUFF_TX_SIZE, SERIAL_BUFF_RX_SIZE);
NRF_SERIAL_BUFFERS_DEF(serial1_buffs, SERIAL_BUFF_TX_SIZE, SERIAL_BUFF_RX_SIZE);


NRF_SERIAL_CONFIG_DEF(serial0_config, NRF_SERIAL_MODE_DMA,
&serial0_queues, &serial0_buffs, serial_event_handler, sleep_handler);
NRF_SERIAL_CONFIG_DEF(serial1_config, NRF_SERIAL_MODE_DMA,
&serial1_queues, &serial1_buffs, serial_event_handler, sleep_handler);

NRF_SERIAL_UART_DEF(serial0_uarte, 0);
NRF_SERIAL_UART_DEF(serial1_uarte, 1);

struct uart_process_buffer msg_buf0;
struct uart_process_buffer msg_buf1;

void uarts_process(void)
{
char c;
while (nrf_serial_read(&serial0_uarte, &c, sizeof(c), NULL, 0) == NRF_SUCCESS)
uart_process_char(c,&msg_buf0);
while (nrf_serial_read(&serial1_uarte, &c, sizeof(c), NULL, 0) == NRF_SUCCESS)
uart_process_char(c,&msg_buf1);
}

Parents Reply Children
Related