Best way/chip for an easy embedded interface between a PC <==>MCU ? - Page 1
Forum section: electronics / general

author: SuzyC
author_rank: Frequent Contributor
timestamp: August 18, 2019, 05:33:27 pm
content: Thanks in advance to anyone who can offer me some advice!I have looked at the FTDI website and there are many choices, which is the easiest, cheapest, best interface for PC<-->MCU communication.The chosen chip will become part of the MCU PCB.The MCU is operating at 5VThe PC is operating with WinXP SP3, has USB 2.0 ports and I am using VB6 to write code (PC cannot be changed to a newer op sys).

author: nctnico
author_rank: Super Contributor
timestamp: August 18, 2019, 05:56:40 pm
content: The best way is to have the USB software inside the MCU doing a virtual com port (CDC ACM device). That way the baudrate or any serial port parameter doesn't need to be set. It just works. I did one project for a customer where I used this and it makes life so much easier for them that they insist every product I develop for them has this type of USB interface. For Windows XP you'll need to create a .inf file which tells XP the USB VID/PID are a standard serial CDC port and install it as a driver.

author: MosherIV
author_rank: Super Contributor
timestamp: August 18, 2019, 06:04:39 pm
content: What does the interface do?It is difficult to answer unless you give more details.Most embedded processors have quite a few interface peripherals built in, eg usb and erthernet are very common. Wifi is starting to become well supported (built in erthernet + external transceiver devices).There are also the old classic RS232.

author: SuzyC
author_rank: Frequent Contributor
timestamp: August 18, 2019, 06:08:08 pm
content: The interface provides a way to send commands and data to a MCU and then receiving data back from the MCU when data is ready to be sent and/or when requested by the PC. Comm speeds of 115200 would be fast enough.The MCU is already chosen and designed into a machine control module that is now using the PC's legacy bi-directional parallel port.I am not aware of MCU's that have virtual comm ports nor do I would like the extended learning curve to develop a LAN interface.A LAN interface is not supported by the software I am writing the PC code with, and it would not be a good choice because it requires a very complicated revision of my PC and MCU code and its PCB and that would not be the best use of time and money.I would be most pleased to find a solution using the UART peripheral built into almost all MCU chips that would interface with a PC USB port.I am aware on EBay there are many fairly small USB-->Serial converter modules for Arduino, etc, but I would like to have a single chip solution on the existing PCB.

author: MosherIV
author_rank: Super Contributor
timestamp: August 18, 2019, 07:23:59 pm
content: So it sounds like serial/RS232 is what you are after.On the microcontroller, most offer some kind of serial peripheral. They only output logic level, 5V or 3.3V so the microcontroller is going to need an RS232 level converter like the old MAX232 chip.Most will allow data speeds upto 115200baud and beyond.Most modern pc do not provide RS232 ports anymore. If not, one of those usb serial adapters should work. I have used them many times before. Some are better than others, you may have to try a few before you find the right one.I would not recommend trying to bypass the level convert ie 5V level RS232 on both ends, level convert is there to give noise imunity.Whether you can achieve 115200 baud will depend mainly on how good the data lines are.Experiment to see what data speeds you can get, you might get better.Fyi virtual com port is just directing serial over usb. The host side just treats it as a serial comm port and the pc driver takes care of the conversion to usb. The micro end needs development of a usb serial device. Most micro vendors provide examples of this. On the micro, the output is usually in a buffer. Then you just connect usb to usb on both ends.

author: SiliconWizard
author_rank: Super Contributor
timestamp: August 18, 2019, 08:08:14 pm
content: Asking for the best way of doing this is like asking for the best programming language or something.Anyway, since you mentioned "The MCU is operating at 5V", we can only assume that the MCU is a given and we can't change it. So if it doesn't have an embedded USB core, suggesting to use an MCU with integrated USB will not answer your question, and you'll need an external chip.And that said, first tell us more about your requirements:- What is the expected max data throughput?- Do you want to support only WinXP? Is that a one-off project?

author: RoGeorge
author_rank: Super Contributor
timestamp: August 18, 2019, 08:36:12 pm
content: You are looking for CH340. 10 to 100 times cheaper than FTDI.

author: Fire Doger
author_rank: Regular Contributor
timestamp: August 18, 2019, 08:52:38 pm
content: FT232https://www.ftdichip.com/Products/ICs/FT232R.htmMCP2200https://www.microchip.com/wwwproducts/en/en546923#additional-featuresCP2102https://www.silabs.com/products/interface/usb-bridges/usbxpress-usb-bridgesCH340 ChineseFor all of them you need decoupling, you can avoid controlled impedance in usb if its very close to the connector, for the rest look their datasheet.I would go with CP2102, MCP2200 needs oscillator, ftdi killed chips in past with drivers and CH340 is for cheapass products

author: Mr. Scram
author_rank: Super Contributor
timestamp: August 18, 2019, 08:54:08 pm
content: Quote from: RoGeorge on August 18, 2019, 08:36:12 pmWhat you pay isn't what it costs.

author: rstofer
author_rank: Super Contributor
timestamp: August 18, 2019, 09:17:02 pm
content: If you come off of the MCU board at RS232 voltage levels, there are cables that start with the DB9 and end with a USB connector:https://www.amazon.com/Serial-Adapter-Prolific-Chipset-Windows/dp/B0753HBT12If you come off of the MCU with 3.3V or 5V logic levels, there are cables like:3.3Vhttps://www.amazon.com/Converter-Terminated-Galileo-BeagleBone-Minnowboard/dp/B06ZYPLFNB5Vhttps://www.amazon.com/Serial-Adapter-Female-FT232RL-Windows/dp/B07RBK2P47Any of these work, I have used them all.

author: SuzyC
author_rank: Frequent Contributor
timestamp: August 19, 2019, 12:26:11 am
content: I have >10 PC's with identical control PCB boards to modify. 115200 baud is fast enough. Just want to use a very easy to find USB to USB cable(like those used to connect a PC to a printer) to connect to the modified control board.----------CH340, "what you pay, isn't what it costs"I take that to mean that you get a lot of free trouble with this chip and to get it work right requires an enormous cost in time?-----------Why would and how could FTDI kill a chip with a driver??-----------May I offer a long serial stream of thanks to all that have gifted me with their advice and taken a moment to share their know how to implement a solution!-------------Looks like there are two recommended best choicesCP2102 and FT232RLWhich chip has the best easy to get it to work with no crashes/it just works driver?

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 19, 2019, 01:03:32 am
content: Quote from: SuzyC on August 19, 2019, 12:26:11 amBoth are good, The CP2102Nis newest version of CP2102, but the FT232RL is now quite old. The FT231X is probably a more modern choice.Get an Eval board for each one, and try them.Does the package matter ? Will you be making your own PCB, or buying a interface module ?If buying an interface module, you need to consider form factor and cable used.USB-A is cheap in a module, but those cables are now less common.eBay has many CP2102 modules, tho the eBay FT231X modules seem to be very silly prices - maybe they target someone who mistakes currency conversions ?eBay has better prices on the older FT232RL parts

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 19, 2019, 01:10:20 am
content: Quote from: SuzyC on August 18, 2019, 06:08:08 pmWhat MCU does this use now, and how fast does the parallel port send data ?If this is a legacy retrofit, did you look at the USB-Parallel port adapter cables on eBay ? You would need to try one, but that may be simpler than USB-UART and then some additional parallel step.eg USB to DB25 Parallel Port 25 Pins IEEE-1284 Old Printer Scanner Cables Adapters.

author: nctnico
author_rank: Super Contributor
timestamp: August 19, 2019, 01:18:47 am
content: Quote from: PCB.Wiz on August 19, 2019, 01:03:32 amBut these are likely fake. The problem with FTDI chips is that the driver kills fakes or doesn't work silently. This can lead to huge amounts of wasted time & frustration to track a problem. Don't use FTDI chips at all. The CP210x devices don't have a unique serial number so it will end up getting a different COM port every time you plug it in UNLESS you program a serial number yourself (not difficult but it is an extra step). All in all maybe the CH310 is a better choice if it has a unique serial number.

author: SuzyC
author_rank: Frequent Contributor
timestamp: August 19, 2019, 01:32:01 am
content: USB to parallel printer port adaptors have no programming language interface drivers for general I/O, their only use is to interface with the Win printer drivers.

author: SuzyC
author_rank: Frequent Contributor
timestamp: August 19, 2019, 01:35:09 am
content: "UNLESS you program a serial number yourself"Do tell, how is this done?-----------Some replies recommend FTDI chips and never mention a problem.It is beyond my imagination to see how any small company would have the resources(or any promise of profit) to undertake making clone FTDI chips.

author: rstofer
author_rank: Super Contributor
timestamp: August 19, 2019, 02:14:10 am
content: What about documentation and API support? If you plan to modify so few machines and you plan to use a chip solution, I would go genuine FTDI all the way.Is USB HID a possibility? If so, the drivers are built into WindowsFT 260 from FTDI

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 19, 2019, 02:36:20 am
content: Quote from: nctnico on August 19, 2019, 01:18:47 amReally ? I've not seen that problem at all. Keeps the same COM port just fine...Windows can vary IDs across a windows-reboot, but that's on all COM devices and more a Windows side issue.

author: oPossum
author_rank: Super Contributor
timestamp: August 19, 2019, 02:40:33 am
content: It will typically get a new COM port number if you plug it into a USB port that it has never been plugged in to before.

author: MosherIV
author_rank: Super Contributor
timestamp: August 19, 2019, 07:02:41 am
content: QuoteHi.Have I miss-understood something?Does the micrcontroller (control board) have serial port or 8 bit port?As far as I know, usb serial or usb parallel port adaptors just provide a serial port or parallel port in software, then you put another driver ontop to talk serial of parallel.https://www.amazon.co.uk/slp/usb-to-serial-adapter/7mx4bkg982vz64rhttps://www.amazon.co.uk/DB25-female-parallel-adapter-cable/dp/B001D50VQE

author: Howardlong
author_rank: Super Contributor
timestamp: August 19, 2019, 07:53:46 am
content: An alternative to CDC is to implement a HID interface.Some benefits I see to HID over a CDC serial interface on XP:(1) No drivers or .inf files required for Windows XP.(2) You have 64 byte packets each way available every milllisecond, although in practice maximum throughput is about 32kB/s (~250kbps). 64 bytes allow you to tailor a structured interface protocol rather than having to parse a serial stream.There are already VB examples using HID in this way from vendors. I've used the Microchip MLA examples several times. The VB code for a custom hid device for the current MLA is in this directory \v2018_11_26\apps\usb\device\hid_custom\utilities\plug_and_play_example\windows\src\vb2008_express with the firmware here C:\Microchip\mla\v2018_11_26\apps\usb\device\hid_custom\firmware. There are examples supplied for about two dozen boards, from a PIC16 through to a PIC32MM.(I would avoid trying to use Microchip's MCC for USB, it is very limited and buggy, and instead stick to the MLA: I don't think MCC even supports HID anyway. Harmony [for medium to large PIC32 only] is just far too over-complicated and has a huge learning overhead).I am sure other vendors have similar HID solutions.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 19, 2019, 09:36:17 am
content: Quote from: SuzyC on August 18, 2019, 06:08:08 pmWhat is the MCU, and how does it interface with the parallel port - two way, or one way ? and which handshake signals, and what speed ?Do you have the source code for that MCU, or must this emulate the parallel port as a transparent retro-fit ?Do you have the messages sent (received?) and which parallel port mode it uses/expects ?You might be able to get a FT240X (two way FIFO) to handshake with a SPLD, to look like a parallel port. and the FT240X can 'look like' a serial port.

author: NorthGuy
author_rank: Super Contributor
timestamp: August 19, 2019, 12:51:56 pm
content: Quote from: SuzyC on August 19, 2019, 12:26:11 amIf your computer has a real COM port (it'll be eaither external DB9 or DB25 connector or a DuPont connector on MotherBoard), there's no reason to mess with USB. You can use RS232 to TTL converter instead, such as (just an example, never used this one):https://www.digikey.com/product-detail/en/texas-instruments/MAX202CDR/296-18480-1-ND

author: Mr. Scram
author_rank: Super Contributor
timestamp: August 19, 2019, 12:59:33 pm
content: Are MCUs with USB capabilities an option perhaps?

author: SiliconWizard
author_rank: Super Contributor
timestamp: August 19, 2019, 01:05:36 pm
content: Quote from: nctnico on August 19, 2019, 01:18:47 amAfter what happened with the drivers, still considering buying FTDI parts from dubious sources is complete madness.Buy them from official distributors or just buy something else.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 19, 2019, 07:49:19 pm
content: Quote from: SuzyC on August 19, 2019, 01:32:01 amGoogle finds thishttps://www.vogons.org/viewtopic.php?f=62&t=57919The appeal of the Cypress CY7C68013A, is it uses HS-USB, and so the USB microframes are 125us spaced, or 8 time more frequent than FS-USB.That extra speed, would help to 'look' more like a standard port, but the on-board MCU likely manages the handshake anyway.CY7C68013A modules are widely available so this would also be easy to verify.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 19, 2019, 07:52:34 pm
content: Quote from: SiliconWizard on August 19, 2019, 01:05:36 pmFair point, I was merely commenting on the price, as the FT231X were strangely high. Maybe no clones for those ?CP2102N is a better mainstream choice. Digikey have low cost (sub $10) compact modules like CP2102N-MINIEK

author: SiliconWizard
author_rank: Super Contributor
timestamp: August 19, 2019, 08:11:26 pm
content: Agreed.While (contrary to many who got totally put-off by FTDI's attitude) I consider FTDI products pretty good and recommend them for many reasons, I particularly do so for applications in which you need relatively high throughput (which to me means > 1MByte/s).Now if all you need is a simple USB connection with an UART port with low speed at one end (to me 115200 bds is low) and a virtual serial port on the host's side, there are cheaper solutions out there that are just as good. One thing that FTDI products offer that I'm not sure others do, is the ability to store some custom info such as VID/PID, a description string, serial number, etc. I don't know if CP21xx chips do? Or the CH34x ones?

author: nigelwright7557
author_rank: Frequent Contributor
timestamp: August 19, 2019, 09:00:55 pm
content: I took the USB project fromwww.waitingforfriday.com's website.It basically is a pc program and a PIC18F4550 PIC program and circuit that toggles an LED.You just build on that.Its a bit old hat now as it uses the C18 compiler.So I converted it to a PIC32MX and modern XC32 compiler.Done numerous projects with it now and all work well.