usbPoll() & _delay_ms() error

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
honupata
Posts: 14
Joined: Sat Sep 24, 2011 1:53 am

usbPoll() & _delay_ms() error

Post by honupata » Sat Oct 22, 2011 5:24 am

Hi,

I'm blinking a RGB LED depending of the the number in buffer[0] (fill with usbFunctionWrite).
Everything is working fine without the 2 _delay_ms(500) in the main loop but with them I can only do one write (ie 0x03 for 3 blinks) after I lost the connection and I can't do any reads or writes.
Someone have a clue why the _delay_ms() in the main loop is crashing the usbPoll() ?

Thank you

Here is my main:

Code: Select all

int main(void) 
{
   // PWM LED
   int iteration = 0;
   uchar colorState = 0;
   // PWM LED
   // Set pins to output
    DDRB|= _BV(REDLED);
   DDRB|= _BV(GREENLED);
   DDRB|= _BV(BLUELED);

   // VUSB   
   wdt_enable(WDTO_1S);
   usbInit();
   
       uchar delayIteration = 20;
        while(delayIteration){ //300 ms disconnect, also allows our oscillator to stabilize
              _delay_ms(1);
              delayIteration--;
       }
        sei();

    for(;;) /* main event loop */
    {   
      // VUSB
      wdt_reset();
      usbPoll();
           
      if (iteration==INTERATION_MAX)
      {
         int nbrMessage;
         for (nbrMessage =  buffer[0];nbrMessage>0;nbrMessage--)
         {   
            wdt_reset();

            PORTB &= ~(1<<REDLED);
            PORTB &= ~(1<<GREENLED);
            PORTB &= ~(1<<BLUELED);

            // !!!!!!!!! Here !!!!!!!!!!!!!
            // I lost the connection after one write if I leave this delay and the other after.
            _delay_ms(500); 

            PORTB |= (1<<REDLED);
            PORTB |= (1<<GREENLED);
            PORTB |= (1<<BLUELED) ;

            // !!!!!!!!! Here !!!!!!!!!!!!!
            _delay_ms(500);
          }
         iteration=0;
      }
    }
    return 0;
}

ulao
Rank 4
Rank 4
Posts: 480
Joined: Mon Aug 25, 2008 8:45 pm

Re: usbPoll() & _delay_ms() error

Post by ulao » Sun Oct 23, 2011 9:45 pm

I apologize if I'm out of line here, and I can not say I know whether or not this is an issue. However I'm fairly certain 500 ms is a bit of a long wait in between pulls. I though t the usb expects talk after x ms, otherwise quits.

Daid
Rank 2
Rank 2
Posts: 55
Joined: Mon Apr 18, 2011 12:19 pm

Re: usbPoll() & _delay_ms() error

Post by Daid » Mon Oct 24, 2011 10:54 am

Code: Select all

USB_PUBLIC void usbPoll(void);
/* This function must be called at regular intervals from the main loop.
 * Maximum delay between calls is somewhat less than 50ms (USB timeout for
 * accepting a Setup message). Otherwise the device will not be recognized.
 * Please note that debug outputs through the UART take ~ 0.5ms per byte
 * at 19200 bps.
 */

ulao
Rank 4
Rank 4
Posts: 480
Joined: Mon Aug 25, 2008 8:45 pm

Re: usbPoll() & _delay_ms() error

Post by ulao » Thu Oct 27, 2011 4:11 am

well there ya go.

honupata
Posts: 14
Joined: Sat Sep 24, 2011 1:53 am

Re: usbPoll() & _delay_ms() error

Post by honupata » Wed Nov 16, 2011 4:13 am

Thank you for the info.

Post Reply