Purpose of this article is to inform readers about implementation USB interface into singlechip microcontroller, which this interface directly not supports. Simply: implementation USB interface on firmware level (similar as emulation of RS232 interface in microcontrollers, which not have RS232 support). This project includes development of firmware on microcontroller side, driver development on computer side (for Windows operating system) , development of DLL library for functions calling from another programs (programmers level) and development of demo program (users level), which shows all functions of this device. Device is named IgorPlug-USB (AVR) (as successor of my previous device for computer remote control IgorPlug - serial port version).
At present time is USB interface very popular especially
within end user. This is due to the simplicity to the end users (Plug and Play,
without restart). For developers is implementation of USB into their
devices more complicated (with comparison to RS232 is USB more complex
protocol). In addition there is need of software support on PC side - device
drivers. Therefore more devices from small vendors are inclined to RS232
communication. This interface is probably the oldest in PC history and has good
operating system support. But in latter years is RS232 removing from standard
included PC interfaces (new computers hasn't RS232). In this case help only
add-on PCI card with this interface.
Implementation of
USB into external devices is at present time solved in two
choices:
a) First is using
microcontroller, which have hardware implemented USB interface. Then
is necessary to know how USB works and according this write firmware into
microcontroller. And in addition is necessary to create driver on the computer
side (while operating system not includes it - e.g. standard USB classes).
Disadvantage (and this is the main disadvantage for small vendors and amateurs)
is not good availability of this microcontrollers (PIC, Cypress, Atmel, Intel,
...) and their high price (with comparison to simple "RS232"
microcontrollers).
b) Second option is to use some universal converter between USB and "another"
interface. This "another" interface depends on type of convertor:
there are used especially RS232, 8-bit data bus, I2C bus. In this case is not
need of special firmware (actually we needn't to know how USB works) and no need
of driver writing (vendor of converter offer free drivers). Disadvantage is
higher price of the complete device and greater dimensions of product (need of
one chip more).
My solution,
which I have resolved to develop - and successfully finished ;-) -
is USB implementation into cheap microcontroller
through the emulation of USB protocol in firmware of
microcontroller. Problem during design was microcontroller speed.
Speed of USB bus is too high: LowSpeed - 1.5Mbit/s, FullSpeed - 12Mbit/s,
HighSpeed - 480Mbit/s. Normal microcontrollers are maximum performance cca:
AT89C2051 - 2MIPS = 24MHz/(12cycl/inst.), PIC16F84 - 5MIPS =
20MHz/(4cycl/inst.), AT90S23x3 - 10MIPS = 10MHz/(1cycl/inst.). There exist
microcontrollers with highest speeds too, but they are poorly available (price
too) and are biggest (more pins - difficult construction). For all that I have
decided for microcontrollers PIC16F84 or AT90S1200/AT90S23x3, which would be
"enough" for LowSpeed USB. For highest USB speeds is this solution not good -
for one bit from USB processing is need of several cycles of microprocessor:
reading, comparison, storing, some operation, ... .
Firstly I choose PIC16F84-20, with which I have experiences. To ensure
synchronizing with USB clock and speed increasing was used microcontroller clock
24MHz = 6MIPS (PIC was slightly overclocked). For one bit from USB processing
were 4 instructions (4=6MIPS/1.5Mbit for LowSpeed USB). I reject this solution
(after some time) - PIC is too slow (and in addition the no so good instruction
set ...) .
Second try was AT90S1200-12, which
satisfied me with its speed - possible to receive and transmit signal on
LowSpeed USB speed. But I reject this solution too - absence of enough program
and data memory - simply small memory to implement this.
Third try was successful: AT90S2313-10 (or AT90S2323-10, AT90S2343-10).
This are RISC microcontrollers from Atmel production - AVR family. With
comparison with PIC are slow crystal clock, but have 1 instruction per crystal
clock (PIC16F84 has to 1 instruction per 4 crystal clock). In addition their
instruction set and architecture is nearly to RISC. Again because of
synchronization with USB clock I used overclocking to12MHz (AT90S23x3-10 are
initially to10MHz only). In this manner I obtained more performance and 12MHz
crystals are "easy to obtain" (with comparison to e.g. 10.5MHz - which is the
multiple of LowSpeed USB clock 1.5Mbit/s too).
My solution offer very simple and cheap hardware (cca
3,-US$). All intelligence is in firmware. Construction is designed as infrared
remote control of computer through USB (successor of construction for serial port ), but this is
universal USB interface too.
This device allow:
Thanks to versatility is possible to use microprocessor on place of universal converter e.g. in application where we want to control (read and write) some input-output pins. Possible application are e.g.: to pins we directly connect I2C thermometer, inputs and outputs of security device, or simply only LED diodes or LCD/LED display etc., etc., etc. .
On the next picture is schematic:
with
microprocessor AT90S2313-10 (universal interface):
or with microprocessor AT90S2323-10 (only for IR code receiving) - not
tested yet, but designed for this purpose - was tested by users - WORKS
GOOD:
and physical construction (IR receiver: computer remote control for
program Girder):
Simplicity of device is truly wondrous. And is accessible for amateurs too - for their devices connection to USB (this always enjoy - I know this according my experience, when Windows first time find this "New hardware found" ;-) ). Firmware - the heart of device - is the same for both microprocessors. In 8-pin version (AT90S2323-10) you can use only infrared code receiving and writing/reading to/from EEPROM. But 8-pin version is by dimension probably the smallest device connected to USB (SMD version).
For success communication between USB device and computer,
there is necessary to give driver for device. This driver is requested by
operating system during first connection IgorPlug-USB (AVR) into USB
connector in computer. In the future maybe this driver will not be necessary :
by change in firmware is possible, that device will be standard USB class (HID
class, Storage Class ,...), - for this classes has operating system build-in
drivers. Advantage of own driver is, that we have control of driver behavior. I
choose for "own" driver only because of learning "how this works" and mainly for
simplicity of implementation into firmware of device.
Next pictures shows device installation steps
(and driver installation) on the first plugging IgorPlug-USB
(AVR) into USB connector. Driver is the same for Windows98, WindowsME,
Windows2000 and WindowsXP (under Windows95 not works):
Firstly under WindowsXP:
Windows find device IgorPlug-USB (AVR).
Choose install from our location.
Here we browse to folder with
installation files (INF file and SYS driver)
Windows do some necessary changes.
Driver have not digital signature from Microsoft -
but we not stop installation.
Windows make backup (for safe recovery ;-) ).
And in case when Windows don't to find SYS driver,
...
... then we give to him
correct path to driver.
And installation is finished:
And under Windows98:
The same as under WindowsXP, only in
another visual form.
After success installation
we can look at device in "Device manager":
Device Manager
under WindowsXP:
Device Manager under Windows98:
As I mentioned - for correct device operation is necessary
driver, which is requested by operating system during installation. This
driver
I not wrote alone - I used one freeware USB driver and for this driver I adapted firmware. Thanks to
versatility of this driver this solution is conform to me. I only slightly
modify this driver I wrote in Microsoft Windows2000 DDK enviroment (and
has some improvements - comparison with old driver). Name of this driver is
"IgorPlug.sys" and is included in installation
pack.
For installation is necessary installation descriptive file INF. Just this file was
requested by Windows during installation of device and we must browse to folder
with this INF file if we are asked for driver location. In this file is install
information for given device - and according to this information will be
installed driver and eventually will be made other actions. I was created this
INF file according to template file from my USB book. Because every USB
device must have assigned vendor number (VID) from USB-organization
(USB-IF), then I "borrow" this number from company Atmel (I
hope that Atmel excuse me this borrowing - I won't to pay cca 1500 US$ for
number assignment) and I implement it into microprocessor and into INF file.
Name of this file is "IgorPlug.inf" and is included in installation pack.
So for device installation are necessary only two files
("IgorPlug.sys" a "IgorPlug.inf").
By this way we
had successfully installed device IgorPlug-USB (AVR). And we can go to
test it. For this purpose I had written DLL
library "IgorUSB.dll", which contains functions, which device
IgorPlug-USB (AVR) makes. This DLL library communicates with driver
"IgorPlug.sys" and provide serialization of communication (when we are
using DLL from more threads or applications). Library DLL is primary dedicated
for programmers of end user applications for access to device: exported functions from DLL are
published.
Next pictures shows information
about DLL library and SYS driver as was displayed under WindowsXP:
Finally I had created end user
application - exemplar program
"AVR to USB tester", which shows all functions of device IgorPlug-USB
(AVR). It call functions from DLL library "IgorUSB.dll" and is in fact the
sample program.
Program
functions:
Next picture shows functions of demonstrational program AVR to USB tester and its properties (in WindowsXP style):
For programming AVR microcontroller is necessary
programmer. But commercial programmer is for most users hard to obtain
because its high price. Therefore I design simple LPT
programmer of this microlontrollers
- simple connection to computer LPT port. For this programmer I wrote control
software - inside it is also firmware of device IgorPlug-USB
(AVR) (only start program and burn microcontroller) and also schematics
of programmer (for both microcontrollers: AT90S2313 and AT90S2323).
Here
is schematic of programmer and its control program (works under WinXP
too):
You can download control software in download section.
Development of this device was cca 4 months long (every
evening after work cca 4 hours - long evenings ;-) ) + previous study and
knowledge about USB and AVR microprocessors. Therefore this was not too easy (I
must all study, watch, try alone). But now is no problem for me to change some
function of microcontroller (e.g. omit "infra-buffer" and instead it to
implement RS232 buffer). And USB is now nothing "unknown" for me (from the
physical level to end user application).
Idea of this project was in my head
cca 2 years (after my first download of USB specification) - reborn was after
similar project of one Russian "developer", which make this - but this was only
his All Fools Day joke (but at that time I give the lie to his device). But his
project was impulse for me to my project activity and to slogan : nothing is
impossible ;-) .
The biggest "unknown" was understand all USB specification (but really all -
from the physical level to end user level). Therefore study of USB was very
important. The main information source was USB specification (free
download from http://www.usb.org/) and lately
book "USB Měření, řízení a regulace pomocí sběrnice USB" from
publisher BEN . And of course various internet
sources.
During development I was using for testing many "test" a "information utility"
downloaded from internet (USBcheck, DisplayUSB, SnoopyPro, Fiddler, ...).
For firmware development I was using free tool "AVR Studio 4" (from Atmel-u pages) and programmer "T51prog"
(from Elnec company). For "physical
observation" was used "Scopemeter FLUKE 123" (wonderful device) from FLUKE . As template design of USB device was
for me USB mouse "Genius NetScroll+" from Genius company (bought in Agem-e). The microprocessor (and the
"unsuccessful" too) I has bought in GM-electronic . So Many Thanks to all for
help.
I was using for development next programs and
many thanks of their creators:
And who want to see more pictures from my
"development place" , here are:
DevelopmentBoard1,
DevelopmentBoard2,
DevelopmentBoard3,
DevelopmentBoard4,
DevelopmentPlace1,
DevelopmentPlace2,
DevelopmentTools1,
DevelopmentToolsElnecProgrammer,
TargetDeviceAtmelAVR,
TargetDeviceToUSBcable,
LiteratureAndInformationSource.
And
some information about my device IgorPlug-USB (AVR) as was dislayed by test utilities:
USBDesignByExample,
USBCheckFullTest,
USBCheckDeviceDescriptor,
USBCheckConfigurationDescriptor,
USBCheckInterfaceDescriptor,
USBCheckEndpointDescriptor,
USBCheckViewDescriptors,
USBCheck,
SnoopyProDeviceDescriptor,
SnoopyProConfigurationDescriptor,
SnoopyProVendorCommand,
......enough (for unfamiliar persons are this not so clearly).
Firmware into
microprocessor is available in HEX-file
and now also as source code (I publish it for
more users requests - for adding your own functions). And now I publish
documentation of PC software support (that was in the past only in full
version). Of course: commercial use is not free. As freeware I
publish e.g. computer remote
control on serial port , (and all other my projects) and even if I was
requesting small development fee from satisfied users, so from cca 20 000
downloads (about which I know) will be helpful only one person (4US$ - thank
you) (although time for answering to cca 1500 e-mails is too much). So there is
rule - if there is something free only per voluntary - no wait from
anybody.
Because I
want that device will be available for more users, then
for download is : IntelHEX file for
AT90S23x3-10, driver , DLL-library for access to IgorPlug-USB (AVR)
and demonstration program for control of
IgorPlug-USB (AVR) (so all :-o ).
In the next I
publish source code of firmware of
microcontroller and also documentation of DLL
library (for writing your own applications). Documentation is for
Delphi, C++Builder/Visual C++, Visual Basic. So everybody
can try how the device work.
For fast device
construction is available also simple LPT
programmer of given microcontrollers (AT90S2313-10 and AT90S2323-10).
And for less experienced users is small installation
guide (step by step).
There is only one
limitation of this "free" version - DLL library shows information window during
the first run (functions is the same). For your own application will be
better to buy registered version of DLL library. For vendors, which
want to sell complete product:: programmed microprocessor + CD
with full version of software and documentation, I offer full versions
for distribution (of course with my copyright). According this way I want to
remove problems with payment - end users will be buying from internet shops of
local vendors in your country.
Price for end user will be cca 150,-Sk
(Slovakia) or 4,-Euro (Europe) or 4,-US$ (other world). For distributors will be
of course discount (after contract with me).
The persons concerned for documentation and for commercial
usage of product can contact me by e-mail.
For utilization of product as computer
remote control - is recommended to read article IgorPlug
.
DOWNLOAD:
Here is the download (ZIP
archive):
IntelHEX into
AT90S23x3-10, installation files (driver), DLL library (free version), exemplar
application. This files can be changed in the future (according to
requests there will be changing only DLL library, SYS driver remain the
same).
For programming of microcontroller through
LPT port is necessary to download
IgorPlugUSBprogrammer.
And
developers will be interested in package:
firmware source
code into AT90S23x3 + interface to DLL library IgorUSB.dll
(please don't abuse). DLL function descriptions are for Delphi,
C++Builder/Visual C++, Visual Basic.
For end
users is very useful detailed installation
procedure (small install manual - step by step: plug device into USB,
there appear ... , then insert CD ... , etc.)
I am making decision to
publish (concerned person can contact me - I am making
consumer research):
- documentation
for DLL library : for programmers to write own application - IT ALREADY
BECAME
- source code for
microcontroller : for firmware changes to your specific functions - IT ALREADY
BECAME
- but this all only for non
commercial use!!! - THIS REMAINS VALID
History:
- January 2003 :
finishing, documented and publishing of project
- May 2003 : begin of
new project: implementation into ATmega8 as RS232+ converter (see my projects)
- July 2003
: finished implementation of improoved RS232+ interface into
ATmega and AT90S2313 (see IgorPlug-USB
(AVR) RS232.htm)
- August 2003 : created my own driver in DDK with
some improvements (more effective transfer, removed
problem during computer hibernation, ...)
- September 2003
: changed interface of DLL library for correct use in v C++ and Visual Basic
(modified documentation of DLL)
In case of problems with downloads - visit my mirror pages in Russia: http://www.cesko.nm.ru/downloads, or contact me by e-mail and I will send it to you by e-mail.
If you are satisfied with this my
smart idea - you can you can send to me some small financial payment
(amount of payment is your choice): Bank account number:
5006722891-1100, for foreign payment is shift
code: TATR SK BX.
Tested on operating systems:
- Windows95 - no
function (need to rewrite driver)
- Windows98, Windows XP, Windows
2000 : fully functional and
tested
- Windows ME : should
be fully functional
but not tested (you can test it - and give me answer by e-mail)
Hardware
requirements:
- minimal tested configuration : Intel Pentium
120MHz without MMX, 32MB RAM (Windows 98) (my old PC)
For the persons concerned to build this device as USB receiver like small USB key I prepared documentation: PCB layout, schematic and PCB devices location. This documentation you can see here as PDF file.
WORLDWIDE:
- Lukáš Dziadkowiec offer on his website
well looks USB receiver with all software for computer remote
control. The persons concerned find all necessary information on his website (with many photos).
Delivery is possible worldwide by post -
very reliable vendor.
SLOVAKIA:
-
(in preparation is Pavol
Bielopotocký)
- Vrták František offer on website http://vrtak.webpark.sk/ USB receiver without cover (good solution to 3.5/5.25´ slot in computer) or also in small box in SMD version. Delivery by post. Info, photos and prices is on this site.
- Branislav Rozbora : all information is on http://sektor-x.wz.cz/.
CZECH REPUBLIC:
- Lukáš Dziadkowiec offer on his website
well looks USB receiver with all software for computer remote
control. The persons concerned find all necessary information on his website (with many photos).
Delivery is possible Czech republic by
post.
- Jiři Kalkus : offer USB and serial version. Cable length is optional by customer (0-10 m). Price of USB version is 350,-Kč (1.5m cable). Delivery is possible by post in all Czech Republic or personally in towns Ceske Budejovice and Prague. Contact: tel: +420721758094, e-mail: djbj@volny.cz , ICQ: 230642851, webpage: www.volny.cz/djbj
RUSSIA:
- Evgeniy
Melnikov offer on his website USB receiver. Site: http://evm.wallst.ru
page: http://evm.wallst.ru/main/igorusb/index.htm
Price: receiver (hardware) - 7$, DLL (full version) - 4$. Delivery is fast, cash
on delivery (in Russia), or delivery is
possible in Chelyabinsk (face-to-face).
e-mail: msevm@mail.ru.
SINGAPORE (ASIA PACIFIC REGION):
- Han Loke Su : from Singapore site offer USB and Serial
versions. For DIY, offers SFH5110-38 and AT90S2313-10PI as well. More info
on website: http://www.alldiy.info/
Delivery is possible within Asia Pacific
region by post.
In case of your interest to sell this
"product" (programmed microprocessor + CD with
documentation and software) I publish your address (or another contact) on
this place. Condition is reliability of your customers. Price of device will be
contracted (cost free for small production volume!!!). You can contact me by e-mail.
http://www.cesko.host.sk/ - section
Hardware
www.cesko.host.sk/girderplugin.htm
- remote control of computer by infrared remote control
http://www.appliedp.sk/ - company for which I
am working and developing something from another brand
http://www.usb.org/ - all about USB bus
and
another: ...
This site will be continuously renewed with new information (which will be interest).
author: Ing. Igor
Češko:
e-mail: cesko@internet.sk
homepage: http://www.cesko.host.sk/