0

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 A Config A Datasheet

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

Config B

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.

Exec A enter image description here

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.

  • 1
    You do have the grounds of the Arduinos connected together don't you? – Majenko Sep 9 at 19:08
  • 1
    Ok, looking in more detail - what code is at the other end? You have two megas, but only show one code. Second - your terminal program is set to a different baud rate than your program. – Majenko Sep 9 at 20:10
  • 1
    With that code for both, why do you expect anything to echo back? The 00 is the error, not the no response. – Majenko Sep 9 at 20:23
  • 1
    Does your fritzing diagram precisely describe reality, or is your right-hand chip actually wired differently to how you are showing it? – Majenko Sep 9 at 20:37
  • 1
    So, you actually have your right-hand chip wired wrong? Inspect the wires going between the Arduino and the right hand chip... – Majenko Sep 9 at 20:50
1

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 <SoftwareSerial.h>
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);
    }
}
  • Well, the code and the configuration was ok but... a resistor divider at the RO output not shown in the diagram was causing the problem. After removing it, everything worked fine. Thanks for the effort anycase... – Brethlosze Sep 11 at 2:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.