Hi,
I am going to transmit and receive data with libuarte. I read the libuarte example, but I am not quite sure my understanding of the data transfer process is correct.
In my opinion, it looks like "nrf_libuarte_async_tx" can do both transmitting and receiving data, the received data will be first pushed to the queue. Then when we want to process it, we just pop the data out. Is my understanding is correct? So based on this, I modified the uarte event handler as followed, which I use to get the received data and process it. Do you think my implementation is reasonable?
Please let me know if the initialization of my libuarte is needed, and thanks in advance for your help:D
static void uart_event_handler(void * context, nrf_libuarte_async_evt_t * p_evt)
{
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:
break;
case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
//recieve the data?
ret = nrf_libuarte_async_tx(p_libuarte, p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
if (ret == NRF_ERROR_BUSY)
{
RxBuffer buf = {
.p_data = p_evt->data.rxtx.p_data,
.length = p_evt->data.rxtx.length,
};
//push the data to the queue
ret = nrf_queue_push(&RxBufferQueue, &buf);
APP_ERROR_CHECK(ret);
}
else
{
APP_ERROR_CHECK(ret);
}
if (nrf_queue_is_empty(&RxBufferQueue) == false)
{
RxBuffer buf;
//pop the data from queue
nrf_queue_pop(&RxBufferQueue, &buf);
//Reset the queue
nrf_queue_reset(&RxBufferQueue);
//get the received data
memcpy(rxdata, buf.p_data, buf.length);
//process the received data
processB2B(rxdata);
}
}
}