LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-08-2016, 05:21 AM   #1
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 225

Rep: Reputation: 32
Why serial port /dev/ttyS1 after a while only send data and doesn't receive?


Hello,

I have kernel 3.6.11 with real time support (ingo molnar patch) and my app use serial port to connect access door control.
When app start, all works fine, but after a while ( 1 day or one week ) serial port doesn't receive anything but it is possible to send data.

Code:
n_bytes = read(fd_485, &byte_485, 1);
The function above always return me -1 and interrupt doesn't increase.
This is very strange, it's like driver doesn't reset flag interrupt, but I can't check or I don't known how to check it from user space.

This is init function where configure and open port:

Code:
int openserial(char *devicename)
{
int fd;
struct termios attr;
struct serial_struct serial;

	if ((fd = open(devicename, O_RDWR | O_NOCTTY | O_NDELAY)) == -1)
        perror("openserial(): open()");

    if (tcgetattr(fd, &oldterminfo) == -1)
        perror("openserial(): tcgetattr()");

    attr = oldterminfo;
    attr.c_oflag = 0;

    //**************************************************************************************
    //**************************************************************************************

    cfsetispeed(&attr, B19200);
	cfsetospeed(&attr, B19200);

	cfmakeraw(&attr);							//--> OBTENER LOS DATOS EN RAW

	attr.c_cflag |= PARENB;						//--> HABILITAMOS LA PARIDAD
	attr.c_cflag &= ~PARODD;					//--> HABILITAMOS LA PARIDAD PAR
	attr.c_cflag &= ~CSTOPB;					//--> UN BIT DE STOP
	attr.c_cflag &= ~CSIZE;						//--> ACTIVAMOS 8 BITS DE DATOS
	attr.c_cflag |= CS8;

	attr.c_cflag &= ~CRTSCTS;					//--> NO HAY CONTROL DE FLUJO DE HARDWARE
	attr.c_iflag &= ~(IXON | IXOFF | IXANY);	//--> NO HAY CONTROL DE FLUJO DE SOFTWARE

	attr.c_cflag |= (CLOCAL | CREAD);			//--> ENABLE RECEIVER AND SET LOCAL MODE

	attr.c_cc[VMIN]  = 1;						//--> LECTURA MINIMA DE CARACTERES DEL BUFFER
	attr.c_cc[VTIME] = 10;						//--> TIMEOUT DE LECTURA DE CARACTERES, EN PASOS DE 0.1 SEG

	ioctl(fd, TIOCGSERIAL, &serial);
	serial.flags |= ASYNC_LOW_LATENCY; // (0x2000)
	ioctl(fd, TIOCSSERIAL, &serial);

//**************************************************************************************
//**************************************************************************************

    if (tcflush(fd, TCIOFLUSH) == -1)
        perror("openserial(): tcflush()");

    if (tcsetattr(fd, TCSANOW, &attr) == -1)
        perror("initserial(): tcsetattr()");

    return fd;
}
And this is a function where I read all data avaible in serial port:

Code:
	while (1)
	{
		n_bytes = read(fd_485, &byte_485, 1);

		if (n_bytes < 0)
		{
			error_rs485_negative = n_bytes;
		}
		else if (n_bytes == 0)
		{
			error_rs485_zero ++;
		}
		else
		{
			buffer_485[commEnd] = byte_485;

			commEnd = ( commEnd + 1 )  BUFFER_RS485;
			commItems ++;
		}

		// Tiempo de espera para no dejar la CPU tostada
		//********************************************************
		usleep(2000);   // Se ejecuta cada 1 ms, si no , peta la CPU con carga al 100%

		counter_rs485 ++;
	}
and cat /proc/tty/driver/serial

Code:
0: uart:16550A port:000003F8 irq:4 tx:0 rx:0
1: uart:16550A port:000002F8 irq:3 tx:336 rx:540 fe:6 pe:60 DTR
2: uart:unknown port:000003E8 irq:4
3: uart:unknown port:000002E8 irq:3
I suppose that parity error or frame error isn't the problem because I don't use software and hardware flow control, but now I am not sure.

any advice??

Best reagards.

Last edited by webquinty; 01-08-2016 at 05:39 AM.
 
Old 01-08-2016, 08:53 AM   #2
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 225

Original Poster
Rep: Reputation: 32
I just check linux driver for UART and I have some doubts.
My hardware is old ( Geode LX800 ), and interrupts are edge trigger.

In Linux driver ( linux-3.6.11/drivers/tty/serial/8250/8250.c ), there is a comment:

/*
* Configuration:
* share_irqs - whether we pass IRQF_SHARED to request_irq(). This option
* is unsafe when used on edge-triggered interrupts.
*/

By default, serial port driver use shared interrupts. Perhpas this is my problem. I am going to disabled shared interrupts and test it.

If somebody has other idea..........

Best regards.
 
Old 01-11-2016, 06:43 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 20,294

Rep: Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213
I'd think it is the real time stuff. It's never really worked like it should in my opinion.

Anyway to test with near real time or standard kernel?
 
Old 01-13-2016, 06:06 AM   #4
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 225

Original Poster
Rep: Reputation: 32
Real time kernel
 
Old 01-13-2016, 08:37 PM   #5
jefro
Moderator
 
Registered: Mar 2008
Posts: 20,294

Rep: Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213Reputation: 3213
Can you see if use some other ways to test. Put in a different kernel or distro?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script to recieve and send data for serial port ffonseca Linux - Software 6 12-15-2014 02:09 PM
Serial port problem: ttyS1 input/output error. ted_chou12 Linux - Software 2 02-08-2013 05:26 PM
How send to data through serial port using linux C waqasdaar Programming 2 10-20-2009 03:55 PM
Can't send data on serial port (recieving works) OdieQ Linux - Hardware 7 07-26-2008 05:38 AM
serial port (ttyS1) - Sending commands via terminal... HELP!!! Nalorin Linux - Networking 2 08-21-2005 11:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration