I don't claim to be an expert on any of these topics, but there are a couple of things I noticed in the code that concern me:
-
First off, in your interrupt function read_ir_bit(), you make a call to delayMicroseconds(). I'm fairly certain that timing functions (including serial) do not work inside an interrupt routine.
-
I believe the preferred method for handling interrupts is to simply set a few variables or bitmasks and then return processing to the rest of your code. For example, things might work out better if read_ir_bit() simply modified a volatile boolean variable irCommandIncoming = true; and then allow the main code loop to process that bit? it's just an idea.
-
also, though your function is named read_ir_bit() it appears to be reading the entire code, thus I would guess that every time the pin is FALLING (which happens numerous times during a single command) you start another interrupt routine. Once the interrupt is triggered by the falling edge, I would disable the interrupt while reading the rest of the command.
These are all just educated guesses. I'll try to play with it a bit myself when I have some free time.
Tim