USART TX & RX over IR interfere

I’m sending and receiving IR transmission through the USART on my Arduino, but I find that my transmission interferes with my reception. To some extent, it’s a hardware issue: when I extract the IR LED and replace it with a visible-light LED, reception occurs as it should, with no errors.

All three of my AVR’s timers are already in use, so reception is triggered in an ISR for USART_RX_vect, and transmission is running all the time in the main loop:

void main()
  initialize(); // run some tasks, such as setting up timers and interrupt

  while (1) {
    /* update rgb leds */
    /* Read from USART if flag is set */
    /* Transmit packet through USART */

void input()
  /* read from usart if usart rx flag is set */
  if (flagToReadFromUsart) {
    // read a byte and do stuff
    flagToReadFromUsart = false;

void output()
  /* count and transmit */

  flagToReadFromUsart = true;

The result is that one out of every three to five packets I receive contain errors (even though I am confirming packet headers and checksums, and the header for TX is different from the header for RX).

I tried calling cli() and sei() before and after transmitPacket(), but that made no effect. So I guess I really just don’t understand how the USART works. Can anyone help me figure out how to get TX and RX working without interfering with one another?

The code is obviously incomplete, and it would be better if it was complete.

I guess that you're using the IR as a loopback connection ie sending from the Arduino back to itself.

If you're using the UART to generate and decode the serial signal then it should be capable of sending and receiving simultaneously. In this case you'd use TX (1) to output the signal to the IR emitter and RX (0) to input the signal from the IR receiver. Is it possible that the IR receiver is simply not receiving accurately the signal that you sent?

Your suggestion that my Arduino might not be receiving the IR data correctly may be accurate.

When I remove the IR LED from my Arduino and set up another Arduino to read from the TX port, I see that data being transmitted is incorrect. (The data that's passed to the Arduino from the IR receiver is correct, at least. But I can't confirm that my Arduino is receiving it through the USART correctly.) Do you have any idea how I can diagnose this better?

You can find the entire code on my github repo here: (The included files are also available on that repo.)

Vaselinessa: Do you have any idea how I can diagnose this better?

The only way I can see would be to use a 'scope to compare the sent and received TTL serial signals and see if they matched consistently. Well, the other way is just to see whether the byte stream sent is received correctly, but you've already shown that it isn't.

In the absence of a 'scope, you could just try playing around with the physical sensor arrangement and the preprocessing you (presumably) apply to that signal before supplying it to the UART, and see if you can stumble on a setup that works better. But without know what's wrong with the signal, it'd be pure guesswork. A 'scope is the only practical way I can see to find out what's wrong with the signal.