Pages: [1]   Go Down
Author Topic: USART TX & RX over IR interfere  (Read 480 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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

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

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 */
  _delay_ms(80);
  transmitPacket();
}

ISR(USART_RX_vect)
{
  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?
« Last Edit: May 03, 2013, 03:02:12 pm by Vaselinessa » Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11196
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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: https://github.com/Vaselinessa/treasure-hunt-des-marais/blob/feature/will-o-the-wisp/will-o-the-wisp/main.c. (The included files are also available on that repo.)
Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11196
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: