8 Replies Latest reply on Aug 30, 2016 1:03 PM by Intel Corporation

    UART1 flow control

    shmkv

      Hi,

      I connected UART1 to RS485 transceiver. I used RTS pin for data direction control. The problem is that UART1_ RTS always is active low. I tried to control the flow manually, but nothing happened (see the code below). How I can control the RTS? Could Edison control the flow automatically (without ioctl) when sending and receiving data?

       

      ...
      //open port
      attr.c_cflag |= CRTSCTS | CLOCAL;
      attr.c_oflag = 0;
      tcsetattr(fd, TCSANOW, &attr)
      ...
      //try set RTS
      ioctl(fd,TIOCMGET,&status); 
      status |= TIOCM_RTS;
      ioctl(fd, TIOCMSET, status);
      
        • 1. Re: UART1 flow control
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hello shmkv,
           
          I believe what's happening to you is what is described in https://communities.intel.com/message/298991#298991. The Edison might be too fast for the buffer to be filled causing RTS to stay low all the time.
           
          If you would like to control Edison's UART with an IO library I suggest you to use mraa (https://github.com/intel-iot-devkit/mraa). You can check http://iotdk.intel.com/docs/master/mraa/uart_8h.html to learn about mraa's UART capabilities.
           
          I hope this information helps you.
          -Peter.

          • 2. Re: UART1 flow control
            shmkv

            Hi Peter,

            As I understand it, the first method is only applicable for the Arduino board (I do not have it).  Anyway, I do not have gpio with such numbers. Using the source code MPAA also did not help (and I did not see anything new and interesting in them). I strongly doubt that the Edison too quickly switches the RTS.  I look at oscilloscope (25MHz), and can not see anything. I learned how to control the RTS as a GPIO. To do this, you need to configure this output

            echo mode0 > /sys/kernel/debug/gpio_debug/gpio129/current_pinmux

            However, this method is inconvenient because of synchronization problems. It would be easier if there was no buffering. I do not know ways to disable it..

            upd:

            Now I send so

            write(rts, "1", 1);
            write(fd, data, sizeof(data));
            tcdrain(fd);
            write(rts, "0", 1);
            

            But I think there is a better way.

            • 3. Re: UART1 flow control
              Intel Corporation
              This message was posted on behalf of Intel Corporation

              Hi shmkv,

              Why do you say that mraa does not work for you? It has a method to enable UART's flow control, have you checked http://iotdk.intel.com/docs/master/mraa/uart_8h.html#abf0e5f97dfcbf227e03a4e1b2225dfd2? I believe that method might be helpful for you.

              If you still believe mraa is not suitable for your project, could you please explain us how you would like to accomplish this?

              -Peter.

              • 4. Re: UART1 flow control
                shmkv

                Hi Peter,

                I believe that method might be helpful for you.

                I also thought method might be helpful for me, but nothing came of it. In RTS always logical 0. Maybe I used the mraa wrong. I would like to see examples with flow control. In mraa source code I saw the most usual calls Linux Api for work with serial port. I got the impression that this is just a wrapper, but I may be mistaken.

                could you please explain us how you would like to accomplish this?

                I want to when sending the data (using posix function write) RTS automatically set to logical 1 and was reset on completion. There is a big project for the desktop version of Linux and it runs on Edison without porting, but there is a problems with a serial ports and RTC.  It would be really nice to see a working example of the code that configures the port as I want.

                • 5. Re: UART1 flow control
                  0andriy

                  The driver of 8250 UART and compatibles has got rs485 emulation support only recently.  I doubt the one is used in Edison official BSP has it or some variation of.

                  • 6. Re: UART1 flow control
                    Intel Corporation
                    This message was posted on behalf of Intel Corporation

                    Hello shmkv,
                     
                    I’m not aware of any example that uses flow control, however, let me check if I can find any method to accomplish what you are describing. On the other hand, submitting an issue in mraa's GitHub about this might be a good idea, they could provide some inputs about it.
                     
                    -Peter.

                    • 7. Re: UART1 flow control
                      shmkv

                      Hi Peter,

                      I decided that in the near future I will change uart mfd driver as I want. The driver uses interrupts that I am encouraged.

                      • 8. Re: UART1 flow control
                        Intel Corporation
                        This message was posted on behalf of Intel Corporation

                        If that's the case, then I encourage you to post your progress in the community. Other users might find your results useful.
                         
                        Anyhow, if you have any other doubts, feel free to post them in the community. We'll try to help you in any way we can.
                         
                        -Peter.