USB Endpoint-Interrupt Problem

Moderator Persönliche Seite #1159848
Lesenswert?

Frank S. wrote:

> Woran liegt es?

Daran, dass wir gerade mal eine Zeile Code von dir gesehen haben,
das Ganze aber ein verdammt komplexes Gebilde ist.  Been there,
done that.  Meine Version kannst du auf 1400 Zeilen Quellcode in
µracoli nachlesen.  Im Gegensatz zu den eierlegenden Wollmilchsäuen
wie LUFA oder dem Atmel-Code habe ich dort eine reine CDC-Implemen-
tierung gebaut, die nicht über 10 verschiedene Makro-Abstraktions-
Ebenen läuft.  Das sollte dem, was du möglicherweise hier vor hast,
nicht so sehr fern sei -- wobei du dich ja neblig-trüb bedeckt
hälst, was für eine Art USB-Gerät du da gerade aufbauen willst.
OP #1239209
Lesenswert?

Hallo, sorry so lange keine Rückmeldung.
Ich hab das code geändert.
Meine usb-initialisierung:
void USB_Init()
{
  uchar i;
//VID / PID: 0x03EB / 0x2FFB

   //reset usb
   USBCON=(1<<FRZCLK);
   USBCON &=~_BV(USBE);
   UDCON = (1<<DETACH);
   OTGIEN=0;
   UDIEN=0;
   UHIEN=0;
   UEIENX=0;
   UPIENX=0;

   for (i=0;i<8;i++)
   {
     UENUM=i;
     UEINTX=0x00;
     UECONX=0x00;
   UECFG1X=0x00;
   }

   UHWCON=(1<<UIMOD)|(1<<UVREGE);  //enable the usb device mode and 
enable pad regulator
   USBCON &= ~_BV(HOST); //device mode
 PLLCSR=0x14; // external XTAL required for usb operation:16M,
  PLLCSR=0x16;  //enable PLL
  while(!(PLLCSR & (1<<PLOCK)));

   USBCON = (1<<USBE)|(1<<FRZCLK)|(1<<OTGPADE);

    USBCON &= ~_BV(FRZCLK);
    UDCON&=~_BV(LSM);  //select full speed mode

   USBCON |= _BV(VBUSTE);
   UDCON &= ~_BV(DETACH);  //reconnect the device
    UDIEN=(1<<EORSTE)|(1<<WAKEUPE)|(1<<SOFE)|(1<<SUSPE)|(1<<EORSME);
 sei();
  }

Mein Interrupt Code:
ISR(USB_GEN_vect)
{
  uchar i, EP_Num;

 cli();

 //EP_Num = UENUM;

 if (UDINT & (1<<SUSPI))  //suspend
 {

   UDIEN |= _BV(WAKEUPE);
   UDINT &= ~_BV(WAKEUPI);

   USBCON |= (1<<FRZCLK);
   PLLCSR &= ~_BV(PLLE);
   UDINT &= ~_BV(SUSPI);
   UDINT &= ~_BV(SUSPE);
 }

 if (UDINT & (1<<EORSMI))   //resume
 {

   UDIEN &= ~_BV(WAKEUPE);
   UDINT &= ~_BV(EORSMI);
   UDIEN &= ~_BV(EORSME);

 }

 if (UDINT & (1<<WAKEUPI))   //wakeup
 {
    UDINT &= ~_BV(WAKEUPI);
    UDIEN &= ~_BV(WAKEUPE);

   PLLCSR |= (1<<PLLE);
   PLLCSR = (1<<PLLP2)|(1<<PLLP0);
   PLLCSR &= ~_BV(PLLP1);
   while(!(PLLCSR & (1<<PLOCK)));
    USBCON &= ~_BV(FRZCLK);

 }

 if (UDINT & (1<<EORSTI))   //end of reset interrupt
 {

   UDINT &= ~_BV(EORSTI); //delete INT flag
   USBCON &= ~_BV(FRZCLK);
   USBCON |= _BV(USBE);
//configuration ep0
  UENUM = 0x00;   //select endpoint 0
  UECONX &= ~_BV(EPEN);
  UECONX |= (1<<EPEN);  //enable endpoint
  UECFG0X=0x00; //control Endpoint, out.
  UECFG1X=0x30; //64 bytes, one bank
  UECFG1X |= _BV(ALLOC);//allocate the endpoint memory

  while(!(UESTA0X & (1<<CFGOK)));   //until the config is ok

 //reset all the endpoints
  UERST |= (1<<UENUM);
  UERST &= ~_BV(UENUM);

  UEIENX = (1<<RXSTPE)|(1<<RXOUTE)|(1<<TXINE);  //enable received setup 
int, enable received out data int

  }
}

In main() hab ich eine Funktion usb_poll() geschrieben:
usb_poll()
{
UENUM = 0;
//sei();
  if (UEINTX & (1<<RXSTPI))  //check if a new setup packet is received
  {}
}

Jetzt ist das Problem: RXSTPI nicht gleich 1! Fuse habe ich auch richtig 
eingestellt. Weiß jemand wieso? Bitte mir einen Vorschlag geben. Danke

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren