nRF9160 UART: UART_ASYNC_API Rx block while reading large data

Hi, everyone.

I am testing reading/writing data between n52840 and n9160 through UART with buf_len=1(byte by byte) based on Zephyr's UART_ASYNC_API provided in ncs v2.6.1.

When the data length is small, everything works as expected, which is great.

However, when I'm trying to read a large amount of data from the n9160, such as 512 bytes (ends with "\r\n") * 100, I can only successfully read the first 512 bytes. After that, I cannot read the second 512 bytes no matter how long the timeout is set. I also tried slicing the data into 2048 bytes* 25, and the first 2048 bytes can still be received completely, but similarly, no matter how long I wait, I cannot read the second 2048 bytes.


The testing code is like:
First enable the Uart Rx by:
static uint8_t uart_rx_buf[1];
uart_rx_enable(nrf_uart, &uart_rx_buf[0], 1, 0);
Then, async reads byte by byte every time Uart gets one byte until met an "\r\n"
if(evt->data.rx.len)
{
    buf[*p_rcv_len] = evt->data.rx.buf[0];

    *p_rcv_len += 1;
    if((*p_rcv_len >= 2) && (buf[*p_rcv_len-2] == '\r') && ((buf[*p_rcv_len-1] == '\n')))
    {
        return RCV_OK;
    }
}
I can get the first RCV_OK for both 512-bytes-len RX and 2048-bytes-len RX and blocked at waiting for the second one.
  • Hi,

    It looks like some implementation issue in your project.

    Those 512 bytes contain end of line characters or not?

    Can you test first with receiving 2 bytes rather than 512 bytes.

    However, when I'm trying to read a large amount of data from the n9160, such as 512 bytes (ends with "\r\n") * 100,

    What buffer size did you use in this case.

    As you have said that you can read first 512 and also 2048 bytes of data, looks like some issue with you end of line. Maybe you can share more details (code and testing snippets for both cases when len=1 and len=some other number, preferably 2)

Related