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?

  • Now my overlay file looks like this


    &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 >;
    };
    &i2c1 {
      status = "disabled";
    };


    But again it doesn't work.

    It seems to me that the changes to the overlay file make no difference, how can I check?

    These are the files that I'm changing.

  • You can't use those tx and rx pins without changing a few things in the board files, which will impact the network core.
    That's why I recommended using pin 34 and 35 instead.

    You can check whether the overlay is being applied in build/zephyr/zephyr.dts

  • As i suspected the .dts file is not changing, do you perhaps know what the reason would be?

    I change the overlay file and then in Segger IDE run these 2 commands.

    Is that enough? 

  • Oh, no that is not enough. When using SES, you need to run "Project->Run CMake" after changes to overlay files, prj.conf etc.

  • Now when I use run "Project-> Run CMake" .dts file is changed and looks fine.

    uart1: arduino_serial: uart@9000 {
      compatible = "nordic,nrf-uarte";
      reg = < 0x9000 0x1000 >;
      interrupts = < 0x9 0x1 >;
      status = "okay";
      label = "UART_1";
      current-speed = < 0x4b00 >;
      tx-pin = < 0x22 >;
      rx-pin = < 0x23 >;
    };

    Now I use pins 34 --> P1.02 and 35 --> P1.03 as you recommended.

    Wires -> ORANGE -> TXD; YELLOW -> RXD;

    An error that occurred before is gone,

    but a new error occurs...

    OUTPUT

    Not able to allocate UART receive buffer2

    CODE

    static void uart_work_handler(struct k_work *item)
    {
          struct uart_data_t *buf;

          buf = k_malloc(sizeof(*buf));
          if (buf) {
                buf->len = 0;
          } else {
                printk("Not able to allocate UART receive buffer2\n");
                k_work_reschedule(&uart_work, UART_WAIT_FOR_BUF_DELAY);
                return;
          }

          uart_rx_enable(uart, buf->data, sizeof(buf->data), UART_WAIT_FOR_RX);
    }

    I believe the problem is here buf = k_malloc(sizeof(*buf));

    , do you have any idea why this is happening?

    Do I miss any other settings?

Related