AppNote_USBtoRS232
Transcript of AppNote_USBtoRS232
-
8/11/2019 AppNote_USBtoRS232
1/17
AVR309 USB to UART protocol converter
Features: USB protocol implemented in firmware low
cost USB solution for small devices Supports ow Speed USB !"#$%&it's( inaccordance wit) USB"#" and USB*#0
+mplementation runs on ver, small AVR devices-from *.B,tes and up#/ nl, one e1ternal component re2uired for USBconnection !one resistor(
Ver, small footprint- startin from t)e S045AT90S*3*3
+mplemented functions: 6irect +' pin control-USB to RS*3* converter- 778R% scratc) reister
User can implement own functions !USB to T+control- USB A'6 and 6'A converter- (
Vendor customi;a&le device name !visi&le from
user side( Full 8< side support: full documentation )ow toaccess device !6 li&rar, functions(/ 71amples for developers on )ow tocommunicate wit) device !6elp)i-
-
8/11/2019 AppNote_USBtoRS232
2/17
-
8/11/2019 AppNote_USBtoRS232
3/17
sync pattern, then wait for two ;eros, and startrecei"ing data
ata reception on USB must satisfy thatrecei"er and transmitter are in sync at all times,therefore it is not permitted to send a stream ofcontinuous ;eros or ones on the data lines TheUSB protocol ensures synchroni;ation by bitstuffing This means that, after < continuousones or ;eros on the data lines, one singlechange (one bit) is inserted +s signal on USBlines are >#G& coded, this means that one ;erobit is inserted into the logical data stream after #G& ata =ncoding
66aattaa77nnccooddiinnSSee22uueennccee::
BBiittSSttuuffffeedd66aattaa
RRaaww66aattaa
AARR++
77nnccooddeedd66aattaa++ddllee
SS,,nncc88aatttteerrnn
SS,,nncc88aatttteerrnn
SS,,nncc88aatttteerrnn
88aacc..eett66aattaa
88aacc..eett66aattaa
SSttuuffffeeddBBiitt
SSii1100nneess
88aacc..eett66aattaa
!igure otification of end of data transfer is madeby and =DP (endofpac*et) part =DP consistsof $ ;eros on both data lines (both physical
+T+C and +T+ are at low "oltage le"el) =DPis succeeded by a short time of idle state (min $periods of data rate) +fter this, the nexttransaction can be performed
TP=#&DB
BifferentialBata 1ines
=DP.idth
Bata'rosso"er
1e"el
!igure H =DP .idth Timing
ata between sync pattern and =DP is >#G&coded communication between USB de"ice andhost The data stream is composed by pac*etsconsisting of se"eral fields Sync field (syncpattern), Pac*et& (P&), +ddress field (+#),=ndpoint field (=>P), ata, and 'yclicredundancy chec* field ('#') Usage of thesefields in different types of data transfer isexplained well in I8J USB describes four types oftransfer 'ontrol Transfer, &nterrupt Transfer,
&sochronous Transfer, and Bul* Transfer =ach ofthese transfers is dedicated for different de"icere0uirements, and their explanations can befound in I8J
Dur de"ice is using 'ontrol transfer Thistransfer mode is dedicated for de"ice settings,but can also be used for general purposes&mplementation of 'ontrol transfer must exist one"ery USB de"ice, as this mode is used forconfiguration when the de"ice is connected(obtaining information from de"ice, setting de"iceaddress, etc) + description of the 'ontroltransfer and its contents can be found in I8JandI8J =ach 'ontrol transfer consists of se"eralstages Setup stage, ata stage and Statusstage
ata is in USB transferred in pac*ets, withse"eral bytes each The pac*et si;e isdetermined by each de"ice, but is limited byspecification !or 1owSpeed de"ices, pac*et
si;e is limited to - bytes This - bytes longpac*ed C beginning and ending field must berecei"ed into the de"ice buffer in one USBtransfer &n hardwarebased USB recei"ers, the"arious parts of the transfer are automaticallydecoded, and the de"ice is notified only whenthe entire message has been assigned for theparticular de"ice &n a firmware implementation,the USB message must be decoded by firmwareafter the entire message has been recei"ed intothe buffer This gi"es us the re0uirements andlimitations The de"ice must ha"e a buffer forstoring the whole USB message length, another
buffer for USB transmitting (prepared data totransmit), and administration o"erhead withmessage decoding and chec*ing +dditionally, ofcourse, the firmware is re0uired to perform fastand precise synchronous speed reception (fromphysical pins to buffer) and transmission (frombuffer to pins) +ll these capabilities are limitedby microcontroller resources (speed andprogram5data memory capacity), so the firmwaremust be carefully optimi;ed &n some cases themicrocontroller computation power is "ery closeto the minimum re0uirements and therefore allfirmware must be written in assembly
-
8/11/2019 AppNote_USBtoRS232
4/17
GND
VCC
+
C2
10u
XT112MHz
1
2
3
4
XC1
USB-A
RST1
PD0/RXD2
PD1/TXD3
XTAL24
XTAL15
PD2/INT06
PD3/INT17
PD4/T0
PD5/T1!
GND10
VCC20
ICP/PD611
AN2/PB012
AN1/PB113
PB214
"C1/PB315
PB416
M"SI/PB517
MIS"/PB61
SC#/PB71!
IC1
AT!0S2313-10 / AT$%&'2313
DATA+
DATA-
GND
VCC
VCC
C1100&
GND
GND
GND
VCC
D0
D1
D2
D3
D4
D5
D6
D7
T(D
R(D
RS232 TTL
D1
3V6
D2
3V6
GND GND
R2
6R
R3
6R
R1
2)2
R2
4)7
VCC
!igure - USB interface with +T98S$%2% (as USB to #S$%$ con"erter with %$ byte !&!D C -bit &5D
control C 2$- bytes ==P#D4)
GND
XT112MHz
T(D
R(D PC6/RST
1
PD0/RXD2
PD1/TXD3
XTAL2/T"SC2/PB710
XTAL1/T"SC1/PB6!
PD2/INT04
PD3/INT15
PD4/T0/XC#6
PD5/T111
GND
AVCC 20
PD6/AIN012
PD7/AIN113
PB0/ICP14
PB1/"C1A 15
PB2/SS/"CIB 16
PB3/M"SI/"C2 17
PB4/MIS" 1
PB5/SC# 1!
AR* 21
GND 22
PC0/ADC0 23
PC1/ADC1 24
PC2/ADC2 25
PC3/ADC3 26
PC4/ADC4/SDA 27
PC5/ADC5/SCL 2
VCC7
IC1
AT,.
R1
2)2+
C210u
1
2
3
4
XC1
USB-A
DATA+
DATA-
GND
VCC
GND
GND
VCC
VCC
C1100&
GND
VCC
VCC
GND
RS232 TTL
D3
D4
D5
D6
D7 D2
D3
D4D5
D0
D1
D2
D3
D4
D5D6/RST
D13V6 D23V6
GND GND
R3
6R
R4
6R
R2
4)7
VCC
GND
!igure 9 USB interface with +Tmega- (as USB to #S$%$ con"erter with -88 byte !&!D C ==P#D4 C &5Dcontrol C ==P#D4)
-
8/11/2019 AppNote_USBtoRS232
5/17
The USB data lines, +T+ and +T+C, areconnected to pins PB8 and PB2 on the +@#This connection cannot be changed because thefirmware ma*es use of one +@# finesse for fastsignal reception The bit signal captured from thedata lines is right shifted from 1SB (PB8) to carryand then to the reception register, which collectsthe bits from the data lines PB2 is used as inputsignal because on -pin +T98S$%$% this pin canbe used as external interrupt &>T8 (no additionalconnection to &>T8 is necessary E the -pin"ersion of the +@# is the smallest pin counta"ailable) Dn other +@#s, an externalconnection from +T+C to the &>T8 pin isnecessary if we want to ensure no firmwarechanges between different +@# microcontrollers
!or proper USB de"ice connection andsignaling, the +@# acting as low speed USBde"ice must ha"e a 23*ohm pullup resistor on+T+
The other components only pro"idefunctions for proper operation of themicrocontroller 'rystal as cloc* source, andcapacitors for power supply filtering
This small component count is sufficient toobtain a functional USB de"ice, which cancommunicate with a computer through the USBinterface This is a "ery simple and cheapsolution Some additional components can beadded to extend the de"ice functions &f we wantto recei"e an signal, we can add theTSDP2H%- infrared sensor &f we want to use thede"ice as an USB to #S$%$ con"erter, we
should add the 4+K$%$ TT1 to #S$%$ le"elcon"erter &f we want to control 1= diodes ordisplay, we connect them to &5D pins directly orthrough resistors
+mplementation+ll USB protocol reception and decoding is
performed at the firmware le"el The firmwarefirst recei"es a stream of USB bits in one USBpac*et into the internal buffer Start of receptionis based on the external interrupt &>T8, whichta*es care of the sync pattern uring reception,only the end of pac*et signal is chec*ed (=DP
detection only) This is due to the extreme speedof the USB data transfer +fter a successfulreception, the firmware will decode the datapac*ets and analy;e them +t first it chec*s if thepac*et is intended for this de"ice according to itsaddress The address is transferred in e"eryUSB transaction and therefore the de"ice will*now if the next transferred data are dedicated toit USB address decoding must be done "ery0uic*ly, because the de"ice must answer with an
+'L handsha*e pac*et to the USB host if it
recogni;es a "alid USB pac*et with the gi"enUSB address Therefore this is a critical part ofthe USB answer
+fter the reception of this bitstream, weobtain an >#G& coded array of bits withbitstuffing in the input buffer &n the decodingprocess we first remo"e the bitstuffing and thenthe >#G& coding +ll these changes are made ina second buffer (copy of the reception buffer), soa new pac*et can be recei"ed while the first oneis being decoded +t this point, decoding speedis not so important, because the de"ice candelay the answer, but when the hosts as*s for ananswer during decoding, the de"ice must answerimmediately with >+L so that the host willunderstand it is not ready yet Because of this,the firmware must be able to recei"e pac*etsfrom the host during decoding, decode whetherthe transaction is intended for the de"ice, andthen send >+L pac*et if there is some decoding
in progress The host will then as* again Thefirmware also decodes the main USB transactionand performs the re0uested action (for example,send char to #S$%$ line and wait fortransmission complete), and prepares thecorresponding answer uring this process thede"ice is interrupted by some pac*ets from thehost, usually &> pac*ets to obtain answer fromthe de"ice To these &> pac*ets, the de"ice mustanswer with >+L handsha*e pac*ets .hen theanswer is ready and the de"ice has performedthe re0uired action, the answer must go through'#' field addition and then >#G& coding and
bitstuffing before being transmitted as an array ofbits >ow, when the host re0uests an answer, wecan transmit this bitstream to the data linesaccording to the USB specification (from syncpattern to =DP)
Firmware description&n the following we describe the main parts
of the firmware The firmware is di"ided intobloc*s interrupt routines, decoding routines(>#G& decoding, bitstuffing remo"al5addition, M),USB reception, USB transmission, re0uestedaction decoding, and performing re0uested
actionsUser can add his own functions to the
firmware Some examples on how to ma*ecustomerspecific functions can be found in thefirmware code, and user can write new de"iceextensions according to the existing builtinfunctions !or example T.& support can beadded according to the builtin function for directpin control
-
8/11/2019 AppNote_USBtoRS232
6/17
!igure 28 !lowchart of recei"ing routineEXT_INT0Interrupt
ServiceRoutine
2
INT0 %%&. .
*. $$%&
%$ & S"P82 %$ $ , 9:9;
S,%$uu99@
S$ S>%$u $%&
-
8/11/2019 AppNote_USBtoRS232
7/17
The externalinterrupt 8 is acti"eall the time while thefirmware is runningThis routine initiatesthe reception ofUSB serial data (analternati"e namewould be NUSBreceptionO) +nexternal interruptoccurs on a risingedge on the &>T8pin (a rising edgemar*s the beginningof the sync patternof a USB pac*etsee !igure 7) Thisacti"ates the USBreception routine
!irst, datasampling must besynchroni;ed to themiddle of the bitwidth This is doneaccording to thesync pattern (whichis a s0uare wa"esignal) Because bitduration is only -cycles of the KT+1cloc*s and interruptoccurrence can be
delayed (C5 7cycles), edgesynchroni;ation insync pattern mustbe carefullyperformed =nd ofsync pattern andbegin of data bitsare detectedaccording to the lastdual low le"el bits insync pac*et (see!igure 7)
+fter this, datasampling is startedSampling isperformed in themiddle of the bitBecause data rateis 234bit5s(2346;) and themicrocontrollerspeed is 2$46;, weha"e only - cycles
for data bitsampling, storing itinto the buffer byte,shift the buffer byte,chec*ing if thewhole byte hasbeen recei"ed,storing this byte intoS#+4, andchec*ing for =DPThis is perhaps themost crucial part ofthe firmwaree"erything must bedone synchronouslywith exact timing.hen a whole USBpac*et has beenrecei"ed, pac*etdecoding must be
performed !irst, wemust 0uic*lydetermine thepac*et type(S=TUP, &>, DUT,+T+) and recei"edUSB address Thisfast decoding mustbe performed insidethe interrupt ser"iceroutine because ananswer is re0uired"ery 0uic*ly after
recei"ing the USBpac*et (the de"icemust answer withan +'L handsha*epac*et when apac*et with thede"ice address hasbeen recei"ed, andwith >+L when thepac*et is for thede"ice, but when noanswer is currentlyready)
+t the end ofthe receptionroutine (after
+'L5>+Lhandsha*e pac*ethas been sent) thesampled data buffermust be copied intoanother buffer onwhich the decodingwill be performed
This is in order tofree the receptionbuffer to recei"e anew pac*et
uringreception the pac*ettype is decoded andthe correspondingflag "alue is setThis flag is tested inthe main programloop, and accordingto its "alue theappropriate actionwill be ta*en andthe correspondinganswer will beprepared with noregard tomicrocontroller
speedre0uirements
The &>T8 mustbe allowed to *eepits "ery fastin"ocation time in allfirmware routines,so no interruptdisabling is allowedand during otherinterrupts/ execution(for example serialline recei"e
interrupt) &>T8 mustbe enabled !astreception in the&>T8 interruptroutine is "eryimportant, and it isnecessary tooptimi;e thefirmware for speedand exact timingDne important issueis register bac*upoptimi;ation in
interrupt routines
Mainprogram loop
The mainprogram loop is "erysimple &t is onlyre0uired to chec*the action flag what
to do when somerecei"ed data arepresent &n additionit chec*s whetherthe USB interface isreset (both datalines are at low le"elfor a long time) and,if it is, reinitiali;esthe de"ice .henthere is somethingto do (action flagacti"e), thecorrespondingaction is calleddecoding >#G& inpac*et, bitstuffingremo"al andpreparation of there0uested answer in
the transmit buffer(with bitstuffing and>#G& coding) Thenone flag is acti"atedto signal that theanswer is preparedfor sendingPhysical outputbuffer transmissionto the USB lines isperformed in thereception routine asanswer to the &>
pac*et
Shortdescriptionof usedfirmaresu!routines
&n the following,the firmwaresubroutines andtheir purposes are
described brieflyReset"&nitiali;ation of
the +@#microcontrollerresources stac*,serial lines, USBbuffers, interrupts
Main"4ain program
loop 'hec*s the
-
8/11/2019 AppNote_USBtoRS232
8/17
action flag "alueand, if flag is set,performs there0uired action
+dditionally, thisroutine chec*s forUSB reset on datalines andreinitiali;es the USBmicrocontrollerinterface if this isthe case
Int0#andler"The interrupt
ser"ice routine forthe &>T8 externalinterrupt 4ainreception5transmission engineemulation from USB
data lines Storingdata to buffer,decision of USBpac*et owners(USB address),pac*et recognition,sending answer toUSB host Basicallythe heart of the USBengine
M$Ne%S&'ddress"
'alled from
&>T8 receptionroutine if there is are0uest present tochange the USBaddress Theaddress is changedand its coded >#G&e0ui"alent for fastest addressdecoding duringUSB pac*etreception isprepared
(inishReceiving"'opies coded
raw data from USBreception pac*et todecoding pac*et (for>#G& and bitstuffingdecoding)
%S& reset"&nitiali;es USB
interface to default
"alues (as the stateafter power on)
Send)repared%S&'nser"
Sends preparedoutput buffer contents to USBlines >#G& codingand bitstuffing isperformed duringtransmissionPac*et is endedwith =DP
Toggle*'T')I*"
Toggles+T+P& pac*etidentifier (P&)between +T+8 and+T+2 P& This
toggling isnecessary duringtransmission as perthe USBspecification
+ompose,ero*'T'-)I*'nser"
'omposes ;eroanswer for transmission Geroanswer contains nodata and is used insome cases as
answer when noadditional data isa"ailable on de"ice
Init'+.&ufffer"
&nitiali;es bufferin #+4 with +'Ldata (+'Lhandsha*e pac*et)This buffer isfre0uently sent asanswer so it isalways *ept ready in
memorySend'+."Transmits +'L
pac*et to USB linesInitN'.&ufffer"
&nitiali;es bufferin #+4 with >+Ldata (>+Lhandsha*e pac*et)This buffer isfre0uently sent as
answer so it isalways *ept ready inmemory
SendN'."Transmits >+L
pac*et to USB lines+omposeST'/
/"&nitiali;es buffer
in #+4 with ST+11data (ST+11handsha*e pac*et)This buffer isfre0uently sent asanswer so it isalways *ept ready inmemory
*ecodeNR,I"Performs >#G&
decoding ata from
USB lines in bufferis >#G& coded Thisroutine remo"es the>#G& coding fromthe data
&itStuff"#emo"es5adds
bitstuffing inrecei"ed USB dataBitstuffing is addedby host hardwareaccording to theUSB specification to
ensuresynchroni;ation indata sampling Thisroutine producesrecei"ed datawithout bitstuffing ordata to transmit withbitstuffing
ShiftInsert&uffer"
+uxiliary routinefor use whenperforming
bitstuffing addition+dds one bit tooutput data bufferand thus increasesthe buffer lengthThe remainder ofthe buffer is shiftedout
Shift*elete&uffer"
+uxiliary routinefor use whenperformingbitstuffing remo"al#emo"es one bit tooutput data bufferand thus decreasesthe buffer lengthThe remainder ofthe buffer is shiftedin
MirrorIn&uffer&$tes"
=xchanges butorder in bytebecause data isrecei"ed from USBlines to buffer inre"erse order (1SB54SB)
+hec+R+In"Performs '#'
(cyclic redundancychec*) on recei"eddata pac*et '#' isadded to USBpac*et to detectdata corruption
'dd+R+1ut"+dds '#' field
into output datapac*et '#' iscalculated
according to theUSB specificationfrom gi"en USBfields
+hec+R+"+uxiliary routine
used in '#'chec*ing andaddition
/oad*escriptor(romR1M"
1oads data from#D4 to USB output
buffer (as USBanswer)/oad*escripto
r(romR1M,eroInsert"
1oads data from#D4 to USB outputbuffer (as USBanswer) but e"erye"en byte is addedas ;ero This is
-
8/11/2019 AppNote_USBtoRS232
9/17
used when a stringdescriptor inU>&'D= format isre0uested (#D4sa"ing)
/oad*escriptor(romSR'M"
1oads data from#+4 to USB outputbuffer (as USBanswer)
/oad*escriptor(romEE)R1M"
1oads data fromdata ==P#D4 toUSB output buffer(as USB answer)
/oadXXX*escriptor"
Performs
selection for answersource location#D4, #+4 or ==P#D4
)repare%S&1ut'nser"
Prepares USBanswer to outputbuffer according tore0uest by USBhost, and performsthe re0uestedaction +dds
bitstuffing to answer)repare%S&'n
ser"4ain routine for
performing there0uired action andpreparing thecorrespondinganswer The routinewill first determinewhich action toperform E disco"erfunction number
from recei"ed inputdata pac*et E andthen perform there0uested function!unctionparameters arelocated in input datapac*et
#outine isdi"ided into two bigparts
- standardre0uests
- "endorspecificre0uests
Standardre0uests arenecessary and aredescribed in USBspecification(S=TQ+#=SS,A=TQ=S'#&PTD#, M)
@endor specificre0uests arere0uests that canobtain "endor specific data (in'ontrol USBtransfer) 'ontrol &>
USB transfer isused for this +@#de"ice tocommunicate withhost e"eloperscan add into thispart their ownfunctions and in thismanner extendde"ice "ersatilityThe "ariousdocumented builtinfunctions in the
source code can beused as templateson how to addcustom functions
Standard USBfunctions (Standard#e0uests)
+ompose2ET_ST'T%S"
+ompose+/E'R_(E'T%RE"
+omposeSET_
(E'T%RE"+omposeSET_'**RESS"
+ompose2ET_*ES+RI)T1R"
+omposeSET_*ES+RI)T1R"
+ompose2ET_+1N(I2%R'TI1N"
+omposeSET_+1N(I2%R'TI1N3
+ompose2ET_INTER('+E3
+omposeSET_INTER('+E"
+omposeS4N+#_(R'ME3
@endor USBfunctions (@endorre0uests)
*oSetInfra&ufferEmpt$"
*o2etInfra+ode"
*oSet*ata)ort*irection"
*o2et*ata)ort*irection"
*oSet1ut*ata)ort"
*o2et1ut*ata)ort"
*o2etIn*ata)ort"
*oEE)R1MRead"
*oEE)R1M5rite"
*oRS676Send"*oRS676Read"*oSetRS676&
aud"*o2etRS676&
aud"*o2etRS676&
uffer"*oSetRS676*
ata&its"*o2etRS676*
ata&its"*oSetRS676)a
rit$"*o2etRS676)
arit$"*oSetRS676St
op&its"
*o2etRS676Stop&its"
ata structures(USB descriptorsand strings)
*evice*escriptor"
+onfig*escriptor"
/angI*String*escriptor"
8endorString*escriptor"
*evNameString*escriptor"
(ormat ofinputmessagefrom%S&host
+s statedabo"e, our USBde"ice uses USB
'ontrol TransferThis type of transferuses a data formatdefined in the USBspecificationdescribed in usbinanutshellpdfI8J onpage 2% ('ontrolTransfers) &n thisdocument thedetails andexplanations onhow control transfer
wor*s, andtherefore how ourde"icecommunicates withthe USB host, canbe found The +@#de"ice is usingcontrol &> endpoint
+ nice example ofdata communicationcan be found onpage 23 of I8J'ommunicationbetween host and
+@# de"ice is doneaccording to thisexample
&n addition tothe actual controltransfer, the formatof the +T+852 fieldin the transfer should bediscussed 'ontroltransfer defines in
-
8/11/2019 AppNote_USBtoRS232
10/17
its setup stage astandard re0uest,which is - byteslong &ts format isdescribed on page$< of I8J (The SetupPac*et) There istable with adescription of themeaning of e"erybyte The followingis important for ourpurpose
Standard setuppac*et used fordetection andconfiguration ofde"ice after poweron This pac*etuses the Standard
Type re0uest in thebmRequestTypefield (bits
-
8/11/2019 AppNote_USBtoRS232
11/17
t
;
wValue
8
-
8/11/2019 AppNote_USBtoRS232
12/17
'ontrol Transfer is used for usercommunication, implemented as customfunctions in the firmware, as well The endorType re0uest in the bmRequestType field (bitsT5KP)
$) 11 library Used for encapsulation of
de"ice functions and communication withde"ice dri"er 11 simplifies the de"icefunction access from user applications, &tincludes some de"ice and operatingsystem related functions (threads, buffers,etc)
%) User application 4a*es user interface for friendly communicationbetween user and de"ice Uses functioncalls from 11 library only
*evice driver and installationfiles
The first time we connect the USB de"ice tothe computer USB port, the operating system willdetect the de"ice and re0uest dri"er files This iscalled de"ice installation !or the installationprocess it is necessary not only to ma*e thede"ice dri"er, but also an installation script inwhich the installation steps are described
The de"ice dri"er for the de"ice described inthis document is made with .indows$888 L(ri"er e"elopment Lit) The de"elopment ofthe USB dri"er is based on one of the includedexamples in the L E Iso%s! This dri"er was
modified for our purpose E +@# USB de"icecommunication &n the original source code,parts ha"e been extended5added about the&D'T1 communications, because our de"icecommunicates with the computer through these&D'T1 calls To reduce the dri"er code si;e,unused parts ha"e been remo"ed (read andwrite routines) The name of the dri"er isN+@#%89sysO and it wor*s as sender ofcommands to the USB de"ice ('ontrol &>
-
8/11/2019 AppNote_USBtoRS232
13/17
-
8/11/2019 AppNote_USBtoRS232
14/17
Function prototype in "AVR309.dll" library:
Delphi:
&$
AVR309DLL? FAVR30!99F
//return values from AVR309DLL functions:NO!RROR ? 0
D!V"C!NO#$R!%!N# ? 1NODA#AAVA"LA&L! ? 2
"NVAL"D&A'DRA#! ? 3
OV!RR'N!RROR ? 4
"NVAL"DDA#A&"#%? 5
"NVAL"D$AR"#(? 6
"NVAL"D%#O$&"#%? 7
u&$%&DoGetInfraCode8:TimeCodeDiagram Earray of byte :DiagramLengtEinteer;Einteer $99($&9AVR309DLL&, FDG$I&CF
u&$%&DoSetData!ortDire"tion8Direction!yteEbyte;Einteer $99($&9AVR309DLL&, FDS$D$P$D%$%&F
u&$%&DoGetData!ortDire"tion8:DataDirection!yteEbyte;Einteer $99($&9AVR309DLL&, FDG$D$P$D%$%&F
u&$%&DoSet#$tData!ort8Dataut!yteEbyte;Einteer $99($&9AVR309DLL&, FDS$"u$D$P$F
u&$%&DoGet#$tData!ort8:Dataut!yteEbyte;Einteer $99($&9AVR309DLL&, FDG$"u$D$P$F
u&$%&DoGetInData!ort8:Data#n!yteEbyte;Einteer $99($&9AVR309DLL&, FDG$I&D$P$F
u&$%&DoSetData!ortDire"tion%8Direction!yte!=Direction!yteC=Direction!yteD= $%ed&ort%Ebyte;Einteer $99($&9AVR309DLL&,
FDS$D$P$D%$%&F
u&$%&DoGetData!ortDire"tio n%8:DataDirection!yte!=Direction!yteC=Direction!yteD= $%ed&ort%Ebyte;Einteer $99($&9AVR309DLL&,
FDG$D$P$D%$%&F
u&$%&DoSet#$tData!ort%8Dataut!yte!=Dataut!yteC=Dataut!yteD= $%ed&ort%Ebyte;Einteer $99($&9AVR309DLL&, FDS$"u$D$P$F
u&$%&DoGet#$tData!ort%8:Dataut!yte!=Dataut!yteC=Dataut!yteD= $%ed&ort%Ebyte;Einteer $99($&9AVR309DLL&,FDG$"u$D$P$F
u&$%&DoGetInData!ort%8:Data#n!yte!=Data#n!yteC=Data#n!yteD= $%ed&ort%Ebyte;Einteer $99($&9AVR309DLL&, FDG$I&D$P$F
u&$%&Do&&!R#'Read8Addre%%E(ord :Data#n!yteEbyte;Einteer $99($&9AVR309DLL&, FD**PR"MRF
u&$%&Do&&!R#')rite8Addre%%E(ordDataut!yteEbyte;Einteer $99($&9AVR309DLL&, FD**PR"M%$F
u&$%&DoRS232Send8Dataut!yteEbyte;Einteer $99($&9AVR309DLL&, FDRS232S&F
u&$%&DoRS232Read8:Data#n!yteEbyte;Einteer $99($&9AVR309DLL&, FDRS232RF
u&$%&DoSetRS232*a$d8!audRateEinteer;Einteer $99($&9AVR309DLL&, FDS$RS232BuF
u&$%&DoGetRS232*a$d8:!audRateEinteer;Einteer $99($&9AVR309DLL&, FDG$RS232BuF
u&$%&DoGetRS232*$ffer8:R'(3(!u))erEarray of byte :R'(3(!u))erLengtEinteer;Einteer $99($&9AVR309DLL&, FDG$RS232BuF
u&$%&DoRS232*$fferSend8:R'(3(!u))erEarray of byte :R'(3(!u))erLengtEinteer;Einteer $99($&9AVR309DLL&, FDRS232BuS&F
u&$%&DoSetRS232Data*it%8Data!it%Ebyte;Einteer $99($&9AVR309DLL&, FDS$RS232D$B%$F
u&$%&DoGetRS232Data*it%8:Data!it%Ebyte;E%&$. $99($&9AVR309DLL&, FDG$RS232D$B%$F
u&$%&DoSetRS232!arity8&arityEbyte;Einteer $99($&9AVR309DLL&, FDS$RS232P%$'F
u&$%&DoGetRS232!arity8:&arityEbyte;Einteer $99($&9AVR309DLL&, FDG$RS232P%$'F
u&$%&DoSetRS232Stop*it%8'top!it%Ebyte;Einteer $99($&9AVR309DLL&, FDS$RS232S$
-
8/11/2019 AppNote_USBtoRS232
15/17
int$99DoGetRS232*$ffer8$"har R'(3(!u))er= intDummy#nt= int ,R'(3(!u))erLengt;
int$99DoRS232*$fferSend8$"har R'(3(!u))er=intDummy#nt=int ,R'(3(!u))erLengt;
int$99DoSetRS232Data*it%8$"harData!it%;
int$99DoGetRS232Data*it%8$"har Data!it%;
int$99DoSetRS232!arity8$"har&arity;
int$99DoGetRS232!arity8$"har &arity;
int$99DoSetRS232Stop*it%8$"har'top!it%;
int$99DoGetRS232Stop*it%8$"har 'top!it%;
%
-
8/11/2019 AppNote_USBtoRS232
16/17
End user applicationThe enduser application will only use
functions from the 11 library to communicatewith the de"ice &ts main purpose is to ma*e auserfriendly AU& (graphical user interface)
+pplication programmers use the 11 library
to write their own applications +n example canbe found in the published proect where all thesource code is a"ailable 4any applications can
be written using this example as starting point,and in se"eral programming languages (elphi,'CC, @isual Basic)
There is included an example of an end userapplication called N+@#%89demoexeO Thissoftware is only meant as an example on how touse the functions from the 11 library Thesource code can be used as a template for otherapplications
Appendi1 A: Source code of firmware for ATmea5 AVRSource code of firmware for +Tmega- +@# microcontroller was written in +@# Studio 7 Source code is in text
USBto#S$%$asm or in syntax highlighted form file USBto#S$%$asmpdf
Appendi1 B:'8R70:;dllinterface1ibrary+R3./-d!!was written in elphi% therefore its source code is based on 'b0ect Pasca!language But in the n
is described interface also for other programming languages 1e!p%i, CCand isua! Basic&nterface to 11 library (exported functions) N+@#%89dllO are described in file +@#%89Q11Qhelphtm
Appendi1
-
8/11/2019 AppNote_USBtoRS232
17/17
Used documentation and resources
>$$$)- u$>