uart communication doubts..

Hi, i am new to using linux.
i wanted to just work on UART of my beagleboard.
when i do echo "1" > /dev/ttyS2
i see a pulse on CR-Oscillocsope.

i wrote the following code to send some data out of my uart tx pin and
see some pulse/disturbance on the CR-Oscillocsope.

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>

int main()
{

        struct termios tio;

       const char *device = "/dev/ttyS2";
    char c;
  int tty_fd;
  tty_fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
  if(tty_fd == -1) {
    printf( "failed to open port\n" );
    return EXIT_FAILURE;
  }

    memset(&tio,0,sizeof(tio));
        tio.c_iflag=0;
        tio.c_oflag=0;
        tio.c_cflag=CS8|CREAD|CLOCAL; // 8n1, see termios.h
for more information
        tio.c_lflag=0;
        tio.c_cc[VMIN]=1;
        tio.c_cc[VTIME]=0;

        cfsetospeed(&tio,B115200); // 115200 baud
        cfsetispeed(&tio,B115200); // 115200 baud

        tcsetattr(tty_fd,TCSANOW,&tio);
    tcflush(tty_fd, TCIFLUSH);

    while(1)
    {
            scanf (" %c \n ",&c);
                write(tty_fd,&c,1);
                 }
}

Please tell me what is wrong with my code , if there is any,

regards,
bumble..

this code works on my host comp… when i test it on CRO, i see a pulse… but
when i cross compile it and take the object file to the board, it gives me an error. saying unexpected ‘(’ in the obj file…

how should i run it on my board… ??

bumble,

That error looks funky … what command are you doing ? can you copy the whole session, so we can see the exact error message ?

BTW, if you’re only interested in observing pulses with you oscilloscope, don’t bother writing a program for that, just use:

cat > /dev/ttyS2

on the shell command line.

this code works on my host comp... when i test it on CRO, i see a pulse..
but
when i cross compile it and take the object file to the board, it gives me
an error. saying unexpected '(' in the obj file..

how should i run it on my board.. ??

Seems like something is wrong with your cross compilation process.
apply the command from your terminal
file application_name.c in your host PC where you cross compiled.And
check whether it's giving proper ARM file description or not .

Thanks for your replies,
the problem was due to erred cross compilation.
I worked it out.. It is working fine now..

Welcome ! !

Hi,
If i am not wrong… How can i see the echo [ shorting Tx, Rx and see the character sent on the terminal]
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>

int main()
{

struct termios tio;

const char *device = “/dev/ttyS0”;
char c[4];
char d[4];
int i=0;
int tty_fd;
tty_fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
if(tty_fd == -1) {
printf( “failed to open port\n” );
return EXIT_FAILURE;
}

memset(&tio,0,sizeof(tio));
tio.c_iflag=0;
tio.c_oflag=0;
tio.c_cflag=CS8|CREAD|CLOCAL; // 8n1, see termios.h for more information
tio.c_lflag=0;
tio.c_cc[VMIN]=4;
tio.c_cc[VTIME]=0;

cfsetospeed(&tio,B115200); // 115200 baud
cfsetispeed(&tio,B115200); // 115200 baud

tcsetattr(tty_fd,TCSANOW,&tio);
tcflush(tty_fd, TCIFLUSH);

while(1)
{
while( i < 3 )
{
c[i]=getchar();
c++;
}
c[4]=’\0’;
write(tty_fd,c,4);

read(tty_fd,d,4);
d[4]= ‘\0’;
printf("%s", d);
}
}
that is my code to see the echo…
Please tell me what went wrong…

Thanks and regards…
Bumble.

Hi guys,

there is some code modification required now…
Please test my code by shorting Tx and Rx … and send your suggestions on that Code.

Thanks and Regards…

yeah…
i got the communication… i could get the Echo…
i attach my code here…
short Tx and Rx … u will see what u have entered…

omap35uart.c (1.64 KB)