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;
}