This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

UARTE configuration with nrf9160 and zephyr

Hi,

we have developed our working UART code according to Zephyr documentation, and its working fine,

we find that this code works with EasyDMA . but my question is my uart2_fifo_callback function is calling for every byte, why its happening like this, please help me to understand?

Note: we are using UART in UARTE_INTERRUPT_DRIVEN mode

and some other doubts are:

1. How we can increase/decide RX FIFO size

2. How we can configure UART so that the Uart_fifo_callback function will be called only once per every communication

3. What is the difference between UARTE_INTERRUPT_DRIVEN and CONFIG_UART_ASYNC_API, can we have interrupt handler even if i use CONFIG_ASYNC_API mode?

Best Regards

Rajener.

Parents
  • Hi Rajener

    I think it would be better to use the ASYNC version in this case. Then you can define a timeout, and rather than get a callback for each byte you will get a callback either if the RX buffer is full, or if the timeout is reached and there is no new data. 

    I made a simple example to show how to use the UART ASYNC driver a while back:
    https://github.com/too1/ncs-uart-async-count-rx/blob/master/src/main.c

    Best regards
    Torbjørn

  • Hi,

    after spending some time on this i got to know that

    when i transmit data using uart_tx() this will return 0, (means-successful) but again it will trigger timeout function(static void tx_timeout()) then, UART_TX_ABORTED event, and then UART_TX_DONE event.
    but anyway data will not sends to the UART Terminal.

    Please help me to solve this.

    NOTE: I am attaching my project for your reference please check.

    UART_TEST.zip

    Best Regards

    Rajender.

  • Hi Rajender

    In order to configure pins and baudrate it is best to create an overlay file, which overwrites the default configuration for the UART_2 peripheral from dts. 

    This case describes how to create the overlay file for the UART peripheral on the nRF9160:
    https://devzone.nordicsemi.com/f/nordic-q-a/65473/uart-gpio-configuration

    Can you try this and see if you can spot any activity on the pins?

    If you are still having issues can you share the overlay file with me, and I will try to reproduce it on my end. 

    Best regards
    Torbjørn

  • Hi,

    we are using a custom board based on nrf9160,

    I found my .dts file in my zephyr/boards/arm/"board name", i figured out my default pinout and baud rate and all for my UART_2,

    that's why my rx interrupt is working properly and i can read the data properly

    but my present problem is (TX) i am not able to send any data from my controller, but i can receive properly.

    I have added This api to transmit

    int rett = uart_tx(dev_uart,read_ptr,read_len,1000);

    and when i deep dive in further,  i found that in below function its going into "else " statement only which is error message: Unknown ARM architecture.

    static ALWAYS_INLINE unsigned int arch_irq_lock(void)
    {
    	unsigned int key;
    
    #if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE)
    	__asm__ volatile("mrs %0, PRIMASK;"
    		"cpsid i"
    		: "=r" (key)
    		:
    		: "memory");
    #elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
    	unsigned int tmp;
    
    	__asm__ volatile(
    		"mov %1, %2;"
    		"mrs %0, BASEPRI;"
    		"msr BASEPRI, %1;"
    		"isb;"
    		: "=r"(key), "=r"(tmp)
    		: "i"(_EXC_IRQ_DEFAULT_PRIO)
    		: "memory");
    #elif defined(CONFIG_ARMV7_R)
    	__asm__ volatile(
    		"mrs %0, cpsr;"
    		"and %0, #" TOSTR(I_BIT) ";"
    		"cpsid i;"
    		: "=r" (key)
    		:
    		: "memory", "cc");
    #else
    #error Unknown ARM architecture
    #endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */
    
    	return key;
    }

    Please help me

    Best Regards

    Rajender

  • Hi Rajender

    Have you tested the code on an nRF9160DK to see if the problem is the same?

    Are you able to share the board files for your board with me, and also a schematic of the board if you have one?

    If you want I can make the case private, in case you don't want to share your files in a public case. 

    Best regards
    Torbjørn

Reply Children
  • Hi

    Yes, the problem is in board files only, but these board files used to work fine without any extra hardware in INTERRUPT_DRIVEN_MODE

    finally now my TX and Rx both are working, after little bit modification in board files->uart config

    i have changed my board files like this...

    &uart2 {
    	compatible = "nordic,nrf-uarte";
    	status = "okay";
    	current-speed = <115200>;
    	tx-pin = <11>;
    	rx-pin = <10>;
    	rts-pin = <12>;
    	cts-pin = <7>;
    	/*hw-flow-control;*/
    };

    Now my UARTE configuration is like this, and its working fine

    Prior to this The "hw-flow-control" was not in comment so then only RX used to work when i comment "hw-flow-control" now its working with both RX and TX.

    Best Regards

    Rajender

  • Hi Rajender

    Thanks for the update, interesting to see that the flow control setting was the culprit. Good to know for the future Slight smile

    I will close this case then. 

    Best regards
    Torbjørn

  • Hi 

    I got one more issue in the UARTE execution,

    the issue is when we are sending the data string one by one its works fine, but when we send a string1 and then we send string2 before completely collecting  string1 in callback function then issue starts, from now on the callback function is getting the new length which is length of string2 and the data pointer points to middle of the string1, finally we are collecting combination of string1 and string2 so entire data format is collapsing.

    Please help us,

    Best Regards

    Rajender

  • Hi Rajender

    Do you make sure to wait until string1 is transmitted before sending string2? 

    Either you have to do this, or you have to store string2 in a buffer while waiting for string1 to complete, and then you can read it from the buffer and send it in the TX callback. 

    If you look at the example I shared earlier in this case I do something like this, by putting all the TX data in a ring buffer, so that you can prepare more TX data while the UART is busy:
    https://github.com/too1/ncs-uart-async-count-rx/blob/master/src/main.c#L111

    Best regards
    Torbjørn

Related