Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

RS232 Flow Control in uClinux

System: DE0-Nano Dev. Kit running uClinux on NIOS2

I've added a custom daughter board with RS232 and some other goodies.

My system receives raw serial data via RS232, error free, up to 38k4. The data is in the form of 250B packets, received once per second. At rates higher than 38k4 I start to lose bytes. I have a need to run this at 115k2, at which I lose about 30B per packet.

I thought the best option would be to include support for RTS/CTS in SOPC builder. Of course I've also added the instantiation and pins to my top level .v.

When I send data to this system at 115k2 I lose bits but I cannot get RTS to respond. Any suggestions would be greatly appreciated.

My receiving software is as follows:

# include <stdio.h> /* Standard input/output definitions */# include <string.h> /* String function definitions */# include <unistd.h> /* UNIX standard function definitions */# include <fcntl.h> /* File control definitions */# include <errno.h> /* Error number definitions */# include <termios.h> /* POSIX terminal control definitions */

/*

* 'open_port()' - Open serial port 1.

*

* Returns the file descriptor on success or -1 on error.

*/

int open_port(void);

int main(void)

{

int fd,n,i;

unsigned char buffer[256]; //Input buffer

FILE *ECG_file = NULL;

struct termios config;

ECG_file = fopen("/bin/test_data.txt","w+");

fd = open_port();

n = write(fd, "Ready!\n", 7);

if (n < 0)

printf("write() failed!\n", stderr);

cfmakeraw(&config); //configure the serial port structure for raw data comms. i.e. no character processing

config.c_cflag |= CRTSCTS; //enable hw flow control

tcsetattr(fd, TCSAFLUSH, &config); //update the serial port attributes

tcflush(fd, TCIFLUSH); //flush data received but not read

for(i=0;i<=250;i++)

{

read(fd, &buffer, 1);

fprintf(ecg_file,"%i\n",buffer);

}

fclose(ECG_file);

close(fd);

}

int open_port(void)

{

int fd; // File descriptor for the port

fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);

if (fd == -1)

{

//Could not open the port.

perror("open_port: Unable to open /dev/ttyS0 - ");

}

else

fcntl(fd, F_SETFL, 0);

return (fd);

}
No RepliesBe the first to reply