Page 1 of 1

usbPoll() & _delay_ms() error

Posted: Sat Oct 22, 2011 5:24 am
by honupata
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;
}

Re: usbPoll() & _delay_ms() error

Posted: Sun Oct 23, 2011 9:45 pm
by ulao
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.

Re: usbPoll() & _delay_ms() error

Posted: Mon Oct 24, 2011 10:54 am
by Daid

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.
 */

Re: usbPoll() & _delay_ms() error

Posted: Thu Oct 27, 2011 4:11 am
by ulao
well there ya go.

Re: usbPoll() & _delay_ms() error

Posted: Wed Nov 16, 2011 4:13 am
by honupata
Thank you for the info.