Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
The power wires give approximately 5 volts and Hub Port Low Speed Function
max. 500mA. We can supply our device from Figure 3. Low Speed Device Cable and
Vcc and GND. The signal wires named DATA+ Resistor Connections
and DATA- handle the communication between
host (computer) and device. Signals on these Based on this pull-up, the host computer will
wires are bi-directional. Voltage levels are detect that some new device is connected to
differential: when DATA+ is at high level, DATA- USB line.
is at low level, but there are some cases when
DATA+ and DATA- are at the same level (EOP – After the host detects a new device it can
end of packet, idle state). start communicating with it in accordance with
One Bit
Time
the physical USB protocol. The USB protocol,
(1.5Mb/s)
unlike UART, is based on synchronous data
transfer. Synchronization of transmitter and
VSE (max)
receiver is necessary to carry out the
Signal pins
pass output
Driver spec levels
Signal Pins with minimal
reflections and
communication. Because of this, the transmitter
VSE (min)
ringing
will transmit a small header (sync pattern)
VSS
preceding the actual data. This header is a
square wave (101010), succeed by two zeros
Figure 1. Low Speed Driver Signal after which the actual data is transmitted.
Waveforms
SYNC PATTERN
Stuffed Bit
received into the device buffer in one USB
Bit Stuffed Data
transfer. In hardware-based USB receivers, the
Sync Pattern Packet Data various parts of the transfer are automatically
Six Ones
decoded, and the device is notified only when
NRZI Idle
Encoded Data Sync Pattern Packet Data
the entire message has been assigned for the
particular device. In a firmware implementation,
Figure 6. Bit Stuffing the USB message must be decoded by firmware
after the entire message has been received into
Notification of end of data transfer is made the buffer. This gives us the requirements and
by and EOP (end-of-packet) part. EOP consists limitations: The device must have a buffer for
of 2 zeros on both data lines (both physical storing the whole USB message length, another
DATA+ and DATA- are at low voltage level). buffer for USB transmitting (prepared data to
EOP is succeeded by a short time of idle state transmit), and administration overhead with
(min 2 periods of data rate). After this, the next message decoding and checking. Additionally, of
transaction can be performed. course, the firmware is required to perform fast
TPERIOD and precise synchronous speed reception (from
Data physical pins to buffer) and transmission (from
Differential Crossover
Data Lines Level buffer to pins). All these capabilities are limited
by microcontroller resources (speed and
EOP
Width program/data memory capacity), so the firmware
must be carefully optimized. In some cases the
Figure 7. EOP Width Timing microcontroller computation power is very close
to the minimum requirements and therefore all
Data between sync pattern and EOP is NRZI firmware must be written in assembly.
coded communication between USB device and
host. The data stream is composed by packets
consisting of several fields: Sync field (sync
Connection
pattern), PacketID (PID), Address field (ADDR), A schematic diagram of microcontroller
Endpoint field (ENDP), Data, and Cyclic connection to USB bus is shown in Figure 8 and
redundancy check field (CRC). Usage of these Figure 9. These schematics were made for the
fields in different types of data transfer is specific purpose as USB to RS232 converter.
explained well in [0]. USB describes four types of The functions implemented by direct pin control
transfer: Control Transfer, Interrupt Transfer, and EEPROM read/write.
VCC VCC
IC1
AT90S2313-10 / ATtiny2313
XT1
12MHz R1 +
RS232 TTL 2k2
VCC
1 20 C2
RST VCC GND GND 10u
RxD 2 19 D7
PD0/RXD SCK/PB7
TxD 3 18 D6 D1 D2 GND
PD1/TXD MISO/PB6 C1 R2
4 17 D5 3V6 3V6
XTAL2 MOSI/PB5 100n 4k7
5 16 D4 XC1
XTAL1 PB4
6 15 D3 GND USB-A
PD2/INT0 OC1/PB3
D0 7 14 68R GND
PD3/INT1 PB2 GND 4
8 13 DATA+
PD4/T0 AN1/PB1 R2 3
D1 9 12 DATA-
PD5/T1 AN2/PB0 R3 2
10 11 D2 VCC
GND ICP/PD6 68R VCC 1
GND
Figure 8. USB interface with AT90S2313 (as USB to RS232 converter with 32 byte FIFO + 8-bit I/O
control + 128 bytes EEPROM)
Figure 9. USB interface with ATmega8 (as USB to RS232 converter with 800 byte FIFO + EEPROM + I/O
control + EEPROM)
The USB data lines, DATA- and DATA+, are recognizes a valid USB packet with the given
connected to pins PB0 and PB1 on the AVR. USB address. Therefore this is a critical part of
This connection cannot be changed because the the USB answer.
firmware makes use of one AVR finesse for fast After the reception of this bitstream, we
signal reception: The bit signal captured from the obtain an NRZI coded array of bits with
data lines is right shifted from LSB (PB0) to carry bitstuffing in the input buffer. In the decoding
and then to the reception register, which collects process we first remove the bitstuffing and then
the bits from the data lines. PB1 is used as input the NRZI coding. All these changes are made in
signal because on 8-pin AT90S2323 this pin can a second buffer (copy of the reception buffer), so
be used as external interrupt INT0 (no additional a new packet can be received while the first one
connection to INT0 is necessary – the 8-pin is being decoded. At this point, decoding speed
version of the AVR is the smallest pin count is not so important, because the device can
available). On other AVRs, an external delay the answer, but when the hosts asks for an
connection from DATA+ to the INT0 pin is answer during decoding, the device must answer
necessary if we want to ensure no firmware immediately with NAK so that the host will
changes between different AVR microcontrollers. understand it is not ready yet. Because of this,
For proper USB device connection and the firmware must be able to receive packets
signaling, the AVR acting as low speed USB from the host during decoding, decode whether
device must have a 1.5kohm pull-up resistor on the transaction is intended for the device, and
DATA-. then send NAK packet if there is some decoding
The other components only provide in progress. The host will then ask again. The
functions for proper operation of the firmware also decodes the main USB transaction
microcontroller: Crystal as clock source, and and performs the requested action (for example,
capacitors for power supply filtering. send char to RS232 line and wait for
This small component count is sufficient to transmission complete), and prepares the
obtain a functional USB device, which can corresponding answer. During this process the
communicate with a computer through the USB device is interrupted by some packets from the
interface. This is a very simple and cheap host, usually IN packets to obtain answer from
solution. Some additional components can be the device. To these IN packets, the device must
added to extend the device functions. If we want answer with NAK handshake packets. When the
to receive an IR signal, we can add the answer is ready and the device has performed
TSOP1738 infrared sensor. If we want to use the the required action, the answer must go through
device as an USB to RS232 converter, we CRC field addition and then NRZI coding and
should add the MAX232 TTL to RS232 level bitstuffing before being transmitted as an array
converter. If we want to control LED diodes or of bits. Now, when the host requests an answer,
display, we connect them to I/O pins directly or we can transmit this bitstream to the data lines
through resistors. according to the USB specification (from sync
pattern to EOP).
Implementation
All USB protocol reception and decoding is Firmware description
performed at the firmware level. The firmware In the following we describe the main parts
first receives a stream of USB bits in one USB of the firmware. The firmware is divided into
packet into the internal buffer. Start of reception blocks: interrupt routines, decoding routines
is based on the external interrupt INT0, which (NRZI decoding, bitstuffing removal/addition, …),
takes care of the sync pattern. During reception, USB reception, USB transmission, requested
only the end of packet signal is checked (EOP action decoding, and performing requested
detection only). This is due to the extreme speed actions.
of the USB data transfer. After a successful User can add his own functions to the
reception, the firmware will decode the data firmware. Some examples on how to make
packets and analyze them. At first it checks if the customer-specific functions can be found in the
packet is intended for this device according to its firmware code, and user can write new device
address. The address is transferred in every extensions according to the existing built-in
USB transaction and therefore the device will functions. For example TWI support can be
know if the next transferred data are dedicated added according to the built-in function for direct
to it. USB address decoding must be done very pin control.
quickly, because the device must answer with an
ACK handshake packet to the USB host if it
INT0 raising edge 1
Store Shiftbuffer to
input buffer Finish INT0 interrupt:
Clear pending INT0 2
Restore registers
Received 2
bytes < 3 ?
“EXT_INT0” Service
Figure 10. Flowchart of receiving routine
Interrupt Routine
The external have only 8 cycles will be performed. check the action
interrupt 0 is active for data bit This is in order to flag: what to do
all the time while sampling, storing it free the reception when some
the firmware is into the buffer byte, buffer to receive a received data are
running. This shift the buffer byte, new packet. present. In addition
routine initiates the checking if the During it checks whether
reception of USB whole byte has reception the packet the USB interface is
serial data (an been received, type is decoded and reset (both data
alternative name storing this byte into the corresponding lines are at low level
would be “USB SRAM, and flag value is set. for a long time) and,
reception”). An checking for EOP. This flag is tested in if it is, reinitializes
external interrupt This is perhaps the the main program the device. When
occurs on a rising most crucial part of loop, and according there is something
edge on the INT0 the firmware; to its value the to do (action flag
pin (a rising edge everything must be appropriate action active), the
marks the beginning done synchronously will be taken and corresponding
of the sync pattern with exact timing. the corresponding action is called:
of a USB packet When a whole USB answer will be decoding NRZI in
see Figure 4). This packet has been prepared with no packet, bitstuffing
activates the USB received, packet regard to removal and
reception routine. decoding must be microcontroller preparation of the
First, data performed. First, we speed requested answer in
sampling must be must quickly requirements. the transmit buffer
synchronized to the determine the The INT0 must (with bitstuffing and
middle of the bit packet type be allowed to keep NRZI coding). Then
width. This is done (SETUP, IN, OUT, its very fast one flag is activated
according to the DATA) and received invocation time in all to signal that the
sync pattern (which USB address. This firmware routines, answer is prepared
is a square wave fast decoding must so no interrupt for sending.
signal). Because bit be performed inside disabling is allowed Physical output
duration is only 8 the interrupt service and during other buffer transmission
cycles of the XTAL routine because an interrupts’ execution to the USB lines is
clocks and interrupt answer is required (for example serial performed in the
occurrence can be very quickly after line receive reception routine as
delayed (+/- 4 receiving the USB interrupt) INT0 must answer to the IN
cycles), edge packet (the device be enabled. Fast packet.
synchronization in must answer with reception in the
sync pattern must an ACK handshake INT0 interrupt Short
be carefully packet when a routine is very
performed. End of packet with the important, and it is description
sync pattern and device address has necessary to of used
begin of data bits been received, and optimize the
are detected with NAK when the firmware for speed
firmware
according to the last packet is for the and exact timing. subroutines
dual low level bits in device, but when no One important issue In the following,
sync packet (see answer is currently is register backup the firmware
Figure 4). ready). optimization in subroutines and
After this, data At the end of interrupt routines. their purposes are
sampling is started. the reception described briefly.
Sampling is routine (after Main Reset:
performed in the ACK/NAK Initialization of
middle of the bit. handshake packet program the AVR
Because data rate has been sent) the loop microcontroller
is 1.5Mbit/s sampled data buffer The main resources: stack,
(1.5MHz) and the must be copied into program loop is serial lines, USB
microcontroller another buffer on very simple. It is buffers, interrupts...
speed is 12MHz, we which the decoding only required to Main:
Main program USB reset: handshake packet). ShiftDeleteBuf
loop. Checks the Initializes USB This buffer is fer:
action flag value interface to default frequently sent as Auxiliary routine
and, if flag is set, values (as the state answer so it is for use when
performs the after power on). always kept ready performing
required action. SendPrepared in memory. bitstuffing removal.
Additionally, this USBAnswer: SendNAK: Removes one bit to
routine checks for Sends prepared Transmits NAK output data buffer
USB reset on data output buffer packet to USB lines. and thus decreases
lines and contents to USB ComposeSTA the buffer length.
reinitializes the USB lines. NRZI coding LL: The remainder of
microcontroller and bitstuffing is Initializes buffer the buffer is shifted
interface if this is performed during in RAM with STALL in.
the case. transmission. data (STALL MirrorInBuffer
Int0Handler: Packet is ended handshake packet). Bytes:
The interrupt with EOP. This buffer is Exchanges but
service routine for ToggleDATAPI frequently sent as order in byte
the INT0 external D: answer so it is because data is
interrupt. Main Toggles always kept ready received from USB
reception/transmissi DATAPID packet in memory. lines to buffer in
on engine; identifier (PID) DecodeNRZI: reverse order
emulation from USB between DATA0 Performs NRZI (LSB/MSB).
data lines. Storing and DATA1 PID. decoding. Data from CheckCRCIn:
data to buffer, This toggling is USB lines in buffer Performs CRC
decision of USB necessary during is NRZI coded. This (cyclic redundancy
packet owners transmission as per routine removes the check) on received
(USB address), the USB NRZI coding from data packet. CRC is
packet recognition, specification. the data. added to USB
sending answer to ComposeZero BitStuff: packet to detect
USB host. Basically DATA1PIDAnswer: Removes/adds data corruption.
the heart of the Composes zero bitstuffing in AddCRCOut:
USB engine. answer for received USB data. Adds CRC field
MyNewUSBAd transmission. Zero Bitstuffing is added into output data
dress: answer contains no by host hardware packet. CRC is
Called from data and is used in according to the calculated
INT0 reception some cases as USB specification to according to the
routine if there is a answer when no ensure USB specification
request present to additional data is synchronization in from given USB
change the USB available on device. data sampling. This fields.
address. The InitACKBufffer routine produces CheckCRC:
address is changed : received data Auxiliary routine
and its coded NRZI Initializes buffer without bitstuffing or used in CRC
equivalent for in RAM with ACK data to transmit with checking and
fastest address data (ACK bitstuffing. addition.
decoding during handshake packet). ShiftInsertBuff LoadDescripto
USB packet This buffer is er: rFromROM:
reception is frequently sent as Auxiliary routine Loads data from
prepared. answer so it is for use when ROM to USB output
FinishReceivin always kept ready in performing buffer (as USB
g: memory. bitstuffing addition. answer).
Copies coded SendACK: Adds one bit to LoadDescripto
raw data from USB Transmits ACK output data buffer rFromROMZeroIns
reception packet to packet to USB lines. and thus increases ert:
decoding packet InitNAKBufffer: the buffer length. Loads data from
(for NRZI and Initializes buffer The remainder of ROM to USB output
bitstuffing in RAM with NAK the buffer is shifted buffer (as USB
decoding). data (NAK out. answer) but every
even byte is added Routine is ComposeGET Data structures
as zero. This is divided into two big _CONFIGURATIO (USB descriptors
used when a string parts: N: and strings):
descriptor in - standard ComposeSET_ DeviceDescrip
UNICODE format is requests CONFIGURATION; tor:
requested (ROM - vendor ComposeGET ConfigDescrip
saving). specific _INTERFACE; tor:
LoadDescripto requests ComposeSET_ LangIDStringD
rFromSRAM: Standard INTERFACE: escriptor:
Loads data from requests are ComposeSYN VendorStringD
RAM to USB output necessary and are CH_FRAME; escriptor:
buffer (as USB described in USB DevNameStrin
answer). specification Vendor USB gDescriptor:
LoadDescripto (SET_ADDRESS, functions (Vendor
rFromEEPROM: GET_DESCRIPTO requests): Format of
Loads data from R, …). DoSetInfraBuff
data EEPROM to Vendor specific erEmpty: input
USB output buffer requests are DoGetInfraCod message
(as USB answer). requests that can e:
LoadXXXDesc obtain vendor DoSetDataPort
from USB
riptor: specific data (in Direction: host
Performs Control USB DoGetDataPor As stated
selection for answer transfer). Control IN tDirection: above, our USB
source location: USB transfer is DoSetOutData device uses USB
ROM, RAM or used for this AVR Port: Control Transfer.
EEPROM. device to DoGetOutData This type of transfer
PrepareUSBO communicate with Port: uses a data format
utAnswer: host. Developers DoGetInDataP defined in the USB
Prepares USB can add into this ort: specification
answer to output part their own DoEEPROMRe described in usb-in-
buffer according to functions and in this ad: a-nutshell.pdf [0] on
request by USB manner extend DoEEPROMWr page 13 (Control
host, and performs device versatility. ite: Transfers). In this
the requested The various DoRS232Send document the
action. Adds documented built-in : details and
bitstuffing to functions in the DoRS232Read explanations on
answer. source code can be : how control transfer
PrepareUSBA used as templates DoSetRS232B works, and
nswer: on how to add aud: therefore how our
Main routine for custom functions. DoGetRS232B device
performing the aud: communicates with
required action and Standard USB DoGetRS232B the USB host, can
preparing the functions (Standard uffer: be found. The AVR
corresponding Requests): DoSetRS232D device is using
answer. The routine ComposeGET ataBits: control IN endpoint.
will first determine _STATUS: DoGetRS232D A nice example of
which action to ComposeCLE ataBits: data communication
perform – discover AR_FEATURE: DoSetRS232P can be found on
function number ComposeSET_ arity: page 15 of [0].
from received input FEATURE: DoGetRS232P Communication
data packet – and ComposeSET_ arity: between host and
then perform the ADDRESS: DoSetRS232St AVR device is done
requested function. ComposeGET opBits: according to this
Function _DESCRIPTOR: DoGetRS232St example.
parameters are ComposeSET_ opBits: In addition to
located in input data DESCRIPTOR: the actual control
packet. transfer, the format
of the DATA0/1 field device after power
in the transfer on. This packet
should be uses the Standard wValue wIndex wLength Data
discussed. Control Type request in the Feature Zero Zero None
transfer defines in bmRequestType Selector Interface
its setup stage a field (bits D6-D5 = Endpoint
standard request, 0). All next fields’
which is 8 bytes (bRequest, wValue, Zero Zero One Configuration
long. Its format is wIndex, wLength) Value
described on page meanings can be
26 of [0] (The Setup found in the USB Descriptor Zero or Descriptor Descriptor
Packet). There is specification. Their Type and Language Length
table with a explanation can be Descriptor ID
description of the found on pages 27- Index
meaning of every 30 in [0] (Standard
byte. The following Requests). Zero Interface One Alternate
is important for our Every setup Interface
purpose: packet has eight
Standard setup bytes, used as Zero Zero Two Device,
packet used for described in the Interface Interface, or
Endpoint Endpoint
detection and following table.
Status
configuration of
Field Size Value Device
Description Zero Zero None
Address
bmRequestType 1 Bit-map Characteristics of request
Configuration Zero Zero None
Value
D7 Data xfer direction
0 = Host to device
1 = Descriptor
Device to host Zero or Descriptor Descriptor
Type and Language Length
D6..5 TypeDescriptor ID
Index
0 = Standard
1 = Class
Feature
2 = Vendor Zero Zero None
Selector
3 = Reserved Interface
Endpoint
D4..0 Recipient
Alternate
0 = Device Interface Zero None
Setting
1 = Interface
2 = Endpoint
3 = Other
Zero Endpoint Two Frame Number
4..31 = Reserved
Table 2: Standard device requests
bRequest 1 Value Specific request (refer to
source not found)
PORTC
PORTD
PINC
PIND
Delphi:
const
AVR309DLL= 'AVR309.dll';
//return values from AVR309DLL functions:
NO_ERROR = 0;
DEVICE_NOT_PRESENT = 1;
NO_DATA_AVAILABLE = 2;
INVALID_BAUDRATE = 3;
OVERRUN_ERROR = 4;
INVALID_DATABITS = 5;
INVALID_PARITY = 6;
INVALID_STOPBITS = 7;
function DoGetInfraCode(var TimeCodeDiagram:array of byte; var DiagramLength:integer):integer; stdcall external AVR309DLL name 'DoGetInfraCode';
function DoSetDataPortDirection(DirectionByte:byte):integer; stdcall external AVR309DLL name 'DoSetDataPortDirection';
function DoGetDataPortDirection(var DataDirectionByte:byte):integer; stdcall external AVR309DLL name 'DoGetDataPortDirection';
function DoSetOutDataPort(DataOutByte:byte):integer; stdcall external AVR309DLL name 'DoSetOutDataPort';
function DoGetOutDataPort(var DataOutByte:byte):integer; stdcall external AVR309DLL name 'DoGetOutDataPort';
function DoGetInDataPort(var DataInByte:byte):integer; stdcall external AVR309DLL name 'DoGetInDataPort';
function DoSetDataPortDirections(DirectionByteB, DirectionByteC, DirectionByteD, UsedPorts:byte):integer; stdcall external AVR309DLL name
'DoSetDataPortDirections';
function DoGetDataPortDirections(var DataDirectionByteB, DirectionByteC, DirectionByteD, UsedPorts:byte):integer; stdcall external AVR309DLL name
'DoGetDataPortDirections';
function DoSetOutDataPorts(DataOutByteB, DataOutByteC, DataOutByteD, UsedPorts:byte):integer; stdcall external AVR309DLL name 'DoSetOutDataPorts';
function DoGetOutDataPorts(var DataOutByteB, DataOutByteC, DataOutByteD, UsedPorts:byte):integer; stdcall external AVR309DLL name
'DoGetOutDataPorts';
function DoGetInDataPorts(var DataInByteB, DataInByteC, DataInByteD, UsedPorts:byte):integer; stdcall external AVR309DLL name 'DoGetInDataPorts';
#ifdef __cplusplus
}
#endif
Visual Basic:
Public Const AVR309DLL="AVR309.dll";
'return values from AVR309DLL functions:
Public Const NO_ERROR = 0;
Public Const DEVICE_NOT_PRESENT = 1;
Public Const NO_DATA_AVAILABLE = 2;
Public Const INVALID_BAUDRATE = 3;
Public Const OVERRUN_ERROR = 4;
Public Const INVALID_DATABITS = 5;
Public Const INVALID_PARITY = 6;
Public Const INVALID_STOPBITS = 7;
Public Declare Function DoGetInfraCode Lib "AVR309.dll" (ByRef TimeCodeDiagram As Any, ByVal DummyInt As Long, ByRef DiagramLength As Long) As
Long
Public Declare Function DoSetDataPortDirection Lib "AVR309.dll" (ByVal DirectionByte As Byte) As Long
Public Declare Function DoGetDataPortDirection Lib "AVR309.dll" (ByRef DataDirectionByte As Byte) As Long
Public Declare Function DoSetOutDataPort Lib "AVR309.dll" (ByVal DataOutByte As Byte) As Long
Public Declare Function DoGetOutDataPort Lib "AVR309.dll" (ByRef DataOutByte As Byte) As Long
Public Declare Function DoGetInDataPort Lib "AVR309.dll" (ByRef DataInByte As Byte) As Long
Public Declare Function DoSetDataPortDirections Lib "AVR309.dll" (ByVal DirectionByteB As Byte, ByVal DirectionByteC As Byte, ByVal DirectionByteD As
Byte, ByVal UsedPorts As Byte) As Long
Public Declare Function DoGetDataPortDirections Lib "AVR309.dll" (ByRef DataDirectionByteB As Byte, ByRef DataDirectionByteC As Byte, ByRef
DataDirectionByteD As Byte, ByRef UsedPorts As Byte) As Long
Public Declare Function DoSetOutDataPorts Lib "AVR309.dll" (ByVal DataOutByteB As Byte, ByVal DataOutByteC As Byte, ByVal DataOutByteD As Byte,
ByVal UsedPorts As Byte) As Long
Public Declare Function DoGetOutDataPorts Lib "AVR309.dll" (ByRef DataOutByteB As Byte, ByRef DataOutByteC As Byte, ByRef DataOutByteD As Byte,
ByRef UsedPorts As Byte) As Long
Public Declare Function DoGetInDataPorts Lib "AVR309.dll" (ByRef DataInByteB As Byte, ByRef DataInByteC As Byte, ByRef DataInByteD As Byte, ByRef
UsedPorts As Byte) As Long
Public Declare Function DoEEPROMRead Lib "AVR309.dll" (ByVal Address As Word, ByRef DataInByte As Byte) As Long
Public Declare Function DoEEPROMWrite Lib "AVR309.dll" (ByVal Address As Word, ByVal DataOutByte As Byte) As Long
Public Declare Function DoRS232Send Lib "AVR309.dll" (ByVal DataOutByte As Byte) As Long
Public Declare Function DoRS232Read Lib "AVR309.dll" (ByRef DataInByte As Byte) As Long
Public Declare Function DoSetRS232Baud Lib "AVR309.dll" (ByVal BaudRate As Long) As Long
Public Declare Function DoGetRS232Baud Lib "AVR309.dll" (ByRef BaudRate As Long) As Long
Public Declare Function DoGetRS232Buffer Lib "AVR309.dll" (ByRef RS232Buffer As Any, ByVal DummyInt As Long, ByRef RS232BufferLength As Long)
As Long
Public Declare Function DoRS232BufferSend Lib "AVR309.dll" (ByRef RS232Buffer As Any, ByVal DummyInt As Long, ByRef RS232BufferLength As Long)
As Long
Public Declare Function DoSetRS232DataBits Lib "AVR309.dll" (DataBits As Byte) As Long
Public Declare Function DoGetRS232DataBits Lib "AVR309.dll" (ByRef DataBits As Byte) As Long
Public Declare Function DoSetRS232Parity Lib "AVR309.dll" (Parity As Byte) As Long
Public Declare Function DoGetRS232Parity Lib "AVR309.dll" (ByRef Parity As Byte) As Long
Public Declare Function DoSetRS232StopBits Lib "AVR309.dll" (StopBits As Byte) As Long
Public Declare Function DoGetRS232StopBits Lib "AVR309.dll" (ByRef StopBits As Byte) As Long
End user application be written using this example as starting point,
The end-user application will only use and in several programming languages (Delphi,
functions from the DLL library to communicate C++, Visual Basic).
with the device. Its main purpose is to make a There is included an example of an end user
user-friendly GUI (graphical user interface). application called “AVR309demo.exe”. This
Application programmers use the DLL library software is only meant as an example on how to
to write their own applications. An example can use the functions from the DLL library. The
be found in the published project where all the source code can be used as a template for other
source code is available. Many applications can applications.
Appendix A: Source code of firmware for ATmega8 AVR
Source code of firmware for ATmega8 AVR microcontroller was written in AVR Studio 4. Source code is in text file
USBtoRS232.asm or in syntax highlighted form file USBtoRS232asm.pdf.
Author:
Ing. Igor Cesko
Slovakia
www.cesko.host.sk
cesko@internet.sk