Serge Serge

Com-port using ttymxc0

Discussion created by Serge Serge on Apr 23, 2012
Latest reply on Apr 26, 2014 by Norman C

Hi!

 

I'm trying to make an application using ttymxc0 as a ComPort, but the problem is that it doesn't receive data, only sends.

 

What should I check?

 

MX53-LOCO U-Boot > printenv
bootdelay=3
baudrate=115200
loadaddr=0x70800000
netdev=eth0
ethprime=FEC0
uboot=u-boot.bin
kernel=uImage
nfsroot=/opt/eldk/arm
bootargs_nfs=setenv bootargs ${bootargs} root=/dev/nfs ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp
bootcmd_net=run bootargs_base bootargs_nfs; tftpboot ${loadaddr} ${kernel}; bootm
bootcmd_mmc=run bootargs_base bootargs_mmc; mmc dev 0; mmc read ${loadaddr} 0x800 0x1800; bootm
bootcmd=run bootcmd_mmc
ethact=FEC0
bootargs_base=setenv bootargs console=ttymxc1,115200 di0_primary console=tty1
bootargs_mmc=setenv bootargs ip=192.168.10.24 root=/dev/mmcblk0p1 rootwait rw
stdin=serial
stdout=serial

stderr=serial

 

/etc/inittab

# see busybox-1.00rc2/examples/inittab for more examples

::sysinit:/etc/rc.d/rcS

#::respawn:/sbin/getty -L ttymxc0 115200 vt100

::ctrlaltdel:/sbin/reboot

::shutdown:/etc/rc.d/rcS stop

::restart:/sbin/init

 

The application

#include <stdio.h>
#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 */

int main(void) {

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

    if (fd == -1) {
        //Could not open the port.
        perror("open_port: Unable to open port ");
    }
        else
            fcntl(fd, F_SETFL, FNDELAY);
        //fcntl(fd, F_SETFL, 0);


    struct termios port_settings;

    cfsetispeed(&port_settings, B115200);
    cfsetospeed(&port_settings, B115200);

    port_settings.c_cflag &= ~PARENB;
    port_settings.c_cflag &= ~CSTOPB;
    port_settings.c_cflag &= ~CSIZE;
    port_settings.c_cflag |= CS8;

    tcsetattr(fd, TCSANOW, &port_settings);

    char s[] = "Hello, this is a test of the serial port access";

    int cnt;
    unsigned char in[100];

    for(cnt=0; cnt<1000000; cnt++)
    {
        int n = write(fd, s, sizeof(s));
        if (n < 0)
            fputs("write() failed!\n", stderr);

        usleep(500000);

        int ReadData = read(fd, in, 100);

        if (ReadData > 0)
        {
           printf("%s\n", in);
        }
    }

    return 0;
}

 

Any idea?

 

Yours faithfully

Serge

Outcomes