UART RX missing bytes -event buffer length and offset mismatch-NRF Connect SDK

Hi, greetings all !!

I am developing an application based on ble_uart_peripheral example on nrf52dk_nrf52832 using NRF Connect SDK2.1. In my application, I have to receive bytes from an external client via UART. The problem is, at high baud rate, some of my bytes get missed. For example, while debugging, the evt->data.rx.offset shows 4 but evt->data.rx.len shows 2. So, when i try to read the buffer, based on offset value, I miss bytes. HW flow control is not an option for me since that would involve changes to my client as well. Is there anything else I can do to get this working ? I thought it might be an overrun case, but that was not the error cause.

Any ideas ?

  • Midhunjac said:
    That was what i tried to do initially, but without knowing the exact length and offset, that would be difficult.  Can you guide me with a code snippet ?

    The offset and length are given in the event. Based on your code, you can process it directly like this:

    case UART_RX_RDY:
    	LOG_DBG("UART_RX_RDY");
    	buf = CONTAINER_OF(evt->data.rx.buf, struct uart_data_t, data);
    	buf->len += evt->data.rx.len;
    	if (disable_req) {
    		return;
    	}
    	uint8_t data_t;
    	for (uint8_t i; i < evt->data.rx.len; i++)
    	{
    	    data_t = *(buf->data+evt->data.rx.offset+i);
            packetDecode(data_t,eSrc_UART);
    	}
        if ((evt->data.rx.buf[buf->len - 1] == '\n') ||
            (evt->data.rx.buf[buf->len - 1] == '\r')) 
        {
        	disable_req = true;
        	uart_rx_disable(uart);
        }
    	
    	break;

    You can also define a Queue or a FIFO where you push each received byte, to be processed later.

Related