Hallo Leute,
ich habe mir mal das DEMO "xMega_USBsmart" angeschaut und will das ganze an meinem STK600 mit ATXMega256A3U zum laufen bringen, der Code ist eigentlich genauso wie in der DEMO.
Aber ich vermisse das DING, wenn Windows versucht einen Treiber zu installieren, es passiert nichts.
Wenn ich richtig verstanden habe muss der PortPin B.7 auf HIGH liegen, damit der Treiber erkennt, es ist ein PC angeschlossen oder?
Zum testen habe ich Data+ an PD7 und Data- an PD6 über einen kleinen Vorwiderstand von ca. 20-22Ohm angeschlossen. Den USB-GND habe ich direkt mit dem GND des STK600 verbunden. Und den VBUS habe ich über einen PULLUP an die 3v3 angeschlossen.
Aber es passiert beim einstecken in den PC gar nichts! Habe ich einen Denkfehler?
Gruss
Thorsten
ich habe mir mal das DEMO "xMega_USBsmart" angeschaut und will das ganze an meinem STK600 mit ATXMega256A3U zum laufen bringen, der Code ist eigentlich genauso wie in der DEMO.
Code
program USB_Test;
{$NOSHADOW}
{ $WG} {global Warnings off}
Device = xmega256A3U, VCC = 3.3;
Define_Fuses
Override_Fuses;
NoteBook = D;
COMport = USB;
LockBits0 = [];
FuseBits0 = [];
FuseBits1 = [];
FuseBits2 = [];
// Brown-out is obligatory with USB !!!
FuseBits5 = [BODACT0, BodLevel0, BodLevel1, BodLevel2];
Import SysTick, USBsmart, BeepPort;
Define
// XMega USB must use the internal 32MHz OSC. So the system must use the 2MHz OSC
OSCtype = int2MHz,
PLLmul = 16,
prescB = 1,
prescC = 1;
SysTick = 10, adj; // msec
StackSize = $0064, iData;
FrameSize = $0064, iData;
USBmanufact = 'E-Lab Computers'; // max 31 bytes
USBprodName = 'xMiniUSBApp'; // " "
USBpid = 30;
USBvid = $1234;
USBprodRel = 201;
USBcurrent = 200;
USBvBUS = PortB.7; // port and pin
BeepPort = PortR, 0;
Implementation
{$IDATA}
{-----------------------------------------------------------------------------}
Const
LED : byte = 1;
{------------------------------------------------------------------------------}
{ Type Declarations }
Type
tBuf64 = Array[0..63] of byte;
{--------------------------------------------------------------}
{ Const Declarations }
Const
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
Var
LedCnt : word;
// these two buffers must be aligned to even addresses !!
RxBuf : tBuf64, align2; // USB incomming Buffer
TxBuf : tBuf64, align2; // USB outgoing Buffer
{--------------------------------------------------------------}
// User function to receive EP0 ControlRequests from Host
Function myUSB_ControlRequest(bRequest : Byte; wValue : word) : boolean;
// need always answer from device
Var
b : byte;
begin
case (bRequest) of
$00 : // do a real RESET
USB_ControlSend(nil, 0);
mDelay(100);
HardWareReset;
|
$20 : // write to a Port
PortF:= Lo(wValue);
BeepClick;
USB_ControlSend(nil, 0); // ACK the request
Return(True);
|
$30 : // Read a Port
b:= PinF;
BeepClick;
USB_ControlSend(@b, 1); // send back ACK and PortF status
Return(True);
|
$40 : // do Beep
BeepChirpH(2);
USB_ControlSend(NIL, 0); // send back ACK
Return(True);
|
else
BeepOut(2000, 4);
USB_ControlSend(nil, 0); // unknown vendor request, do an ACK
Return(true);
endcase;
end;
{--------------------------------------------------------------}
Procedure USB_CheckRxTx;
Var Count, C: byte;
begin
if USB_RxDataAvail then
Count:= USB_RxCount;
// do something with RXData .....
// fill TxBuf with data, then...
USB_TxSend(@TxBuf,64);
USB_RxSetBuf(@RxBuf); // we need more data ..
endif;
end;
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
DDRR:= $FF; // PORTR-> OUTPUT single LED
DDRF:= $FF; // PORTF-> OUTPUT LEDs
Incl(PortR.LED); // LED active low
USB_SetControlCallback(@myUSB_ControlRequest); // optional, if you need it!
USB_Init(@RxBuf); // Attach USB and connect RxBuf for FIRST RX INT
EnableInts($87);
BeepOutLH;
LedCnt:= 0;
loop
USB_ControlJob; // or run in Systick every < 40ms
USB_CheckRxTx;
Inc(LedCnt);
if (LedCnt = 0) then
Toggle(PortR.LED);
endif;
endloop;
end USB_Test.
{$NOSHADOW}
{ $WG} {global Warnings off}
Device = xmega256A3U, VCC = 3.3;
Define_Fuses
Override_Fuses;
NoteBook = D;
COMport = USB;
LockBits0 = [];
FuseBits0 = [];
FuseBits1 = [];
FuseBits2 = [];
// Brown-out is obligatory with USB !!!
FuseBits5 = [BODACT0, BodLevel0, BodLevel1, BodLevel2];
Import SysTick, USBsmart, BeepPort;
Define
// XMega USB must use the internal 32MHz OSC. So the system must use the 2MHz OSC
OSCtype = int2MHz,
PLLmul = 16,
prescB = 1,
prescC = 1;
SysTick = 10, adj; // msec
StackSize = $0064, iData;
FrameSize = $0064, iData;
USBmanufact = 'E-Lab Computers'; // max 31 bytes
USBprodName = 'xMiniUSBApp'; // " "
USBpid = 30;
USBvid = $1234;
USBprodRel = 201;
USBcurrent = 200;
USBvBUS = PortB.7; // port and pin
BeepPort = PortR, 0;
Implementation
{$IDATA}
{-----------------------------------------------------------------------------}
Const
LED : byte = 1;
{------------------------------------------------------------------------------}
{ Type Declarations }
Type
tBuf64 = Array[0..63] of byte;
{--------------------------------------------------------------}
{ Const Declarations }
Const
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
Var
LedCnt : word;
// these two buffers must be aligned to even addresses !!
RxBuf : tBuf64, align2; // USB incomming Buffer
TxBuf : tBuf64, align2; // USB outgoing Buffer
{--------------------------------------------------------------}
// User function to receive EP0 ControlRequests from Host
Function myUSB_ControlRequest(bRequest : Byte; wValue : word) : boolean;
// need always answer from device
Var
b : byte;
begin
case (bRequest) of
$00 : // do a real RESET
USB_ControlSend(nil, 0);
mDelay(100);
HardWareReset;
|
$20 : // write to a Port
PortF:= Lo(wValue);
BeepClick;
USB_ControlSend(nil, 0); // ACK the request
Return(True);
|
$30 : // Read a Port
b:= PinF;
BeepClick;
USB_ControlSend(@b, 1); // send back ACK and PortF status
Return(True);
|
$40 : // do Beep
BeepChirpH(2);
USB_ControlSend(NIL, 0); // send back ACK
Return(True);
|
else
BeepOut(2000, 4);
USB_ControlSend(nil, 0); // unknown vendor request, do an ACK
Return(true);
endcase;
end;
{--------------------------------------------------------------}
Procedure USB_CheckRxTx;
Var Count, C: byte;
begin
if USB_RxDataAvail then
Count:= USB_RxCount;
// do something with RXData .....
// fill TxBuf with data, then...
USB_TxSend(@TxBuf,64);
USB_RxSetBuf(@RxBuf); // we need more data ..
endif;
end;
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
DDRR:= $FF; // PORTR-> OUTPUT single LED
DDRF:= $FF; // PORTF-> OUTPUT LEDs
Incl(PortR.LED); // LED active low
USB_SetControlCallback(@myUSB_ControlRequest); // optional, if you need it!
USB_Init(@RxBuf); // Attach USB and connect RxBuf for FIRST RX INT
EnableInts($87);
BeepOutLH;
LedCnt:= 0;
loop
USB_ControlJob; // or run in Systick every < 40ms
USB_CheckRxTx;
Inc(LedCnt);
if (LedCnt = 0) then
Toggle(PortR.LED);
endif;
endloop;
end USB_Test.
Aber ich vermisse das DING, wenn Windows versucht einen Treiber zu installieren, es passiert nichts.
Wenn ich richtig verstanden habe muss der PortPin B.7 auf HIGH liegen, damit der Treiber erkennt, es ist ein PC angeschlossen oder?
Zum testen habe ich Data+ an PD7 und Data- an PD6 über einen kleinen Vorwiderstand von ca. 20-22Ohm angeschlossen. Den USB-GND habe ich direkt mit dem GND des STK600 verbunden. Und den VBUS habe ich über einen PULLUP an die 3v3 angeschlossen.
Aber es passiert beim einstecken in den PC gar nichts! Habe ich einen Denkfehler?
Gruss
Thorsten