1
\$\begingroup\$

An industrial device can be connected to a host computer via a standard USB port. The USB port on the device itself is indeed a CH340 USB-to-TTL converter, which allows to control the device through a known set of clear text commands. In Windows the device appears as a standard COM port. Now I need to communicate with the USB device using a low level communication interface, such as a standard TTL serial port from a budget microcontroller. What exactly do I need to interface with the device? Is there any chip I can use to interface TTL with a USB "slave" device?

\$\endgroup\$
8
  • 2
    \$\begingroup\$ You need anything with USB host and drivers for CH340. You will need to spend much more than a budget microcontroller anyway so you might as well use something that can directly communicate with it, such as a cheap Windows PC or single board computer that runs Linux. But any MCU with USB host will do, as long as you can write drivers for CH340. \$\endgroup\$
    – Justme
    Sep 20, 2022 at 20:58
  • 2
    \$\begingroup\$ I agree with Justme. The cheapest you can get away with (time and cost wise) is probaby a Raspberry Pi or similar. \$\endgroup\$
    – Dejvid_no1
    Sep 20, 2022 at 21:02
  • \$\begingroup\$ @Justme Nope. I do not need drivers. It is just a simple serial interface. That's why I wrote "raw mode" communication. Even far more complex devices, such as printers, can be interfaced in raw mode. Thus, the USB host functionality is the only thing that I am missing. Any idea how to emulate that? \$\endgroup\$
    – Francesco
    Sep 21, 2022 at 5:17
  • 1
    \$\begingroup\$ @Francesco You don't seem to understand how USB or how "simple" USB serial chips or devices work. You need to know what to communicate with the CH340 chip to make it do what you want. Just like you need drivers to communicate with USB CDC or USB storage devices, you need drivers to communicate with CH340. And USB host can't really be emulated, you need an actual MCU with actual USB host. \$\endgroup\$
    – Justme
    Sep 21, 2022 at 5:40
  • \$\begingroup\$ @Justme This does not convince me. How is it possible that a USB host functionality cannot be "emulated"? After all it is just voltage signal levels. Moreover, this is a bare USB CDC which actually does not need a real "driver" but only an inf file with a signature id. \$\endgroup\$
    – Francesco
    Sep 21, 2022 at 7:24

1 Answer 1

2
\$\begingroup\$

The easiest way, as said in comments, is to use a small Linux computer such as a Pi. Otherwise you have to organise quite a bit of software.

If you want to try that, consider a Raspberry Pi Pico, which has a USB host controller.

However, the difficulty will be the driver (thanks @justme).

You might be able to use https://github.com/hathach/tinyusb, which is supposed to do communications devices; and you might need the code for CDC340, which is manufacturer's C source available for the chip here.

From the Pico datasheet:

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ This answer is true, but like I said in comments, having a USB host is not enough. You need the USB driver stack, which runs the USB host, with a device driver to communicate with the CH340. Do you know if there are CH340 drivers for the Pico? So what you suggest may be impossible unless there happens to be such a driver for it. Otherwise the CH340 drivers need to be written. \$\endgroup\$
    – Justme
    Sep 21, 2022 at 4:14
  • \$\begingroup\$ @justme of course you're quite right; I edited my answer accordingly. \$\endgroup\$
    – jonathanjo
    Sep 21, 2022 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.