user45924: So I have an Arduino Mega and I'm attempting serial communication with another device, and I ran into this 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 as different Megas.
How is this interference happening? Do I have an incorrect understanding of the serial buffers? What can I do to stop it? It's causing interference in communicating with my external device.
Here is a super short program to test this theory. 
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); 
  }
}

UPDATE:  I came back the next day with my O-scope and the yellow line is the TX and the blue line is the RX. I was not getting the crosstalk anymore in the Serial port, but on the scope shows the RX line was only being effected about 250mV in perfect unison to the TX. I tried connecting everything back up the same way but I was not able to replicate the issue. Somehow whatever I had going on when I posted this was causing the RX line to be affected great enough for the Mega to pick up on it over serial. For now I'm just blaming it on escaped aliens from Area 51 :)


user57952: I ran a slightly modified version of your test code on a Mega 2560 and got no echo at all;  Unless I totally misunderstood your problem description, there must be something else going on.  Here's the code I ran:

char test[15];

void setup()
{
    Serial.begin(9600);
    Serial1.begin(115200);
    for (int i = 0; i < 15; i++)
    {
        //Serial.print(i);
        test[i] = i;
        Serial.print(test[i],HEX);
    }
    Serial.println();

    for (size_t j = 0; j < 15; j++)
    {
        Serial.print("test["); Serial.print(j); 
        Serial.print("] = ");Serial.println(test[j],HEX);
    }
}

void loop()
{
    for (int i = 0; i < 15; i++)
    {
        Serial1.write(test[i]);
    }

    Serial.println(Serial1.available());

    while (Serial1.available() > 0)
    {
        byte c = Serial1.read();
        Serial.print(' ');
        Serial.print(c, HEX);
    }
}

And here's a bit of the output seen on Serial0:
Opening port
Port open
VMDPV_1|1_�Se�
0123456789ABCDE
test[0] = 0
test[1] = 1
test[2] = 2
test[3] = 3
test[4] = 4
test[5] = 5
test[6] = 6
test[7] = 7
test[8] = 8
test[9] = 9
test[10] = A
test[11] = B
test[12] = C
test[13] = D
test[14] = E
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

As you can see, the Serial1 read buffer was always empty.  
Did I misunderstand something you said?

45924: <p>So I have an Arduino Mega and I'm attempting serial communication with another device, and I ran into this weird issue.</p>

<p>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), <strong>with NO wires plugged in the serial port</strong>, 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 as different Megas.</p>

<p>How is this interference happening? Do I have an incorrect understanding of the serial buffers? What can I do to stop it? It's causing interference in communicating with my external device.</p>

<p>Here is a super short program to test this theory. </p>



<pre class="lang-cpp prettyprint-override"><code>void setup() 
{
  Serial.begin(9600);
  Serial1.begin(115200);  
}

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

  for (int i = 0; i &lt; 15; i++)
     Serial1.write(test[i]);

  while(Serial1.available() &gt; 0 ) 
   {
    byte c = Serial1.read();
    Serial.print(' '); 
    Serial.print(c, HEX); 
  }
}
</code></pre>

<p><strong>UPDATE:</strong>  I came back the next day with my O-scope and the yellow line is the TX and the blue line is the RX. I was not getting the crosstalk anymore in the Serial port, but on the scope shows the RX line was only being effected about 250mV in perfect unison to the TX. I tried connecting everything back up the same way but I was not able to replicate the issue. Somehow whatever I had going on when I posted this was causing the RX line to be affected great enough for the Mega to pick up on it over serial. For now I'm just blaming it on escaped aliens from Area 51 :)</p>

<p><a href="https://i.stack.imgur.com/kGHWw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kGHWw.png" alt="enter image description here"></a></p>
 57952: <p>I ran a slightly modified version of your test code on a Mega 2560 and got no echo at all;  Unless I totally misunderstood your problem description, there must be something else going on.  Here's the code I ran:
</p>

<pre class="lang-cpp prettyprint-override"><code>char test[15];

void setup()
{
    Serial.begin(9600);
    Serial1.begin(115200);
    for (int i = 0; i &lt; 15; i++)
    {
        //Serial.print(i);
        test[i] = i;
        Serial.print(test[i],HEX);
    }
    Serial.println();

    for (size_t j = 0; j &lt; 15; j++)
    {
        Serial.print("test["); Serial.print(j); 
        Serial.print("] = ");Serial.println(test[j],HEX);
    }
}

void loop()
{
    for (int i = 0; i &lt; 15; i++)
    {
        Serial1.write(test[i]);
    }

    Serial.println(Serial1.available());

    while (Serial1.available() &gt; 0)
    {
        byte c = Serial1.read();
        Serial.print(' ');
        Serial.print(c, HEX);
    }
}
</code></pre>

<p>And here's a bit of the output seen on Serial0:</p>

<pre class="lang-cpp prettyprint-override"><code>Opening port
Port open
VMDPV_1|1_�Se�
0123456789ABCDE
test[0] = 0
test[1] = 1
test[2] = 2
test[3] = 3
test[4] = 4
test[5] = 5
test[6] = 6
test[7] = 7
test[8] = 8
test[9] = 9
test[10] = A
test[11] = B
test[12] = C
test[13] = D
test[14] = E
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
</code></pre>

<p>As you can see, the Serial1 read buffer was always empty.  </p>

<p>Did I misunderstand something you said?</p>
