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: How to open /dev/tty port

Tool/software: Linux

I am using UART4_RXD/TXD for communication I have tried to open ttyO4 port but I can't able to find ttyO4 in the "/dev/ttyO4" directory. How can open /dev/ttyO4.

I used ti-processor sdk -linux-am335x v04.02 version.

SOURCE FILE

&am33xx_pinmux {
        [.......]

	uart4_pins: uart4_pins { 
		pinctrl-single,pins = <
		           0x70 (PIN_INPUT | MUX_MODE6) /*conf_gpmc_wait0.UART4_RXD*/
		           0x74 (PIN_OUTPUT | MUX_MODE6) /*conf_gpmc_wpn.UART4_TXD*/ 
		>;

	};

};

&uart4 { 
          status = "okay";
          pinctrl-names = "default"; 
          pinctrl-0 = <&uart4_pins>;
};

Thanks,

somkiat

  • Hello somkiat,

    Please, attach the complete boot log.

    Best regards,
    Kemal
  • Hi Kemal,

    first time, i confused little bit about a name of serial port. !now i can send data out to UART4 but i still have some problem from code below.

    #include<stdio.h>
    #include<fcntl.h>
    #include<unistd.h>
    #include<termios.h>
    
    int main(){
        int file, count;
        if ((file = open("/dev/ttyS4", O_RDWR | O_NOCTTY | O_NDELAY))<0){
            perror("UART: Failed to open the file.\n");
            return -1;
        }
        struct termios options; // the termios structure is vital
        tcgetattr(file, &options); // sets the parameters associated with file
        // Set up the communications options:
        // 9600 baud, 8-bit, enable receiver, no modem control lines
        options.c_cflag = B9600 | CS8 | CREAD | CLOCAL;
        options.c_iflag = IGNPAR | ICRNL; // ignore partity errors, CR -> newline
        tcflush(file, TCIFLUSH); // discard file information not transmitted
        tcsetattr(file, TCSANOW, &options); // changes occur immmediately
        unsigned char transmit[18] = "Hello BeagleBone!"; // the string to send
    
        if ((count = write(file, &transmit,18))<0){ // send the string
            perror("Failed to write to the output\n");
            return -1;
        }
    
        usleep(100000); // give the Arduino a chance to respond
        unsigned char receive[100]; // declare a buffer for receiving data
    
        if ((count = read(file, (void*)receive, 100))<0){ // receive the data
            perror("Failed to read from the input\n");
            return -1;
        }
        if (count==0) printf("There was no data available to read!\n");
        else {
            printf("The following was read in [%d]: %s\n",count,receive);
        }
    
        close(file);
        return 0;
    }

    OUTPUT


    Best regards,
    Somkiat

  • Hi Kemal,
    I remove the O_NONBLOCK and O_NDELAY options then example is working right now.
    Do you have any other examples about UART?

    Best regards,
    Somkiat
  • You can refer to this example.