The solution to the Problem was to enable interrupt within the polling timer so that it doesnt block the USB interrupts. I nearly went crazy because the USB stack crashed when I used a timer at F_CPU/1024 with that code without the highligthed sei(); With the sei(); everything runs like clockwork since the rc5 decoding is not too time critical.
Code: Select all
ISR(TIMER0_OVF_vect)
{
// triggert FCPU/1024, 64µs
TIMSK &= ~(1 << TOIE0);
TCNT0 = -1;
[b]sei();[/b]
uint16_t tmp = rc5_tmp;
if (++rc5_time > PULSE_MAX) {
if (!(tmp & 0x4000) && tmp & 0x2000) rc5_data = tmp;
tmp = 0;
}
if ((rc5_bit ^ PIND) & (1 << PIND3)) {
rc5_bit = ~rc5_bit;
if (rc5_time < PULSE_MIN) tmp = 0;
if (!tmp || rc5_time > PULSE_1_2) {
if (!(tmp & 0x4000)) tmp <<= 1;
if (!(rc5_bit & 1<<PIND3)) tmp |= 1;
rc5_time = 0;
}
}
rc5_tmp = tmp;
TIMSK |= (1 << TOIE0);
}
)