This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Using UART1 for the serial communication

I am using nRF5340DK and would like to send and receive data to computer via UART1 and pins "TX", "RX", "CTS" and "RTS" using USB TO RS232 SERIAL CONVERTER.


This way I would keep UART0 for logging.

But I can't receive or send data via UART1.

I'm using the Segger IDE and the Peripheral_UART for the first nRF5340 DK board and the Central_UART example for the second board.

Im trying to use UART1 in Peripheral_UART example.

For now I changed settings for UART1 in zephyr.dst file

uart1: uart@9000 {
  compatible = "nordic,nrf-uarte";
  reg = < 0x9000 0x1000 >;
  interrupts = < 0x9 0x1 >;
  status = "okay";
  label = "UART_1";
  current-speed = < 0x4b00 >;
  tx-pin = < 0x21 >;
  rx-pin = < 0x20 >;
  rts-pin = < 0x0b >;
  cts-pin = < 0x0a >;
};

And i added in autoconfig.h

#define CONFIG_NRFX_UARTE1 1
#define CONFIG_UART_NRFX 1
#define CONFIG_UART_1_NRF_UARTE 1
#define CONFIG_UART_1_ENHANCED_POLL_OUT 1
#define CONFIG_UART_1_ASYNC 1
#define CONFIG_UART_1_NRF_TX_BUFFER_SIZE 32

It won't work with UART1.

When I switch back to UART0 it works fine.

What could be a problem?

  • Hi,

    Do not make changes to files in the build folder. Instead, make config changes in peripheral_uart/prj.conf and make dts changes in an overlay file named <board>.overlay. For example nrf5340dk_nrf5340_cpuapp.overlay

    The only change you need to make to the prj.conf will be to add CONFIG_NRFX_UARTE1=y and CONFIG_BT_NUS_UART_DEV="UART_1"

    In the overlay file, use "&uart1 {}" instead of "uart1: uart@9000 {}"

    Try these changes instead, and let me know if you still encounter issues.

  • Hi,

    I rollback all the changes to Peripheral_UART project,

    then I add

    CONFIG_NRFX_UARTE1=y
    CONFIG_BT_NUS_UART_DEV="UART_1"

    to the prj.conf file 

    and I add new file "build_nrf5340dk_nrf5340_cpuapp\zephyr\nrf5340dk_nrf5340_cpuapp.overlay"

    with inside 

    &uart1 {
     compatible = "nordic,nrf-uarte";
     reg = < 0x9000 0x1000 >;
     interrupts = < 0x9 0x1 >;
     status = "okay";
     label = "UART_1";
     current-speed = < 0x4b00 >;
     tx-pin = < 0x21 >;
     rx-pin = < 0x20 >;
     rts-pin = < 0x0b >;
     cts-pin = < 0x0a >;
    };

    But it doesn't work.

    It gives me an exception --> ENXIO 6  /**< No such device or address */

    uart = device_get_binding(DT_LABEL(DT_NODELABEL(uart1)));
    if (!uart) {
      printk("UART binding failed");
      return -ENXIO;
    }

    I even tried the same changes in the Central_UART project but still get the same exception.

    If I change back to uart0 everything works like before.

    I'm using SDK 1.6.1.

  • The overlay file should be outside of the build folder, you can put the overlay file at the same location as the prj.conf.
    You should never have to change anything in the build folder yourself, that also means that you should never have to add or delete files from it.

    In NCS v1.6.1 you should not include CONFIG_BT_NUS_UART_DEV="UART_1". Instead, you change line 214 in main.c, which I see you have already done.

    I would also advise you to use different pins for the uart1.
    You do not need to include rts or cts pins, as you are not using hardware flow control, so just choose two other unused pins for tx and rx.

  • I put the overlay file at the same location as the prj.conf and remove CONFIG_BT_NUS_UART_DEV="UART_1".

    It still doesn't work.

    I change the code to check uart0, uart1 and UART?

    Like before uart0 work, uart1 and UART_1 doesn't. 

    uart = device_get_binding(DT_LABEL(DT_NODELABEL(uart0)));
    if (!uart) {
       printk("UART device_get_binding(DT_LABEL(DT_NODELABEL(uart0))) --> ERROR!\n");
    } else
       printk("UART device_get_binding(DT_LABEL(DT_NODELABEL(uart0))) --> SUCCESS!\n");

    uart = device_get_binding("UART_1");
    if (!uart) {
       printk("UART device_get_binding('UART_1'); --> ERROR!\n");
    } else
       printk("UART device_get_binding('UART_1'); --> SUCCESS!\n");

    uart = device_get_binding(DT_LABEL(DT_NODELABEL(uart1)));
    if (!uart) {
       printk("UART device_get_binding(DT_LABEL(DT_NODELABEL(uart1))) --> ERROR!\n");
    } else
       printk("UART device_get_binding(DT_LABEL(DT_NODELABEL(uart1))) --> SUCCESS!\n");

    OUTPUT

    UART CHECK START
    UART device_get_binding(DT_LABEL(DT_NODELABEL(uart0))) --> SUCCESS!
    UART device_get_binding('UART_1'); --> ERROR!
    UART device_get_binding(DT_LABEL(DT_NODELABEL(uart1))) --> ERROR!
    UART CHECK END

     

    Which pins would you recommend for uart1?

    Would it make sense to try the same example on the latest SDK version?

    Could it be a problem that I'm not using the latest version?

    Thanks in advance for the help.

  • You also need to add this to the overlay file:

    &i2c1 {
        status = "disabled";
    };

    You can use pin 34 and 35. They are marked P1.02 and P1.03 on the board.

Related