Forum Discussion
Altera_Forum
Honored Contributor
16 years agoError while trying to use RS232 port on DE2 2c35 running uClinux
Hi all,
I try to use RS232 port on my DE2 board to communicate with my device (magnetic card reader). But when I try to use the command "cat test.txt > /dev/ttyS0", the console appears with "/dev/ttyS0: cannot create." I am wondering if I have to check "Altera UART support" in "Device Drivers ---> Character devices ---> Serial drivers --->" or just use ttyS0 as a normal file? And how I can know that there are data coming from my device or PC? Is there buffer for data from RS232 port? :confused: Thanks for reading! :)2 Replies
- Altera_Forum
Honored Contributor
Hi Tien,
You have to be carefull with this command "cat test.txt > /dev/ttyS0", use microcom instead. You will find it in the application selection of the make menuconfig. command will be : microcom -s 9600 /dev/ttyS0 with 9600 the baud rate of your serial connexion. - Altera_Forum
Honored Contributor
thanks for replying Mr actris, I have solved that problem by updating to nios2-linux 2009 version. I can open and write data to "dev/ttyS0" well.
But I encounter another problem now. I can't read from "dev/ttyS0" by using read or fread functions. :( here's my code:# include <string.h> # include <unistd.h> # include <fcntl.h> # include <errno.h> # include <termios.h> int main(void) { char buf; int fd1, fd2, count; fd1 = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY); fd2 = open("/mnt/SD/t.txt",O_WRONLY); if (fd1 == -1) { perror("open_port: Unable to open /dev/ttyS0 - "); } while(count = read(fd1, buf, 10) > 0) write(fd2, buf, 10); close(fd1); close(fd2); //return (fd); }