Einzelne Bits der serillen Schnittstelle mit ioctl() setzen geht (nicht)



  • Hallo,

    Ich arbeite aktuell an einem Bitbanging Algo für i2c über die serielle Schnittstelle. Grundsätzlich kann ich einzelne Signale der UART (RTS/CTS) mit ioclt() setzen. Beim Debugging mit dem Oszilloskop habe ich jedoch gemerkt, dass sich manchmal (ich kenne die Bedingungen dazu nicht) sich der elektrische Zustand des RTS-Signal nicht ändert, obwohl das Bitmuster inkl. RTS mit ioctl() gesetzt bzw. verändert wurde.

    Hier die Funktion, welche das RTS-Signal meistens zuverlässig setzt.

    int setRTS(unsigned short level)
    {
         int status;
    
         if (ioctl(serialfd, TIOCMGET, &status) == -1) {
    	  perror("setRTS(): TIOCMGET");
    	  return 0;
         }
         if (level) { status |= TIOCM_RTS;}// set high bit pattern
         else {
         	status &= ~TIOCM_RTS; // set low bit pattern
         }
         if (ioctl(serialfd, TIOCMSET, &status) == -1) { 
    	  perror("setRTS(): TIOCMSET");
    	  return 0;
         }
         return 1;
    }
    

    Ich öffne das Serial Device mit folgenden Optionen:

    serialfd = open( "/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
    

    Ansonsten greift kein Prozess auf ttyS0 zu. Hat jemand von euch bereits ähnliches erlebt? Kann das an der Initialisierung der Schnittstelle liegen?

    Danke für die Hilfe.



  • Hallo nochmals,

    Gleich dazu noch, wie ich die Schnittstelle initialisiere:

    //Configure the port
    	options.c_cflag = 0;				//Clear all flags (if you don't, many bits
    	options.c_iflag = 0;				//must be cleared manually to ensure the
    	options.c_oflag = 0;				//correct mode is chosen)
    	options.c_lflag = 0;
    	cfsetispeed(&options, B1200);		//baud rate: 1200 kpbs
    	cfsetospeed(&options, B1200);
    	options.c_cflag |= CS8;				//8 data bits (no parity and 1 stop bit are default)
    	options.c_iflag |= (IXON | IXOFF | IXANY);	//Software flow control
    	options.c_cflag |= CREAD;			//Enable the reciever
    	options.c_cflag |= CLOCAL;			//Set "local" mode
    	options.c_cflag &= ~HUPCL;        	/* clear the HUPCL bit */
    	options.c_cc[VEOL] = 13;			//CR byte
    	options.c_cc[VEOL2] = 10;			//LF byte
    	options.c_cc[VSTART] = 17;			//XON byte
    	options.c_cc[VSTOP] = 19;			//XOFF byte
    	options.c_cc[VMIN] = 0;				//No blocking
    	options.c_cc[VTIME] = 0;
    

Anmelden zum Antworten