Go Down

Topic: Arduino Mega Reading same information that it's sending out (Read 194 times) previous topic - next topic

HAv0C_RC

So I have an Arduino Mega and I'm attempting serial communication with another device, and I ran into this super weird issue.

Let's say I use Serial1.write to send out hex A-F. If I read on that same port (Serial1, print out what I read on Serial0), with NO wires plugged in the serial port, I get a mirror of what I'm sending out in my read function. I've tested this theory on multiple serial ports as well.

How is this interference happening? What can I do to stop it?

Here is a super short program to test this theory.

Code: [Select]


void setup()
{
  Serial.begin(9600);
  Serial1.begin(115200); 
}

void loop()
{
  char test[15];
  for (int i = 0; i < 15; i++)
    test[i] = i;

  for (int i = 0; i < 15; i++)
   {
     Serial1.write(test[i]);
   }
 
  while(Serial1.available() > 0 )
   {
    byte c = Serial1.read();
    Serial.print(' ');
    Serial.print(c, HEX);
  }
}


HAv0C_RC

Why do you care that it happens?
Because it is messing up my communication with another device. Let's say Arduino A is transmitting and receiving, but for a second, it stops receiving data from a Arduino B, the phenomenon occurs while the transmit from A is still active, which in turn echos into the RX which then adds random characters that mess up my checksum, add random characters that change the projected length of my next packet, or take the system a few iterations to get back to receiving clean data when B comes back online and begins transmitting.

Coding Badly

Because it is messing up my communication with another device.
Which indicates your protocol is flawed.

Given the fact that the transmit line (TX) is actively driven I suspect you also have a hardware problem.


HAv0C_RC

Which indicates your protocol is flawed.

Given the fact that the transmit line (TX) is actively driven I suspect you also have a hardware problem.
The problem lies in the framing of my packet. The start delimiter of my receiving packet begins with an 0xFA. That's also the start delimiter of my packet that I am sending out, so when I send that out, and it returns on in my RX via crosstalk, as well as several other random values, it becomes a false start it can mess with my protocol a bit. Yes, my protocol isn't the most robust, but I'm no high level serial programmer. If I can fix this crosstalk with some hardware I'd like to pursue that.

I've tried this on 2 different brand name Arduino Megas, same result.

Robin2

Make a simple pencil drawing that shows clearly how everything is connected and post a photo of the drawing. See this  Simple Image Guide

Have you a GND connection as well as Tx and Rx?

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication. I don't recall any problems communicating between two Megas.

You can send data in a compatible format with code like this (or the equivalent in any other programming language)
Code: [Select]
Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up