UART Transmission Issue

Hello,

I am trying to develop a set of code that will receive data on uart 1 and transmit that data on uart 2, and vice versa.

I have verified via testing printk's that I am receiving and trying to send all of the correct data.
Uart 2 works correctly, but the transmission from uart 1 only provides the first character that I try to send.

I have made sure that flow control is disabled on both (not even pins are assigned to the flow control pins).

I am using XCTU and USB->UART adapters to communicate with the nrf uarts from my computer.

Here is a screenshot of one of my runs. The order of operations was send on left, send on right, send on right, send on left, send on left

blue sections indicate a sent byte. red indicate a received byte.

It seems like when I try to send multiple times from the right one (which is connected to uart 1), the transmission is blocked after the first byte, and no more can be sent until uart 1 receives data, after which it can send one more byte.

note: i am doing this on a nrf9160dk on the 1.6.1 sdk version. I am using the latest VS Code extensions.

/*
 * Copyright (c) 2020 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

#include <zephyr.h>
#include <drivers/uart.h>
#include <stdio.h>
#include <string.h>

static uint8_t uart_buf_in[1024];
static uint8_t uart_buf_out[1024];
static uint8_t sendbuf[1024];
static uint8_t recvbuf[1024];
struct device *uart2;
struct device *uart1;
int state;
int outside_data_length;
int esp_data_length;
void uart_cb2(struct device *x);
void uart_cb(struct device *x);

void uart_cb(struct device *x)
{
	uart_irq_update(uart1);

	//receive data from uart 1
	if (uart_irq_rx_ready(uart1)) 
	{
		outside_data_length = uart_fifo_read(uart1, uart_buf_in, sizeof(uart_buf_in));
		uart_buf_in[outside_data_length] = 0;
		strcat (sendbuf, uart_buf_in);
	}
	
	if (outside_data_length > 0)
	{
		outside_data_length = 0; //set to zero for flow control	
		uart_fifo_fill(uart2, sendbuf, strlen(sendbuf));
		strcpy(sendbuf, "");
	}
}
void uart_cb2(struct device *x)
{
	uart_irq_update(uart2);
	
	//receive data from uart2
	if (uart_irq_rx_ready(uart2))
	{
		esp_data_length = uart_fifo_read(uart2, uart_buf_out, sizeof(uart_buf_out));
		uart_buf_out[esp_data_length] = 0;
		strcat(recvbuf, uart_buf_out);
	}

	if (esp_data_length >0)
	{
		esp_data_length = 0;
		uart_fifo_fill(uart1, recvbuf, strlen(recvbuf));
		strcpy(recvbuf, "");
	}
}



void main(void)
{
	//initialize variables
	state = 0;
	outside_data_length = 0;
	esp_data_length = 0;
	strcpy(uart_buf_out, "");
	strcpy(uart_buf_in, "");

	//get uart bindings
	uart2 = device_get_binding("UART_2");
	uart1 = device_get_binding("UART_1");

	//bind uarts to callback functions
	uart_irq_callback_set(uart1, uart_cb);
	uart_irq_callback_set(uart2, uart_cb2);
	
	//enable uart interrupts
	uart_irq_rx_enable(uart1);
	uart_irq_rx_enable(uart2);

	printk("UART loopback start!\n");
	while (1) 
	{	

	}
}

prj.conj only has 3 lines:

CONFIG_ASSERT=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_AT_HOST_LIBRARY=n
So in short, I am trying to figure out why my two uart_cb functions behave differently.
Parents Reply Children
Related