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

nRF9160 UART_0 not receiving data from nRF52840 on custom PCB

I am hoping to pass data from the nRF52840 to the nRF9160 over UART_0, on a custom PCB. For context, the aim is to pass data at a rather quick rate and good reliability. The board name used for the nRF9160 project was "nrf9160_pca10090ns".

I am fairly sure the data is being sent from the nRF52840, as I was able to probe the data lines between the nRF9160 and the nRF52840 and successfully read messages being sent from the nRF52840 using a debugger.

However, the UART callback on the nRF9160 is never called. Note that I am able to see the normal boot information (where it lists the peripherals, secure vs nonsecure, etc.) without issue, by probing the data going from the nRF9160 to the nRF52840.

The relevant sections of main.c for the nRF9160 are below, with init_uart() being called from main().

#include <drivers/uart.h>

....

#define UART_BUF_SIZE           128
static struct device  *dev_uart;
static K_FIFO_DEFINE(fifo_uart_tx_data);
static K_FIFO_DEFINE(fifo_uart_rx_data);
static u8_t uart_rxbuf[UART_BUF_SIZE];
static u8_t uart_rx_leng=0;
struct uart_data_t {
	void  *fifo_reserved;
	u8_t    data[UART_BUF_SIZE];
	u16_t   len;
};

....

static u8_t uart_buf[1024];
void uart_cb(struct device *x)
{
    printk("Inside UART_CB");
	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;
	}
	// CODE WHICH RESPONDS TO UART MESSAGE BEING RECEIVED
}


static int init_uart(void)
{


	dev_uart = device_get_binding("UART_0");
	if (!dev_uart) {
		return -ENXIO;
	}

	uart_irq_callback_set(dev_uart, uart_cb);
	uart_irq_rx_enable(dev_uart);

	return 0;
}

....

The prj.conf file, slightly simplified, is as follows:

#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n

# BSD library
CONFIG_BSD_LIBRARY=y
CONFIG_BSD_LIBRARY_TRACE_ENABLED=n

# AT Host
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_AT_HOST_LIBRARY=n
CONFIG_SERIAL=y
CONFIG_GPIO=y

# MQTT
CONFIG_MQTT_LIB=y
CONFIG_MQTT_LIB_TLS=y

# Other
CONFIG_UART_1_NRF_UARTE=y

# Appliaction
CONFIG_MQTT_PUB_TOPIC=XXX
CONFIG_MQTT_SUB_TOPIC=XXX
CONFIG_MQTT_CLIENT_ID=XXX
CONFIG_MQTT_BROKER_HOSTNAME=XXX
CONFIG_MQTT_BROKER_PORT=XXX
    
CONFIG_SEC_TAG=XXX
CONFIG_PEER_VERIFY=1

# Main thread
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_HEAP_MEM_POOL_SIZE=4096

A nrf9160_pca10090ns.overlay was added to the project directory at the same level as the prj.conf file:

 

/* Needed to get NRF_UARTE2 and NRF_PWMn defined. */
&uart1 {
  current-speed = <115200>;
  status = "ok";
  tx-pin = <1>;
  rx-pin = <0>;
  rts-pin = <14>;
  cts-pin = <15>;
};

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

&pwm1 {
	status = "ok";
};

&pwm2 {
	status = "ok";
};

&pwm3 {
	status = "ok";
};

The CMakeLists file is default:

#
# Copyright (c) 2018 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

cmake_minimum_required(VERSION 3.8.2)

include($ENV{ZEPHYR_BASE}/../nrf/cmake/boilerplate.cmake)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(nrf9160-lte)

# NORDIC SDK APP START
target_sources(app PRIVATE src/main.c)
# NORDIC SDK APP END

The following nrf9160_pca10090.overlay file is in the spm project (under nrf\samples\nrf9160\spm), although the spm project itself was not downloaded to the board. Is this an issue?

&uart1 {
  current-speed = <115200>;
  status = "ok";
  tx-pin = <1>;
  rx-pin = <0>;
  rts-pin = <14>;
  cts-pin = <15>;
};

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

/* Needed to get NRF_UARTE2 and NRF_PWMn defined. */
&uart2 {
	status = "okay";
};

&pwm1 {
	status = "okay";
};

&pwm2 {
	status = "okay";
};

&pwm3 {
	status = "okay";
};

I am at something of a loss right now, and any help and direction for receiving the UART messages on the nRF9160 would be greatly appreciated!

Thanks in advance!

  • The uart0 pins are connected to the interface MCU (which makes it possible to see the loging on the computer due to a UART-to-USB converter) by default. If you want to use UART0 for other purposes, you have to reconfigure the board controller options on the nRF52840. You could use uart1 if you would like to see the UART logging on the computer.

    Check out this case on how to go about this. The case is somewhat old, and some of the stuff might be outdated. E.g. secure boot has changed name to SPM (secure partition manager).

    Best regards,

    Simon

Related