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

UART Configuration on nrf9160

Hi all,

I have no experience on Nordic products. I have struggled with this issue for several days. My goal is communication between nrf9160 and nrf52840 through UART. In order to provide it, my setup is below:

In nrf9160;

#include <zephyr.h>
#include <sys/printk.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_2");

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

-- In nrf9160_pca10090ns.overlay;

&uart2 {
	current-speed = <115200>;
	status = "okay";
	tx-pin = <10>;
	rx-pin = <11>;
	rts-pin = <12>;
	cts-pin = <13>;
};

In nrf52840, I'm using uart example of nrf SDK 16 which is located at /nRF5_SDK_16.0.0/examples/peripheral/uart

I just changed the following lines on this example:

...

uint8_t cr = 66;
//while (app_uart_get(&cr) != NRF_SUCCESS);
while (app_uart_put(cr) != NRF_SUCCESS);

...

In this way, nrf52 sending the character of 'B' to nrf91. And, nrf91 is waiting on ready state.

The cable setup is also below.

Is there any idea about my mistake? Thanks a lot.

  • Try adding the following to the prj.conf file:

    CONFIG_AT_HOST_LIBRARY=n
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_UART_2_NRF_UARTE=y
    CONFIG_UART_2_NRF_TX_BUFFER_SIZE=32

    Changes to configuration files, such as the .overlay or prj.conf, do not take affect until  the following:

    Close the project

    Exit Segger

    delete the build directory (build_nrf9160_pca10090ns)

    Run Segger and do file --> open nRF Connect SDK project.

    Wait for indexing to complete.

    Then clean and build.

  • Still, I couldn't achieve it. Do you have any suggestion about how I can test UART communication on nrf52840 or nrf9160? I just need simple example for UART communication.

  • Which version of the SDK are you using?   Maybe try the at_client sample project.

    In your example the char 'B' is continually written by the nrf52840.   Maybe reverse the direction.  When bringing up UART communication, I typically setup up a 1 second timer in order to write a single char to the UART once every second.  Transmitting is simpler than receiving.

    In your picture it looks like a nRF9160 dev board is being used which has a USB serial port interface. I'd connect that to a PC and run a serial terminal program such as TeraTerm (be sure to configure the baud rate).  The dev board shows up as 3 COM ports on the PC.  I forgot which one to select so try them all and see if chars are received.  Oh, use UART0 when talking to the PC.

Related