UART communication with external device on nRF9160dk

Hi,

I've been trying to set up UART communication with external device using uart3 instance and have so far failed.

The scenario requires sending 5 bytes to the device, receiving 1 byte confirmation, then another 5 byte request and receiving indeterminate amount of data (though about 75 bytes).

So I set up my overlay to enable uart3:

&pinctrl {

	uart3_default: uart3_default {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 13)>, <NRF_PSEL(UART_RX, 0, 10)>;
		};
	};
};


&uart3 {
	status = "okay";
	current-speed = <2400>;
    parity = "even";
    stop-bits = "1";
    data-bits = <8>;
	pinctrl-0 = <&uart3_default>;
	pinctrl-names = "default";
};

then, in prj.conf:

#UART

CONFIG_SERIAL=y
CONFIG_UART_ASYNC_API=y
CONFIG_UART_LINE_CTRL=n
CONFIG_UART_USE_RUNTIME_CONFIGURE=y

When I run the code (using asynchronous API), after 1st req-ack I get proper UART operation as per observed events:

events generated on tmo = 100 

total_rcved_len = 1
uart_rx_rdy_evt = 1
uart_rx_buf_req_evt = 2
uart_tx_done_evt = 1
uart_tx_aborted_evt = 0
uart_rx_stopped_evt = 0
--uart_rx_stopped_overrun = 0
--uart_rx_stopped_parity = 0
--uart_rx_stopped_framing = 0
--uart_rx_stopped_break_condition = 0
--uart_rx_stopped_collision = 0
--uart_rx_stopped_noise = 0
--uart_rx_stopped_other = 0
uart_rx_disabled_evt = 0

Then moving to next cycle of req-data i get following events (counted as increment of previous values):

events generated on tmo = 100
total_rcved_len = 38
uart_rx_rdy_evt = 13
uart_rx_buf_req_evt = 15
uart_tx_done_evt = 2
uart_tx_aborted_evt = 0
uart_rx_stopped_evt = 59
--uart_rx_stopped_overrun = 0
--uart_rx_stopped_parity = 0
--uart_rx_stopped_framing = 0
--uart_rx_stopped_break_condition = 0
--uart_rx_stopped_collision = 0
--uart_rx_stopped_noise = 0
--uart_rx_stopped_other = 59
uart_rx_disabled_evt = 9

Given that UART settings are correct (8e1@2400, no line control), and I was able to verify with oscilloscope that data is sent correctly from outside device, I think that something is missing either in my conf or overlay though I fail to see what could that be. Additionally, when setting CONFIG_UART_USE_RUNTIME_CONFIGURE=n and removing uart_configure() call from code no transmission occurs as far as I can tell, which as I understand should not be the case as overlay provides necessary configuration making uart_configure() redundant.

UART0 is used as logger backend. Tuning timeouts doesn't help, buffers are sized 256 so no overflow is possible.

Any help is appreciated.

Parents
  • I do not see anything wrong with your prj.conf and code. Maybe try enabling the hardware flow control as mentioned in this thread.
    My colleague in this thread, suggested to enable hw_async mode which seemed to have helped. I do not see anything else apart from these two to help us at this point. If this have not helped, then maybe I need to get more context and code from your end to understand the issue.

  • Hi Susheel,

    Thanks for getting back to me.

    Your suggested solution from this thread has solved my issue. Many thanks!

    For future reference, adding:

    CONFIG_UART_0_NRF_HW_ASYNC=y
    CONFIG_UART_0_NRF_HW_ASYNC_TIMER=1

    to prj.conf is the exact solution to my problem. With this addition, observability printout is:

    events generated on tmo = 100 
    total_rcved_len = 73 
    uart_rx_rdy_evt = 73 
    uart_rx_buf_req_evt = 2 
    uart_tx_done_evt = 2
    uart_tx_aborted_evt = 0 
    uart_rx_stopped_evt = 0 
    --uart_rx_stopped_overrun = 0 
    --uart_rx_stopped_parity = 0 
    --uart_rx_stopped_framing = 0 
    --uart_rx_stopped_break_condition = 0 
    --uart_rx_stopped_collision = 0 
    --uart_rx_stopped_noise = 0 
    --uart_rx_stopped_other = 0 
    uart_rx_disabled_evt = 1

    In the spirit of full disclosure, I've swapped logger backend to uart3 and used uart0 for communication, like this:

    /{
        chosen {
            zephyr,console = &uart3;
            zephyr,shell-uart = &uart3;
        };
    };
    &uart0 {
    	current-speed = <2400>;
        parity = "even";
        stop-bits = "1";
        data-bits = <8>;
    };
    
    &uart0_sleep {
        group1 {
            psels = <NRF_PSEL(UART_TX, 0, 13)>,
                    <NRF_PSEL(UART_RX, 0, 10)>,
                    <NRF_PSEL(UART_RTS, 0, 20)>,
                    <NRF_PSEL(UART_CTS, 0, 21)>;
        };
    };
    
    &uart0_default {
        group1 {
            psels = <NRF_PSEL(UART_TX, 0, 13)>, <NRF_PSEL(UART_RX, 0, 10)>;
        };
    };
    
    &uart3 {
    	status = "okay";
    	current-speed = <115200>;
        parity = "even";
        stop-bits = "1";
        data-bits = <8>;
    	pinctrl-0 = <&uart3_default>;
    	pinctrl-names = "default";
    };
    
    &pinctrl {
    
    	uart3_default: uart3_default {
    
            group2 {
                psels = <NRF_PSEL(UART_TX, 0, 18)>, <NRF_PSEL(UART_RX, 0, 19)>;
            };
    	};
    };

    I don't know if that had anything to do with solving the issue, but there you have it.

    Cheers,

    V

  • Thanks for coming back to us with a full report V

Reply Children
No Data
Related