Hi Team,
We are using the UARTE(UARTE1) module with DMA for our application with nRF52840 board, for that we are using the "libuarte" example project. For testing purpose we are sending the data from Teraterm continuously and same data we transmitting to the same terminal.
We have observed that some times we getting wrong Rx length while we sending the data from Tera term terminal, out of 10 times we are missing two times. Here with i am sharding my code changes what we did for testing.
Global DATA:
NRF_LIBUARTE_ASYNC_DEFINE(libuarte, 1, 0, 0, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 255, 3);
NRF_QUEUE_DEF(buffer_t, m_buf_queue, 10, NRF_QUEUE_MODE_NO_OVERFLOW);
=============================================================================================================
main fun:
==============================================================================================================
err_code = nrf_libuarte_async_init(&libuarte, &nrf_libuarte_async_config, uart_event_handler, (void *)&libuarte);
APP_ERROR_CHECK(err_code);
nrf_libuarte_async_enable(&libuarte);
while (true)
{
if(rx_done_flag)
{
rx_done_flag = 0;
nrf_libuarte_async_rx_read();
err_code = nrf_libuarte_async_tx(&libuarte, Rx_Read_buf.p_data, Rx_Read_buf.length);
if((NRF_SUCCESS != err_code) && (NRF_ERROR_BUSY != err_code))
{
APP_ERROR_CHECK(err_code);
}
}
}
============================================================================================================
uart_event_handler:
=========================================================================================================
{
nrf_libuarte_async_t * p_libuarte = (nrf_libuarte_async_t *)context;
ret_code_t ret;
switch (p_evt->type)
{
case NRF_LIBUARTE_ASYNC_EVT_ERROR:
error_flag++;
break;
case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
rx_done_flag++;
buffer_t buf = {
.p_data = p_evt->data.rxtx.p_data,
.length = p_evt->data.rxtx.length,
};
ret = nrf_queue_push(&m_buf_queue, &buf);
if(NRF_SUCCESS == ret)
nrf_libuarte_async_rx_free(p_libuarte, p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
}
break;
case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
tx_done_flag++;
break;
default:
break;
}
=================================================================================================
Rx_Read:
======================================================================================================
void nrf_libuarte_async_rx_read(void)
{
ret_code_t ret;
if (!nrf_queue_is_empty(&m_buf_queue))
{
ret = nrf_queue_pop(&m_buf_queue, &Rx_Read_buf);
APP_ERROR_CHECK(ret);
}
}
With the above code we are able to read the some of the packets,in between we are getting wrong length vallue.
Regards,
Srinivas.V