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

simple UART example nrf9160dk

I am new to the nRF9160dk board. I have been able to compile and run some of the sample programs. I am now looking to have a simple program to talk to external uarts 0 and 1. I have found a githib project https://github.com/Rallare/fw-nrfconnect-nrf/tree/nrf9160_samples that has a simple UART example. I can build and load it but I am not sure where to configure the UART and how to get it to work.

I see the following for Uart0 in the device tree. so I am assuming this is where the baud rate and external pins are defined.

however when I run the program I do not get an indication that characters are seen on gpio_0 P28 which is on connector P27. I am using TeraTerm to connect.

I am assuming the TX/RX are relative to the nRF9160 board. in other words RX pin (28) is where it is expecting to see characters at 115200 baud.

I am assuming I do not need to connect to RTS/CTS.

I am sure it is something simple I left out or I am not doing. any help would be appreciated.

I am trying to build a simple application where I can type commands on a terminal emulator (putty, TeraTerm, etc.) and parse and execute those commands and send the output back to the terminal emulator. I have done this in the past on several other project and has proven to be quite effective in field support and debugging.


&uart0 {
status = "okay";
current-speed = <115200>;
tx-pin = <29>;
rx-pin = <28>;
rts-pin = <27>;
cts-pin = <26>;
};

the program is included below

/*

* Copyright (c) 2012-2014 Wind River Systems, Inc.

*

* SPDX-License-Identifier: Apache-2.0

*/

#include <zephyr.h>
//#include <misc/printk.h>
#include <sys/printk.h>
//#include <uart.h>
#include <drivers/uart.h>

static u8_t uart_buf[1024];

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("%s", uart_buf);
}

void main(void)
{
struct device *uart = device_get_binding("UART_0");

uart_irq_callback_set(uart, uart_cb);
uart_irq_rx_enable(uart);
printk("UART loopback start!\n");
while (1)
{
k_cpu_idle();
}
}

Parents
  • Hi.

    The pins used are connected to the debugger, which also acts as a UART<->USB bridge, so you will not see any activity on the headers (this can be changed by the board controller, you can read more here).

    On your computer, you should see the nRF91DK as 3 virtual COM ports. One of them will display the log from the DK. In a terminal (such  as TeraTerm), you should then be able to write something, and see it printed back by the device.

    Best regards,

    Didrik

Reply
  • Hi.

    The pins used are connected to the debugger, which also acts as a UART<->USB bridge, so you will not see any activity on the headers (this can be changed by the board controller, you can read more here).

    On your computer, you should see the nRF91DK as 3 virtual COM ports. One of them will display the log from the DK. In a terminal (such  as TeraTerm), you should then be able to write something, and see it printed back by the device.

    Best regards,

    Didrik

Children
No Data
Related