Hi everybody,
I've got an intriguing question on HIDkeys and UART.
My firmware should run in the following way:
whenever the attiny2313 running HIDkeys receives a message on the
UART it should simulate pressing a key on the keyboard. The HIDkeys runs
without problems, with a button attached to the attiny I can make it work fine.
Unfortunately I have strange problems with UART. The following is the main loop
of "my" (yeah, it is rather yours) firmware.
for(;;){
//wdt_reset(); /* watchdog is DISABLED for now */
usbPoll();
if(UCSRA & (1 << RXC)){
// received data, pull that data out of the internal buffer
j=UDR;
//if (j=='d') {
state=STATE_SEND_KEY_DOWN;
//}
}
if (state!=STATE_IDLE && usbInterruptIsReady()) {
if (state==STATE_SEND_KEY_DOWN) {
key = 1;
} else if (state==STATE_SEND_KEY_UP) {
key = 0;
}
state--;
buildReport(key);
usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
}
}
If defined this way, it works -- every time I get something on the USART (and here
it doesn't matter what it is), a key-press is simulated.
Now the strange thing comes: when I enable the innocent "if (j=='d')" the whole
thing stops working. Whenever I send something on the UART ('d' or not 'd'), the
firmware seems to reset, i.e. a new enumeration is started on windows. The device
fails to simulate any key presses.
When I was trying to make this run at all (without UART, with a button) I have had
this strange resettings already. I had the impression that it was sometimes
one line of simple code added in the main-loop which made this happen. This looks
a little like timing problems to me, but I do not have an idea why exactly this
could have happened.
Do you have an idea in which direction I should look? If you have any concrete
tests I could run, let me know, I'll be happy to provide you with more information.
Regards,
Jarek