📜 ⬆️ ⬇️

USB to AVR. Introduction


We will talk about the popular USB interface, namely how to use this very USB on simple AVR microcontrollers. I plan to write a few topics with code examples and explanations from both the microcontroller and the computer. Of course, the Internet is full of all sorts of examples on this topic, but at best, this is the source code in which the devil himself breaks a leg, but a short, per page, its description.

To begin with, previously widely used interfaces like COM, LPT, MIDI are now obsolete, but still often present on modern computers and used in industrial and highly specialized equipment. So, to connect some sort of your own piece of hardware with a computer, it’s already time to master something else. As an option, you can still use any converters / adapters / emulators, but they do not always work as the original interface, causing a lot of problems.

Everything is enough empty chatter, get down to business. How to use USB in your own devices?


We are real Jedi, so let's take the emulation path. At the moment, there are already three ready-made projects for USB software emulation on AVR microcontrollers:

The project from Igor Češko was the first to be written entirely in assembler and it served as a kind of inspiration for V-USB. On its basis, a noteworthy universal IR receiver for a computer was made , as well as many other projects. V-USB, in turn, is written in C, albeit using assembly code in places critical to performance and accuracy of emulation. USBtiny is derived from an earlier version of V-USB, it has fewer features, which makes it theoretically easier to understand.
image
I stopped at the implementation of the V-USB, I think these are the main advantages:

image
In my experiments with USB firmware for MK, I wrote C in AVR-Studio 4 + WinAVR, I developed a program for PC using Borland C ++ Builder 6.0 as the fastest and simplest option. Accordingly, these will be all future examples. In general, the choice of development tools is a very crucial step, but it is not necessary to organize a holivar about what is better than C or Assembler. I will say simply: these are only tools in our hands. You need to own all and use the one that is more convenient and correct for the goals set for yourself. Naturally in skillful hands any tool is effective.
You also need to separately say about the VID and PID. These are 16-bit numbers, with the help of which the operating system determines the devices and loads the necessary driver. In order to get a Vendor-ID you need to pay usb.org $ 2000 . Interesting thoughts about the legality of using VID / PID can be found on the BSVi Embedder page . The fact that V-USB provides a free pair of VID / PID (legally purchased at usb.org) is very warm for the soul. But what to do when you need to simultaneously connect multiple USB devices with the same VID / PID? It's okay, in addition to these VID / PID, each USB device has VENDOR_NAME and DEVICE_NAME identifiers, then in the examples I will show how to use it.
Some links on a subject:

In conclusion, I will write that all the conditions for creating USB 1.1 devices are available to everyone:

Only one thing remains - the desire to understand! And then work wonders on penny microcontrollers for all the majors for envy.
')
I plan to write another topic, with the practical implementation of a running line that receives data via USB.

Source: https://habr.com/ru/post/125253/


All Articles