LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 09-06-2009, 09:49 PM   #1
lxpwj
LQ Newbie
 
Registered: Sep 2009
Posts: 7

Rep: Reputation: 0
Help: cannot change baud rate to s3c2410 seial port via tcsetattr


Hello,

I am writing a simple serial port programing based on s3c2410. However, I found that I cannot change serial port attributes including baud rate using tcsetattr. I think i have follow "Serial Programming Guid for POSIX operating system" strictly, but why it does not work? the baund rate cannot be changed to 115200?

Below is my program
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <error.h>
#include <string.h>
#define _POSIX_SOURCE 1 /* POSIX compliant source */

int myopen_port(char* port, int rate){
int fd,ret;
struct termios curopt;

fd = open(port, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd < 0){
printf("open_port failed");
return -1;
}else {
//fcntl(fd, F_SETFL, FNDELAY); //non-blocking
fcntl(fd, F_SETFL, 0);
}


bzero(&curopt, sizeof(curopt));
/* Mostly 8N1 */
curopt.c_cflag &= ~PARENB;
curopt.c_cflag &= ~CSTOPB;
curopt.c_cflag &= ~CSIZE;
curopt.c_cflag |= CS8;
curopt.c_cflag |= CLOCAL|CREAD; //disable modem statuc check
/* to disable flow control*/
curopt.c_iflag &= ~( IXON|IXOFF|IXANY);

cfmakeraw(&curopt); //make raw mode
/* Set the baud rate */
printf("rate 0x%x\n",rate);
ret = cfsetispeed(&curopt, rate);
if( ret < 0) printf("error set cfsestispeed\n");
ret = cfsetospeed(&curopt, rate);
if( ret < 0) printf("error set cfsestospeed\n");
/* set blocking reading wait condition*/
curopt.c_cc[VMIN] = 1;
curopt.c_cc[VTIME] = 0;

printf("setting attributes:\n");
printf("c_cflag 0x%x \n", curopt.c_cflag);
printf("c_iflag 0x%x \n", curopt.c_iflag);
printf("c_oflag 0x%x \n", curopt.c_oflag);
printf("c_lflag 0x%x \n", curopt.c_lflag);
tcflush(fd, TCIFLUSH);

ret = tcsetattr(fd, TCSANOW, &curopt);
printf("set attribute results: %d\n", ret);
printf("--------------------------------\n");
printf("reading back attributes:\n");
ret = tcgetattr(fd, &curopt);
printf("reading results %d\n", ret);
printf("c_cflag 0x%x \n", curopt.c_cflag);
printf("c_iflag 0x%x \n", curopt.c_iflag);
printf("c_oflag 0x%x \n", curopt.c_oflag);
printf("c_lflag 0x%x \n", curopt.c_lflag);
return fd;
}

int main(int argc, char *argv[])
{
int fd;
int addr =0, ret,s,t;
unsigned char rbuf[50];

fd = myopen_port(argv[1], B115200);
printf("OPEN PORT %s RESULTS %d ", argv[1], fd);
if (fd > 0)
{
memset(rbuf,0,50);
for (addr=0;addr <50000; addr++)
{
ret = read(fd,rbuf,50);
memset(rbuf,0,50);
usleep(10);
}
myclose_port(fd);
}
return 0;
}
 
Old 09-06-2009, 09:56 PM   #2
lxpwj
LQ Newbie
 
Registered: Sep 2009
Posts: 7

Original Poster
Rep: Reputation: 0
more information from kernel printk
1. once I issue command tcsetattr, the kernel will invoke uart_ioctl in the serial_core.c
2. I have checked the s3c2410 uart driver and I think the driver is using s3c24xx_serial_set_termios to do hardware setting for baund rate and other stuffs.

my question is why tcsetattr does not finally call s3c24xx_serial_set_termios to set hardware setting?
Please point out my mistakes if I am wrong. Thank you very much.
 
Old 09-07-2009, 04:08 AM   #3
lxpwj
LQ Newbie
 
Registered: Sep 2009
Posts: 7

Original Poster
Rep: Reputation: 0
this issue is closed.

the source code itself is quite OK.
The problem is our cross-compiling enviroment setting. Thanks a lot.
 
  


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
serial port (and baud-rate) problem kafix Linux - Newbie 8 07-26-2007 04:54 PM
SF Thinstation redirected com port baud rate JoDee Linux - Software 0 09-11-2006 12:25 PM
Change the network baud rate zaheer031 Linux - Software 1 05-15-2006 11:37 PM
Reading Baud Rate of Serial Port zaheer031 Programming 1 09-27-2004 12:47 PM
How do I change ttyS port baud rate? joe_dejesus Linux - General 1 09-27-2001 09:50 PM

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

All times are GMT -5. The time now is 12:37 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