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

UART example acting weird

Hi! 

I've been playing around with the SDK and nrf9160 dk for a week now, and it's a lot of fun. 

In the beginning the UART example worked perfectly, and I managed to add a second UART which also worked. Now, after playing around with mqtt, trying to merge some of the projects etc. it seems something broke. 

When i try to run the UART feedback example (using printk with LTE link monitor), it doesn't work. The monitor shows: "UART feedback loop" as supposed, but nothing can be written to it.

When running the "at_client" example, I can write as many commands as I'd like (at least after restarting the monitor if UART example was previously tried).

Any suggestions?

My prj.conf:

CONFIG_SERIAL=y
CONFIG_TRUSTED_EXECUTION_NONSECURE=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_MAIN_STACK_SIZE=4096

main.c: 

#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_0");

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

The solution might be obvious as I am probably having a big case of tunnel visions.

Any suggestions?

Parents Reply Children
  • A quick chat with one of our developers revealed the issue.

    The Link Monitor was made to communicate with the modem, so it expects the communication to follow a certain protocol. I.e. it expects any input to be answered with a properly formatted "OK" or "ERROR" line.

    The application can output whatever it wants, and that output will appear as blue text in the Link Monitor.

    However, it can only send "AT commands"*, which will appear as yellow text.

    The properly formatted responses will be colored white.

    As a quick test, I changed the output in the callback to "OK\r\n", at which point the Link Monitor worked as expected**.


    * Technically, you can send whatever you want, as long as you get a response similar to what an AT command would get.

    ** The application will print one "OK\r\n" per character. The first one will be taken as the response (white), while the rest will be takes as generic output from the application.

  • Okay, good to know! Thank you very much for the help! Now remains to merge with mqtt, wish me luck.

Related