0
votes

I have problems, when I try to readout the serial interface on my linux device. This is how I open my port:

string port = /dev/ttyMFD1;
struct termios tio;
struct termios stdio;
fd_set rdset;

memset(&stdio, 0, sizeof(stdio));
stdio.c_iflag = 0;
stdio.c_oflag = 0;
stdio.c_cflag = 0;
stdio.c_lflag = 0;
stdio.c_cc[VMIN] = 1;
stdio.c_cc[VTIME] = 0;
tcsetattr(STDOUT_FILENO, TCSANOW, &stdio);
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &stdio);
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);

memset(&tio, 0, sizeof(tio));
tio.c_iflag = 0;
tio.c_oflag = 0;
tio.c_cflag = CS8 | CREAD | CLOCAL;
tio.c_lflag = 0;
tio.c_cc[VMIN] = 1;
tio.c_cc[VTIME] = 2;

serial_port = open(port.c_str(), O_RDWR | O_NONBLOCK);      
cfsetospeed(&tio, B115200);
cfsetispeed(&tio, B115200);
tcsetattr(serial_port, TCSANOW, &tio);

Now I write to the port with the following code (hexadecimal values contained in 'str'):

char str[] = { 0xAA, 0x00, 0x3D, 0x01, 0x0C, 0x00 };
write(serial_port, str, strlen(str));

Now I want to get the response from my UART connected chip:

while(1)
{
    unsigned char theByte;
    int n = 0;
    n = read(serial_port, theByte, 1);
    cout << theByte << "\n" ;
    usleep(100000);
}

When I'm debugging, the returning values are not helpful. When I connect with a debug terminal and do a

od -x < /dev/ttyMFD1

Then the output on the console is fine. But I don't get any of the printed hexadecimal values If I look at "theByte" while debugging.

1

1 Answers

0
votes

Change

n = read(serial_port, theByte, 1);

to

n = read(serial_port, &theByte, 1);

otherwise you do not get any result...