Flow control on USB Serial

a.hinsen

Member
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
 
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.
 
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...
 
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)
 
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".
 
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!
 
Back
Top