Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: Flow control on USB Serial

  1. #1
    Junior Member
    Join Date
    Dec 2015
    Location
    Hungary
    Posts
    10

    Flow control on USB Serial

    Dear Guys!
    ESP8266 based boards having USB port can be switched to programming mode, and back by the arduino IDE automatically. This is accomplished by a ch340 chip on the boaerd, that converts the usb communication into TTL rs232 including the hw flow control signals (in addition to Rx and Tx). The DTR and RTS outputs of the CH340 are connected (via 2 transistors) to RST and GPIO00 lines of the ESP8266, this is how the CPU can be switched to programming mode.
    I am using ESP8266 based boards without USB. To program these boards you usually need an USB-serial adapter AND you need to connect two push buttons to the RST and GPIO00 lines, so you can switch the board to programming mode manually.
    I want to use my teensy3.2 as a programmer to replace the USB-serial adapter and the push buttons. The Teensy would simply forward any data between Serial(usb) and Serial1(RxTx), and set the state of 2 output pins (to be connected to ESPs RST and GPIO00) based on the DTR and RTS status of Serial(usb).
    Question: Is there a way to obtain the DTR and RST status of Serial on Teensy?
    Thanks in advance!
    Andrew

  2. #2
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,318
    On Teensy 3.2, 3.5, and 3.6 there is support for setting pins for transmit enable, RTS, and CTS. Once you set these pins, the Serial code does the flow control for you. While you can use any pin for transmit enable and RTS, the pin for CTS is fixed:


  3. #3
    Junior Member
    Join Date
    Dec 2015
    Location
    Hungary
    Posts
    10
    Thank you Michael, but I am afraid there is a misunderstanding:
    You are talking about the flow control for SerialX (X=1,2,3...6) that is happening on the pins
    My question refers to Serial that is happening over the USB port. I couldn't find an answer to my question on the link you provided
    USB->Serial chips (such as Profilic PL2303, FTDI FT232, CH340 etc) are able to "extract" flow control information from the USB communication. I hope Teensy is also able in some way.

  4. #4
    Senior Member
    Join Date
    May 2015
    Location
    San Francisco
    Posts
    177
    Looking at the usb_serial.h header file, I see the following methods for usb_serial_class which is what Serial is:

    Code:
            uint8_t dtr(void) { return (usb_cdc_line_rtsdtr & USB_SERIAL_DTR) ? 1 : 0; }
            uint8_t rts(void) { return (usb_cdc_line_rtsdtr & USB_SERIAL_RTS) ? 1 : 0; }
    Haven't tested it yet but will later...

  5. #5
    Junior Member
    Join Date
    Dec 2015
    Location
    Hungary
    Posts
    10
    Sounds promising! Any idea what to #include in order to have usb_cdc_line_rtsdtr defined? (I couldn't find it in any installed lib)

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,684
    You don't need to include anything extra. Teensyduino provides these as an extension to the normal Serial.

    Just use Serial.dtr() and Serial.rts() to read the status of those signals controlled by software on your PC.

    For example:

    Code:
      digitalWrite(2, Serial.dtr());
    This stuff is documented here:

    https://www.pjrc.com/teensy/td_serial.html

    Scroll down to "Teensy USB Serial Extensions".

  7. #7
    Junior Member
    Join Date
    Dec 2015
    Location
    Hungary
    Posts
    10
    Hi Paul! I trusted teensy has a solution I feel sorry for not checking documentation enough thoroughly, because I believe in the concept of documentation in a world that is dumped with poorly documented and poorly tested stuff such as esp.
    Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •