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

nRF9160 UART

Hello,

I tried to setup the UART example provided at this link: https://github.com/Rallare/fw-nrfconnect-nrf/tree/nrf9160_samples/samples/nrf9160

I open two COM ports, when I type data in one of the COM port it gets printed on the other one.
However, if I try to print the received letter/message I only get a 0 or 128 (in decimal). I do not get the correct string output.

What could be the issue? Thank you.

Kind regards
Corentin

Parents Reply Children
  • I am trying to add the UART example to the mqtt_simple example and chose to use the UART1.

    What are the necessary changes to prj.conf?

    I have:
    CONFIG_SERIAL=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_UART_1_NRF_UARTE=y

    But I don't have:
    CONFIG_TRUSTED_EXECUTION_NON_SECURE=y

    Thanks.

  • I believe UART1 is used by printk(I might be wrong). In that case you would receive and send on the same COM port. Are you running the UART example or the mqtt_simple example when you get the error? The prj.conf file should be fine.

  • Isn't UART0 used for printk?
    I am running the mqtt_simple example with code from the UART example when I get the error.

  • cdugue said:
    Isn't UART0 used for printk?

     Yes I was wrong apparently. I just checked in autoconf.h, and found #define CONFIG_UART_CONSOLE_ON_DEV_NAME "UART_0".

     

    cdugue said:
    I am running the mqtt_simple example with code from the UART example when I get the error.

     Do you mind sharing your code, so I can see exaclty what you are doing?

  • Sure. I also tried sending data from the nRF52840 to the nRF9160 through UART and the same thing happens, I only get 0 or 128 as data.

    In the main of the MQTT sample I added the following initialization for UART:

    struct device *uart = device_get_binding("UART_1");
    if (!uart) {
        printk("error\r\n"); // error happens.
    }
    
    uart_irq_callback_set(uart, uart_cb);
    uart_irq_rx_enable(uart);
    printk("UART loopback start!\n");

    The UART callback:

    void uart_cb(struct device *x)
    {
      uart_irq_update(x);
      int data_length = 0;
    
      if (uart_irq_rx_ready(x)) {
        data_length = uart_fifo_read(x, uart_buf, sizeof(uart_buf));
        uart_buf[data_length] = 0;
      }
    
      printk("data_length %d - ", data_length);
      printk("%d (", uart_buf[0]);
      printk("%s)\n", uart_buf);
    }

    The UART buffer:

    static u8_t uart_buf[1024];

    In the project config file I added:

    CONFIG_SERIAL=y
    CONFIG_UART_1_NRF_UARTE=y

    Thank you.

Related