Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: USART port driver query
PostPosted: Thu Mar 03, 2011 3:42 pm 
Offline

Joined: Thu Dec 30, 2010 6:49 pm
Posts: 38
Hi,

This is regarding USART driver support on SAM9G45. As this chip support 5 USART port, i see below driver files are created in /dev by some code in the kernel.

ttySAC0
ttySAC1
ttySAC2
ttySAC3
ttySAC4

1. Now i want to access ttySAC0, can i write a application using read() and write() on the driver file to talk to USART port?

2. Can anyone point me to the location in the code where these driver files are created?

3. How do i set Baud rate for this port? If their an ioctl() interface to this?

4. When i do echo 1 > ttySAC0 or ttySAC1, i don't see anything on the Hyperterminal.

Thanks
Prashanth


Top
 Profile  
 
 Post subject: Re: USART port driver query
PostPosted: Mon Mar 07, 2011 11:59 am 
Offline

Joined: Wed Dec 15, 2010 10:40 am
Posts: 9
Hi, try this :
//**********************************************/
int rs232_test(void)
{
int ret = 0,sz;

/* configure serial ports */
system("stty -F /dev/ttyS0 raw isig opost speed 115200 -echo -icanon min 1 time 0 > /dev/null");
system("stty -F /dev/ttyS1 raw isig opost speed 115200 -echo -icanon min 1 time 0 > /dev/null");

int fd_1, fd_2;
char buffer[255];
char * test = "TEST UART !!!";

/* open devices */

fd_1 = open("/dev/ttyS0",O_RDWR | O_NDELAY);
fd_2 = open("/dev/ttyS1",O_RDWR | O_NDELAY);

/* test 1 -> 2 */
write(fd_1,test,strlen(test));
usleep(10000);
/* test receive char from RS232 2*/
if (read(fd_2,buffer,sizeof(buffer))<0) *buffer = 0;
if (strncmp(buffer,test,strlen(test))) {ret |= (1<<0);}

/* test 2 -> 1 */
write(fd_2,test,strlen(test));
usleep(10000);
/* test receive char from RS232 1*/
if (read(fd_1,buffer,sizeof(buffer))<0) *buffer = 0;
if (strncmp(buffer,test,strlen(test))) {ret |= (1<<1);}

close(fd_1);
close(fd_2);

//Just test ret value if everything is OK
return ret;

}
//*******************************/
Regards.
Seb


Top
 Profile  
 
 Post subject: Re: USART port driver query
PostPosted: Thu Mar 10, 2011 6:29 am 
Offline

Joined: Thu Dec 30, 2010 6:49 pm
Posts: 38
Thanks for the reply. Will give it a try.

Over the few days i have tried the following code, but even /dev/ttySAC2 fails to open
What could be problem?

=======================================
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<termios.h>
#include<errno.h>

int main()
{

int fd;
char buf[3] ="444";
unsigned int cnt = 0;

fd = open("/dev/ttySAC2", O_WRONLY);

if (fd == -1)
printf("\n Error opening file");
else
printf("\n File opened successfully ");



while(1)
{

if(write(fd, buf, 3) != 3)
write(2, "Error2\n", 7);

printf("iteration = %d", cnt++);

sleep(5);

}

close(fd);


}


Top
 Profile  
 
 Post subject: Re: USART port driver query
PostPosted: Thu Jul 07, 2011 8:52 pm 
Offline

Joined: Fri Jan 16, 2009 10:46 pm
Posts: 44
hello,

I have a very strange problem, I'm using sam9263 with serial driver, I can receive perfectly but the driver doesn't trasmit...is there any problem regarding the start of trasmission?
below the code used for test: any idea on what is happening or missing...
thanks

#define NUMBER 10
int main()
{
int fd; /* File descriptor for the port */
struct termios options;
char data_send[NUMBER];
char data_receive[NUMBER];
char ch;
unsigned int SendCount;
unsigned int ReceivedCount = 0;
int i;

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

if (fd == -1)
{
perror("open_port: Unable to open /dev/ttyS0 - ");
}
else
fcntl(fd, F_SETFL, 0);

/*
* Get the current options for the port...
*/

tcgetattr(fd, &options);

/*
* Set the baud rates to 19200...
*/

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

/*
* Enable the receiver and set local mode...
*/

options.c_cflag |= (HUPCL | CLOCAL | CREAD);
options.c_cflag &= ~CSIZE; /* Mask the character size bits */
options.c_cflag |= CS8; /* Select 8 data bits */
options.c_cflag &= ~PARENB; /* Parity mode : no parity */
options.c_cflag &= ~CSTOPB;

// options.c_cflag |= CNEW_RTSCTS; /* Also called CNEW_RTSCTS/CRTSCTS, Enable hardware flow control */
options.c_cflag &= ~CRTSCTS;

// options.c_lflag |= (ICANON | ECHO | ECHOE); /* canonical input */
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); /* raw input */

// options.c_iflag |= (INPCK | ISTRIP); /* set input parity option */

// options.c_iflag |= (IXON | IXOFF | IXANY); /* enable software flow control */
options.c_iflag &= ~(IXON | IXOFF | IXANY);

// options.c_oflag |= OPOST;
options.c_oflag &= ~OPOST;

options.c_cc[VMIN] = 0; /* minimum number to read */
options.c_cc[VTIME] = 10; /* Time to wait */


/*
* Set the new options for the port...
*/

tcsetattr(fd, TCSANOW, &options);


for(i=0;i<10000;i++)
{
ch = 'h';
printf("sending, fd = %d, char = %c\n",fd,ch);
SendCount = write(fd, &ch,1);
if(SendCount < 1)
return 1;
}

i = 0;
ReceivedCount = 0;
while(1)
{

printf("receiving, fd = %d\n",fd);
// i = read(fd, data_receive + ReceivedCount, NUMBER - ReceivedCount);
i = read(fd, &ch, (int) 1);

if (i != 0)
{
data_receive[ReceivedCount+i] = ch;
ReceivedCount += i;
printf("%c\n", ch);
}

if(ReceivedCount == NUMBER)
break;
}


close(fd);
return 0;
}


Top
 Profile  
 
 Post subject: Re: USART port driver query
PostPosted: Mon Jul 18, 2011 5:09 pm 
Offline

Joined: Fri Jan 16, 2009 10:46 pm
Posts: 44
Hi All,

I'm still facing the problem on the USART0 (ttyS1) on sam9263 KaeilOS distribution:
I can receive the characters on the serial port but I cannot trasmit: is there any way to debug what is happening, maybe enabling kernel debug output?

thanks
bob


Top
 Profile  
 
 Post subject: Re: USART port driver query
PostPosted: Mon Jul 18, 2011 5:09 pm 
Offline

Joined: Fri Jan 16, 2009 10:46 pm
Posts: 44
Hi All,

I'm still facing the problem on the USART0 (ttyS1) on sam9263 KaeilOS distribution:
I can receive the characters on the serial port but I cannot trasmit: is there any way to debug what is happening, maybe enabling kernel debug output?

thanks
bob


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: