0
\$\begingroup\$

From what it seems like, uart and usb are just two different ways of digital communication so it seems like if you just program a micro controller to accept uart through a couple io pins and put out usb in a couple other pins you could make a uart to usb bridge without buying anything. Kind of like translating languages. Is that how it works? Am I missing something? I am using a pic16f84a.

\$\endgroup\$
4
  • 4
    \$\begingroup\$ Yes, but not if your microcontroller is a PIC16. It doesn't have the proper hardware for USB. \$\endgroup\$
    – Hearth
    Apr 3 '20 at 18:17
  • \$\begingroup\$ thats like saying because a skateboard has wheels and a tow truck has wheels I can tow a car with my skateboard. The uart and usb are dedicated logic blocks within the chip, the pins are just ways to get to them from the outside, its not generic I/O that you can do anything with. either your chip has the hardware or doesnt. mcus with usb often do have a separate uart on separate pins and you can use that chip as a usb to uart bridge with the right software and understanding the speed limits of the uart when moving data \$\endgroup\$
    – old_timer
    Apr 4 '20 at 16:59
  • \$\begingroup\$ you keep asking USB questions for a chip that will not do USB, just get a different chip, there are thousands of options out there for ones or fives of dollars...dont need to keep beating this dead horse by asking the same questions over and over again. \$\endgroup\$
    – old_timer
    Apr 4 '20 at 17:01
  • \$\begingroup\$ The questions are actually all slightly different. I am trying to be specific and I had different ideas on how to do it that weren’t covered in the other questions. Plus I literally don’t have the money to buy another chip. \$\endgroup\$ Apr 4 '20 at 17:07
3
\$\begingroup\$

Any USB to UART bridge IC that you see in the market is already an MCU that has permanently committed firmware (may be in Flash or ROM). These also typically have dedicated UART and USB peripheral block on the chip. Using pure software to implement UARTs and USB line level protocol severely limits speed possibilities and would generally not be practical.

Many of the more modern day MCUs that have on board USB controller peripherals will have available App Notes and reference code that shows how to build a USB UART bridge. In some cases this just becomes a part of a much larger application that runs on the MCU. In particular if you have some 200MHz 32-bit MCU this becomes very practical to even support an RTOS and task processing for an application in addition to the bridge functionality.

Note: An MCU operating in this manner as a bridge is referred to as a USB CDC class device.

\$\endgroup\$
8
  • \$\begingroup\$ Would it still be slow if I dedicated the whole micro controller to converting uart to usb and had a second micro controller to run my other programming? \$\endgroup\$ Apr 3 '20 at 18:50
  • \$\begingroup\$ @user11937382 A dedicated PIC16 IS not enough if that is what you are asking. To DIY is a more difficult project than whatever it is your actual project is. Even the most powerful microcontrollers don't try to bit bang native USB. They use their USB peripheral. \$\endgroup\$
    – DKNguyen
    Apr 3 '20 at 18:53
  • \$\begingroup\$ Is pic16 not fast enough? Or does it not have enough memory to hold the whole thing? \$\endgroup\$ Apr 3 '20 at 19:00
  • \$\begingroup\$ @user11937382 - I do not know how fast your PIC16 is but in my experience trying to make a bit banged UART transmit and receive in software using just GPIO pins when running at a frequency of say 16->25MHz you will find yourself baud rate limited at about 1200 baud or so. USB is many times faster so not at all practical to bit bang even if you try to confine yourself to the ancient USB1.1 speed spec. \$\endgroup\$ Apr 3 '20 at 19:32
  • 1
    \$\begingroup\$ @user11937382 Much, much, much more powerful processors are not fast enough to do it. They might have enough memory but not enough speed. The PIC16 is hopelessly, woefully, utterly lacking in both speed and memory for the task. USB is everywhere but that does not mean it is simple. It is very, very complicated. You could be a professional and still not know anywhere near enough to try to attempt what you are suggesting. \$\endgroup\$
    – DKNguyen
    Apr 3 '20 at 22:27
1
\$\begingroup\$

if you just program a micro controller to accept uart through a couple io pins and put out usb in a couple other pins you could make a uart to usb bridge without buying anything. Kind of like translating languages. Is that how it works?

Not really. From high theoretical computer-science standpoint, from a view of 20,000 feet, it might look that way. However, in reality it is quite different.

The UART is a primitive serial transfer protocol, START+eight-bit-toggling+STOP, no structures, addresses, data correction nor acknowledgement. Sent and hope that other receiver will catch it. At most a LF is expected back. But one can call it a "UART packet".

The basic USB requires to follow a strict protocol for exchange of highly-structured data, that are arranged in "packets". USB packets have SYNC, Packet ID, DATA, CRC, and EOP. The PID-DATA+CRC are encoded in a special way to maintain a balanced +-signal, to avoid the data lines to stay in one state for too long, unlike in UART. Classic USB uses NRZI encoding with "bit stuffing".

The packet exchange requires certain order called "transaction", which usually includes SETUP phase with ADDRESS, DATA phase, and USB device must respond back with some packet acknowledging correctness of received data. So typically it takes three individual packets for a "transaction".

Then the USB transactions are arranged into "transfers", which include SETUP, DATA (might be many DATA packets), and acknowledge packets for each DATA, both ways. There are also CONTROL transfers, which have SETUP stage, DATA stage, and STATUS stage, so typical control transfer (to set or get some parameter from device) takes 9 individual USB packets, each having SYNC-PID/ADDRESS-CRC_EOP structure.

More, responses to incoming packets are time-limited to under 1.7 us response time, so not many MCU are able to decode a packet, verify its checksum, and respond back under 2 microseconds. Therefore the support for USB protocol is usually implemented in hardware, at least the time-critical parts. This is called USB SIE - Serial Interface Engine. While the order and generation of transfers is a responsibility of USB HOST and is not your concern, devices must obey the SIE rules, decode all packets, and respond properly in time.

A USB device becomes functional after a process called "enumeration", which includes reading device capabilities and functional purpose (aka "device descriptors"), receiving individual USB address, selecting/initializing "device configuration". This enumeration typically takes a dozen of control transfers, and it must occur before any bridge between USB DATA and UART DATA can be established.

Given this brief "crush" course in USB, you now decide if you can implement this SIE ("put out usb in a couple other pins") in your PIC16 micro-controller.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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