This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/AM3352: UART1 read issue

Part Number: AM3352


Tool/software: Linux

Hi All,

We want to use UART1 to read the data using UART1. We have a custom board using am3352(Sitara) processor.

We are able to send the data, how ever we are not able to read using the same UART. We are using the default configuration at a baud rate of 9600.

The "read()" function call in linux gets unblocked when any data is received, but no of bytes read is showing as zero.

What could be the issue with it.

Regards

Sudipta.

  • Hi Sudipta,

    Can you elaborate more ? How did you set baud rate in AM335x ? What software package you are using ?
  • Hi Dwarakesh,

    Thanks for your reply. Actually I am am to update using the sample program that I got from internet to read from UART.

    I have attached the program file for your reference. Please assist me.

    #include <sys/stat.h>
    #include <fcntl.h>
    #include <termios.h>
    #include <stdio.h>
    #include <string.h>
    #include <errno.h>        
    #include <stdlib.h> 
    #define BAUDRATE B9600 
    #define MODEMDEVICE "/dev/ttyS1"/*UART NAME IN PROCESSOR*/
    #define _POSIX_SOURCE 1 /* POSIX compliant source */
    #define FALSE 0
    #define TRUE 1
    void openport(void);
    void sendport(void);
    void readport(void);
    int fd=0, n = 0;
    static int cnt, size, s_cnt;
    unsigned char *var;
    struct termios oldtp, newtp;
    char sendcmd1[10]="\0";
    FILE *file;
     
    void  readport(void)
    {
    	unsigned char buff;
    	file = fopen( "zname.txt", "w+" );
    	while (1) 
    	{ 
      		n = read(fd, &buff, 1);
    		printf("Total no of Bytes Read %d\n", n);
    		//fcntl(fd,F_SETFL,0);
     		if (n == -1)
    		{
    			switch(errno)
    			{
             			case EAGAIN: /* sleep() */ 
                			continue;
              
             			default: goto quit;
             		}
    		}
    
      		if (n == 0)
    		{
    			break;
    		}
      
    		fputc(buff, file);
      		printf("%d %c\n", n,buff);
      	}
    quit:
       fclose (file);
    }
    
    void openport(void)
    {
             
    	 fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY |O_NDELAY );
    	 printf("oviya :%d\n",fd);
             if (fd <0)
             {
             	perror(MODEMDEVICE);
     
             }
                                                                                    
             fcntl(fd,F_SETFL,0);
             tcgetattr(fd,&oldtp); /* save current serial port settings */
        //     tcgetattr(fd,&newtp); /* save current serial port settings */
             bzero(&newtp, sizeof(newtp));
      //       bzero(&oldtp, sizeof(oldtp));
                                                                                    
             newtp.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
                                                                                    
             newtp.c_iflag = IGNPAR | ICRNL;
                                                                                    
             newtp.c_oflag = 0;                                                                        
             newtp.c_lflag = ICANON;                                                                    
             newtp.c_cc[VINTR]    = 0;     /* Ctrl-c */
             newtp.c_cc[VQUIT]    = 0;     /* Ctrl-\ */
             newtp.c_cc[VERASE]   = 0;     /* del */
             newtp.c_cc[VKILL]    = 0;     /* @ */
            // newtp.c_cc[VEOF]     = 4;     /* Ctrl-d */
             newtp.c_cc[VTIME]    = 0;     /* inter-character timer unused */
             newtp.c_cc[VMIN]     = 0;     /* blocking read until 1 character arrives */
             newtp.c_cc[VSWTC]    = 0;     /* '\0' */
             newtp.c_cc[VSTART]   = 0;     /* Ctrl-q */
             newtp.c_cc[VSTOP]    = 0;     /* Ctrl-s */
             newtp.c_cc[VSUSP]    = 0;     /* Ctrl-z */
             newtp.c_cc[VEOL]     = 0;     /* '\0' */
             newtp.c_cc[VREPRINT] = 0;     /* Ctrl-r */
             newtp.c_cc[VDISCARD] = 0;     /* Ctrl-u */
             newtp.c_cc[VWERASE]  = 0;     /* Ctrl-w */
             newtp.c_cc[VLNEXT]   = 0;     /* Ctrl-v */
             newtp.c_cc[VEOL2]    = 0;     /* '\0' */
       	                                                                                                                                             
    //	  tcflush(fd, TCIFLUSH);
    //	 tcsetattr(fd,TCSANOW,&newtp);
     
    }
    
    int  main()
    {
    	openport();
    	readport();
            return 0;
    }
    

    Regards

    Sudipta.

  • Hi Sudipto,

    What is connected to the other end of UART ? How sure are you, that the other end is sending data ?