Serial Module Echoing a `0x00` I am having a problem with a MAXIM Serial module (Config A) with a simple repeating code from COM port. When sending a character (k:0x6b) I receive a (0x00) echo.

Without the module and just connecting the arduinos crossing the TX/RX cables, I do not have any echo. 

The echo persists, disregarding of:


The speed (from 38400 to 2000000 bps), 
Using or not the high speed options (2.3MOhm for 250000bps) of the MAXIM,
Using or not 120 ohm terminal resistors,
Both grounds are 0V, connecting them has no effect,
Removing the A (red) B (green) Serial Bus Cables (???). Message not send in this case, as expected (!).


What could be the problem?

Devices:


Two Arduino Mega 2560,
Two MAX3292, one for each arduino,
AWG24 Cable, shorter than 7 in each.


Config A: With Module (00 echo), Half Duplex (f.19 p.13).




Config B: Without Module (No echo), only crossed cables



Code:

long rate=38400;
void setup() {
    Serial.begin(rate); while (!Serial);
    Serial1.begin(rate); while (!Serial1);
    pinMode(22,OUTPUT);
    pinMode(23,OUTPUT);
}
char s;
void loop() {
    if (Serial.available()) {
        digitalWrite(22,1);
        digitalWrite(23,1);
        s=Serial.read();
        Serial1.write(s);
        Serial1.flush();
        digitalWrite(23,0);
        digitalWrite(22,0);
    }
    if (Serial1.available()){
        s=Serial1.read();
        Serial.write(s);
    }
}


Execution: Four k sent, 0x00 echoes received. After this, four k send from other arduino, received successfully. 




Epilogue.

Actually, the problem was a resistor at the RO output, not shown in the diagram ("The problem is in the code you didn't post"). 

It was a voltage divider for a 5V3.3 conversion in the Arduino Due case, useless in the Arduino Mega, but still there. 

Theorizing a reason, that resistor caused a spike at the output (?), thus forcing the module to interpret it as another byte, an empty one (?). 

After removing the resistors, it worked perfectly. 
Now I migrated this back into Arduino Due, but with a diode plus a pull up resistor as a 5V3.3 converter.
Check your wiring! My guess is the twisted pair (A-B swap).

I've checked your code, it seems right. Please note that /RE and DE were designed that way so you can simply connect them and control with only one pin.

I don't have the exact same hardware, I had MAX485 and Arduino Nano at hand. Nano only has one hardware serial, so I've used the SoftwareSerial library instead.
I've connected them, adjusted your code to my setup, and it worked. Here it is in case it helps to troubleshoot your issue. I've also optimized your version a little bit (but it worked before so the bug is somewhere else).

#include &lt;SoftwareSerial.h&gt;
SoftwareSerial mySerial(2, 4); // RX, TX

const int dir_pin=9;
const int dir_transmit=1;
const int dir_receive=0;
long rate=38400;

void setup() {
    Serial.begin(rate); while (!Serial);
    mySerial.begin(rate); while (!mySerial);
    pinMode(dir_pin,OUTPUT);
}
char s;
void loop() {
    if (Serial.available()) {
        digitalWrite(dir_pin,dir_transmit);
        while(Serial.available())
        {
          s=Serial.read();
          mySerial.write(s);
        }
        mySerial.flush();
        digitalWrite(dir_pin,dir_receive);
    }
    while (mySerial.available()){
        s=mySerial.read();
        Serial.write(s);
    }
}