Teensy Ports vs. Serial Ports

minishcap

Member
In the Arduino IDE you can select the Serial Monitor to communicate with a Teensy, but when uploading to a USB device type without serial as an option you can still use it; why? What is a Teensy port vs. a serial port? Does this mean I don't even need to select serial as an option if I want to send data back and forth between my PC and the Teensy? I could use a Python library to make serial communication easy, but what would I use for this Teensy port type of communication?

Or maybe I'm just misunderstanding things lol, some clarification would be appreciated!
 
There is a Serial Emulator USB type that Paul created as part of the Teensy code base, that is used in several of the USB types that do not include Serial. I am not sure if it is documented anywhere, except the code.

Earlier I added support into the USBHost_t36 to be able to use it if you plug one Teensy into another.

You might look at that library at the file SerEMU.cpp
 
There is a Serial Emulator USB type that Paul created as part of the Teensy code base, that is used in several of the USB types that do not include Serial. I am not sure if it is documented anywhere, except the code.

Earlier I added support into the USBHost_t36 to be able to use it if you plug one Teensy into another.

You might look at that library at the file SerEMU.cpp
Ahh, I figured it must be something like that - pretty cool how it just works for monitoring. Speaking of USBHost_t36, is there any extra configuration needed to use its USB A for serial communication instead of the default micro USB? I was thinking of emulating some HIDs via software, but if plugged into anything other than a PC you can't really use that same port to receive data from a program. The workaround I'm thinking of is PC -> USB A on Teensy / micro USB on Teensy -> any device that takes HID input, but I'm not sure if USB A serial is as plug and play as the default serial connection through micro USB.
 
USB isn't anything like serial, where both sides are essentially the same type of hardware. With different connector serial types you basically just have to worry about connecting TX to RX and vice versa. USB doesn't work anything like that.

USB has 3 very different hardware roles, called Host, Device, and Hub.

The host is typically your PC. Devices are things like keyboard and mouse. Each USB bus must have exactly 1 host. Devices NEVER communicate with each other. They only talk to the host. Hosts can't talk to each other directly, because each bus can have only 1 host.

Host and devices are so fundamentally different that early USB standards used different shape connectors. The original concept was you simply could not create an invalid connection because the connectors couldn't physically plug in.

USB protocol is quite complicated, but the basic concept is the host initiates all communication, 1 device at a time. The many devices reply only when the host asks. All data transfer from device to host is actually accomplished by the host repeatedly sending "IN" tokens to every device. When a device has more data to send to the host it replies to that token, and even when it has no data, it still replies but with a NAK token. It's not anything like simple serial communication where each side just transmits data whenever it wants. USB is a bus where the host controls all communication and the devices only communicate when instructed by the host. USB serial devices must buffer incoming serial bytes and only transmit to the host when the host instructs them to send. Of course the host can send whenever it wants, but there too USB has a complex protocol which includes flow control. It's different from RTS/CTS used by old serial lines, but achieves the same effect, fundamentally built into the USB protocol.

USB serial adapters (FTDI, CP2102, etc) are USB device hardware. Typically micocontroller boards have USB device hardware.

But some like Teensy 4.x and Teensy 3.6 also have a USB host port. The Teensy host port functions pretty much the same as the host port on a regular PC. The host port supports USB serial the same way your PC does, where you plug in a USB serial device and a device driver on your PC uses that adapter (functionally as if it were a card physically installed inside your PC). Likewise on Teensy, for the host port you use the USBHost_t36 library and in your program you create instances of all the device drivers you want to be available for use when a USB device is plugged into the host port, or plugged into any hubs you've connected.

Not sure if this helps answer your question, but if you were imagining things working as traditional old serial, hopefully this gives a bit of insight into how USB works.
 
Definitely helps! Just waiting on my soldering iron to get here so I can connect the pins needed for the host cable. Will be my first time soldering so wish me luck haha 😫
 
Back
Top