my old Testprog wolks fine with Atmega32u.
1. no
2. yes. see my sample
3. little define error in AVRco !
Code
program Echo;
{ $NOSHADOW}
{ $WG-} {global Warnings on}
//Device = 90USB128, VCC=4.5;
//Device = 90USB162,VCC=4.5;
//Device = mega16U2;
Device = mega32U4, VCC=3.3;
//Device = mega32U6;
{ $BOOTRST $0F000} {Reset Jump to $0F000}
(***********************************************************************
All CPU define were used only for my development.
Atmel USB Devices Defines
{$IFDEF _USB16U4_32U4} -> Mega16U4, Mega32U4
{$IFDEF _USB32_64} -> Mega32U6, 90USB64/646/647
{$IFDEF _USB128} -> 90USB128/1286/1287
{$IFDEF _USB82_162} -> 90USB82, 90USB162
{$IFDEF _USB8U2_32U2} -> Mega8U2, Mega16U2, Mega32U2
************************************************************************)
Define_Fuses
Override_Fuses;
NoteBook = B;
COMport = USB;
Supply = 5.0, 100;
LockBits0 = [];
FuseBits0 = [];
{$IFDEF _USB128}
FuseBits1 = [SPIEN, JTAGEN, OCDEN];
{$ELSE}
FuseBits1 = [SPIEN];
{$ENDIF}
FuseBits2 = [];
{$IFDEF _USB16U4_32U4 or _USB128}
ProgMode = JTAG;
{$ELSE} // Mega8U2, Mega16U2, Mega32U2 ,162
ProgMode = SPI;
{$ENDIF}
{$IFDEF _USB16U4_32U4}
Import SysTick, USBport, BeepPort, WatchDog;
{$ELSE}
Import SysTick, USBport, BeepPort, SerPort1;
{$ENDIF}
From System Import;
Define
ProcClock = 16000000; {Hertz}
SysTick = 10; {msec}
StackSize = $090, iData;
FrameSize = $090, iData;
{$IFNDEF _USB16U4_32U4}
SerPort1 = 19200;
{$ENDIF}
{$IFDEF _USB128}
BeepPort = PortE, 5;
{$ELSIFDEF _USB16U4_32U4}
BeepPort = PortE, 2; // MIRFscanner
{$ELSIFDEF _USB8U2_32U2}
BeepPort = PortD, 7;
{$ELSE}
BeepPort = PortD, 7; // dummy
{$ENDIF}
//{$IFDEF _USB128}
USBvid = $9124; // Vendor-ID
USBpid = 30; // Product-ID
USBprodRel = 201; // Product-Release
USBmanufact = 'E-LAB Computers';
USBprodName = 'EvaBoard USB128';
USBcurrent = 200; // max current consumption
USBsernum = 2143; // Product serial number
USBendpoints = 1; // !!!! help to compile until Rolf resolved this :)
(*
{$ELSE}
USBvid = 9876;
USBpid = 1234;
USBprodRel = 3210;
USBmanufact = 'E-LAB Computers';
USBprodName = 'EvaBoard USBxxx';
USBcurrent = 200;
USBsernum = 7264;
{$ENDIF}
*)
Uses uAVR_USB;
Implementation
{$IDATA}
{--------------------------------------------------------------}
{ functions }
var
USBrxBuf : array[0..63] of byte;
USBtxBuf : array[0..63] of byte;
Str63[@USBTxBuf[1]] : String[63];
USBrxBuf8 : tEp3_4Buf,Align2;
USBtxBuf8 : tEp3_4Buf,Align2;
Str8[@USBTxBuf8[1]] : String[7];
cnt : Word;
{ functions }
Procedure myUserProc( x : byte; v : word);
begin
// ...
end;
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
// WatchDogStart;
USBsetUserProc(@myUserProc);
mDelay(500);
// USBsetTimeOut(100);
USBinit;
{$ifdef XMega}
EnableInts($87);
{$else}
EnableInts;
{$endif}
BeepOutHL;
{$IFNDEF _USB16U4_32U4}
WriteLn(SerOut1, 'E-LAB USB Test');
{$ENDIF}
While not USBconnected do
BeepClick;
{$IFNDEF _USB16U4_32U4}
SerOut1('x');
{$ENDIF}
mDelay(300);
endwhile;
{$IFNDEF _USB16U4_32U4}
WriteLn(SerOut1);
WriteLn(SerOut1, 'connected');
{$ENDIF}
Str63:='E-Lab Computers';
Str8:='E-Lab C';
loop
if USBgetRxState8 > 0 then
//cnt:=USBgetRxBuf8(USBrxBuf8);
endif;
if USBgetTxState8 > 0 then
USBsetTxBuf8(USBtxBuf8);
endif;
if USBgetRxState > 0 then
cnt:= USBgetRxBuf(@USBrxBuf, SizeOf(USBrxBuf));
// Writeln(Serout,IntToStr(cnt));
endif;
if USBgetTxState > 0 then
//WriteLn(SerOut, 'DownLen: '+IntToStr(USBgetTxState));
cnt:= USBsetTxBuf(@USBtxBuf, SizeOf(USBtxBuf));
endif;
{$IFNDEF _USB16U4_32U4}
if SerStat then
case SerInp of
'D', 'd' : USBclose; // detach, disconnect
|
'C', 'c' : USBinit; // re-init
|
'S', 's' : if USBconnected then
SerOut1('c');
else
SerOut1('x');
endif; // status, connected
|
else
//BeepOut(1000, 10);
SerOut1('?');
endcase;
endif;
{$ENDIF}
endloop;
end Echo.