Tegra K1 Jetson UART on Expansion Header Does Not Work

Hi,

I am trying to send data over the UART2 ports on the J3A2 header but am unable to receive anything from it. I am using pyserial and trying to send bytes over ‘/dev/ttyTHS2’. Is there anything special that I have to do to set up serial? I opened port ‘/dev/ttyTHS2’ and connected wires to UART2_TXD and UART2_RXD on the port header. I then call the write function, after setting the baud rate to 9600. A minimal version of the code I am using is below, though I am pretty sure it is an issue with the UART ports on the Tegra K1, not the pyserial code. Has anyone successfully gotten UART working over the Tegra K1 Jetson Expansion IO ports?

import time
import serial
ser = serial.Serial(‘dev/tty/THS2’, 9600)

while 1:
   ser.write(‘a’)
   time.sleep(1)

Is your device also using the 1.8V logic levels or do you have a logic level translator in between?

I have the same problem. I am reading a GPS unit (properly level translated) which resides on a daughterboard connected to UART2. I can use an oscilloscope to see that the GPS unit is sending out characters on the serial port, but I cannot see them on the Tegra.

Does one need to enable the serial port? Is this automatically performed?

Thanks

Hi,

Try this code, is working on USART0, 41 and 44 pins on J3A2 header. For USART2 change the port to “/dev/ttyTHS2”, I have not tried on USART2 but should work.

The code send’s “START” to serial port and waits for a response, tested between jetson and F4 discovery board.

#include <stdio.h>
#include <termios.h> //header contains the definitions used by the terminal I/O interfaces
#include <unistd.h> //read() write() close()
#include <fcntl.h>
#include <string.h>

//Serial port defines and variables:
#define BAUDRATE B9600
#define SERIAL_PATH “/dev/ttyTHS0”
int serial_fd;
int serial_read_ret, serial_write_ret;
struct termios tty;
char serial_buffer_send = “START”;
char serial_buffer_recv[1024] = “”;

int main() {
printf(“Program to write a string to the serial port and read a string from it.\n”);

fflush(stdout);
//Try opening serial port
serial_fd = open(SERIAL_PATH,O_RDWR|O_NOCTTY);

if(serial_fd == -1) { //Checks the availability of the Serial Port
printf(“Failed.\n”);
fflush(stdout);
return 0;
} else {
printf(“Success.\n”);
fflush(stdout);

cfsetospeed (&tty, B9600);
cfsetispeed (&tty, B9600);

// Setting other Port Stuff
tty.c_cflag &= ~PARENB; // Make 8n1
tty.c_cflag &= ~CSTOPB;
tty.c_cflag &= ~CSIZE;
tty.c_cflag |= CS8;
tty.c_cflag &= ~CRTSCTS; // no flow control
tty.c_lflag = 0; // no signaling chars, no echo, no canonical processing
tty.c_oflag = 0; // no remapping, no delays
tty.c_cc[VMIN] = 0; // read block
tty.c_cc[VTIME] = 1; // 0.5 seconds read timeout

tty.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // turn off s/w flow ctrl
tty.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // make raw
tty.c_oflag &= ~OPOST; // make raw

/* Flush Port, then applies attributes */
tcflush( serial_fd, TCIFLUSH );

if ( tcsetattr ( serial_fd, TCSANOW, &tty ) != 0)
{
printf(“Failed settings.\n”);
}

}

//sends
serial_write_ret = write(serial_fd,serial_buffer_send,strlen(serial_buffer_send));
printf(“Sent to serial port: %s\n”,serial_buffer_send);

while(1)
{
serial_read_ret = read(serial_fd,serial_buffer_recv,sizeof(serial_buffer_recv));

if(serial_read_ret < 1 )
printf("-");
else
printf(“Read from serial port: %s\n”,serial_buffer_recv);
}

serial_read_ret = close(serial_fd); //Close the serial port

printf(“Serial port closed.\n\n”);
return 0;
}

David Fernandes

First, open the port:
minicom -D /dev/ttyTHS2
or
screen /dev/ttyTHS2

Then, loopback the TX pin to the RX pin. Literally just a hairpin of wire stuck between them is all it takes. Mash the keyboard in minicom or screen, and you should see your characters echo back to you. Remove the loopback and the echo should stop.

If you’ve got the port open but no data echoing, doublecheck your pin numbers!

If loopback works, then look at your voltage swing on a 'scope. Also, the “oh wtf did I really just spend 3 hours wondering why nothing worked and I forgot to connect Ground?!” option is always worth checking. ;)

A couple of things:

  1. I don’t know anything about the py serial library, but at first glance ‘dev/tty/THS2’ appears incorrect
  2. Which pins are you using for UART2?
  3. When I’ve used UART2 on J3A2 pin 65 (RX) and pin 68 (TX), the address mapped to /dev/ttyTHS1
    3a) As noted above, UART1 on pins 41 and 44 maps to /dev/ttyTHS0
  4. I believe that there are only two UARTs available on the J3 headers. The DB9 connector is mapped by Linux to /dev/ttyS0 for the console. I’m not quite sure what /dev/ttyTHS2 defines.

You can see a smashing video on the the UART along with level shifting here:

https://www.youtube.com/watch?v=354XkurNHbU

This thread has been open for a long time, unfortunately I just got around to playing with the UARTs. I’m sure the posters have long since solved the problem and moved on, this answer is here informational purposes.