Max485 Burns up

Hi all,
I have a modelrailway at home and it's running on a network of Arduino's. The tracks are powered via L298N modules. The corresponding Arduino is sending a PWM signal to the L298N modules.
To communicate between the different Arduino's I use a Max485 module.
I don't know if I have to describe the global picture with all the arduino's and modules. It will become to much and complicated.
So now my problem I have recently.
One of the MAX485 modules didn't work anymore. The question is how can it happpen ?

Here a fritzing schema for 1 of the arduino's

Hardware components
Arduino : Nano
MAX485: RS-485 TTL to RS485
L298N: Dual H Bridge Dc Stepper Motor Drive Controller Board Module L298N

The MAX485LN modules are connected to each other as it should be. The First and the last module has a resistor of 100ohm between the A and B ports.

I suppose that the following is happening.
When a train a a specific track is "blocked" or not driving, the resistance on that track becomes very high.
Due to the common ground between the 3 modules, the MAX485 is burned up.
First question : Can this happen ?
Second question: Can I isolate the MAX485 and the Nano from the L298N modules via a Optocoupler? Keep in mind that the pins connected to the ENA and ENB of the L298N ports are sending a PWM signal.

Here the code for this Nano

/*
  Besturing van SMD module voor 4 sporen modelspoor deel "Links"
  by Marc Baeten
*/
#include <EEPROM.h>
#include <elapsedMillis.h>
#include "RS485_protocol.h"
#include <SoftwareSerial.h>

#define interval 500 // voor print logging

// sturing SMD High Low
#define inH A1
#define inL A2

#define SSerialRX   7  //Serial Receive pin
#define SSerialTX   8  //Serial Transmit pin
const byte ENABLE_PIN = 4;  //  enable sending rs485
SoftwareSerial rs485 (SSerialRX, SSerialTX);  // receive pin, transmit pin

elapsedMillis timerRS485;
elapsedMillis timer0;


const byte nmbrOfBV = 4;  // 3 + 1
// Arrays per baanvak
elapsedMillis timerSpoor[nmbrOfBV];
byte bzBV[nmbrOfBV];
byte stBV[nmbrOfBV];
byte oldStBV[nmbrOfBV];
byte treinID[nmbrOfBV];
int startSpeed[nmbrOfBV];
int targetSpeed[nmbrOfBV];
int vertragingTrein[nmbrOfBV];
int versnellingTrein[nmbrOfBV];
float speedPWM[nmbrOfBV]; // effectieve speed van het banvak.
boolean debugBV[nmbrOfBV];
const byte PWMtoBV [nmbrOfBV] = {0, 16, 15, 14}; // Index 0 not used
const byte pwmPIN[nmbrOfBV] =   {0, 11, 10,  9}; // pins on Arduino

byte teller;
byte deviceId;   //Variable to store data read from EEPROM.
byte mesCounter = 0;
boolean newMessage = false;

// Manual input of info or debug
int inputStatus = 0;
int inputValue = 0;
int inputID = 0;
int inputFunctie = 0;
byte debugRS485 = 1; //0 = NoDebug, 1 = OnlyError, 2 = NoWarning, 3 = All
boolean debugBezet = false;
boolean debugMessage = false;

// Speed controal via PWM
const byte maxSpeed = 200;
const byte minSpeed = 75;

byte msg[25];
byte buf[26];
//===========================================================================
// callback routines RS485
void fWrite (const byte what)
{
  rs485.write (what);
}

int fAvailable ()
{
  return rs485.available ();
}

int fRead ()
{
  return rs485.read ();
}
//===========================================================================
// the setup function runs once when you press reset or power the board
void setup() {
  EEPROM.get(0, deviceId);

  Serial.begin(19200);
  Serial.println ("");
  Serial.print(F("Begin, Id = "));
  Serial.println(deviceId, HEX);

  int i;

  rs485.begin (19200);
  pinMode (ENABLE_PIN, OUTPUT);  // driver output enable
  digitalWrite (ENABLE_PIN, LOW);  // disable sending
  // init PWM pins
  for (i = 1; i < nmbrOfBV; i++) { // index 0 not used
    pinMode(pwmPIN[i], OUTPUT);
    digitalWrite(pwmPIN[i], 0);
    startSpeed[i] = 0;
    targetSpeed[i] = 0;
    bzBV[i] = 0;
    stBV[i] = 0;
    oldStBV[i] = 0;
    treinID[i] = 0;
    debugBV[i] = false;
  }
  pinMode(inH, OUTPUT);
  pinMode(inL, OUTPUT);
  digitalWrite(inH, HIGH);
  digitalWrite(inL, LOW);
  emptyMsg(0);
  for (i = 0; i < sizeof(buf); i++) {
    buf[i] = 0;
  }
  Serial.println ("Einde setup ");
}
//===========================================================================
// the loop function runs over and over again forever
void loop() {

  if (Serial.available()) {
    int inChar = Serial.read();
    manualSetup(inChar);
  }

  if (debugRS485 > 2) {
    Serial.print ("Loop: ");
    Serial.print (teller++);
    Serial.print (" ID: ");
    Serial.print (deviceId, HEX);
  }
  receiveMessage();
  if (newMessage) {
    if (debugMessage)  {
      Serial.print ("St16: ");
      Serial.print (stBV[1]);
      Serial.print (" St15: ");
      Serial.print (stBV[2]);
      Serial.print (" St14: ");
      Serial.print (stBV[3]);
      Serial.print (" St16: ");
      Serial.print (startSpeed[1]);
      Serial.print (" St15: ");
      Serial.print (startSpeed[2]);
      Serial.print (" St14: ");
      Serial.print (startSpeed[3]);
      Serial.print (" Targ16: ");
      Serial.print (targetSpeed[1]);
      Serial.print (" Targ15: ");
      Serial.print (targetSpeed[2]);
      Serial.print (" Targ14: ");
      Serial.print (targetSpeed[3]);
      Serial.print (" ID16: ");
      Serial.print (treinID[1]);
      Serial.print (" ID15: ");
      Serial.print (treinID[2]);
      Serial.print (" ID14: ");
      Serial.println (treinID[3]);

    }
    newMessage = false;
    // verwerken ontvangen data
  }
  for (int i = 1; i < nmbrOfBV; i++) {
    if (stBV[i] == 0) {
      bzBV[i] = false;
      //      speedPWM[i] = 0;
    } else {
      bzBV[i] = true;
    }
    PWMSturing(i, pwmPIN[i], vertragingTrein[i], versnellingTrein[i]);
    oldStBV[i] = stBV[i];
  }
  if (debugRS485 > 2) {
    Serial.println (" ");
  }
  // print logging
  if (timer0 > interval) {
    printBezetBV();
    printDebugBV();
    timer0 = 0;
  }
}

//=============PWM STURING ==============================================
void PWMSturing(int i, int pin, int vertragingTrein, int versnellingTrein)
{
  float start = startSpeed[i];
  float target = targetSpeed[i];
  float versnelling = 0;
  if (start > target) {
    versnelling = - vertragingTrein;
  } else {
    versnelling = versnellingTrein;
  }
  if (stBV[i] != 0) {
    if (oldStBV[i] == 0) {
      timerSpoor[i] = 0;
      speedPWM[i] = start;
    }
    float tijd = (timerSpoor[i] / 1000.0);
    speedPWM [i] = (start + (tijd * versnelling));
    if (versnelling < 0) {                 // afremmen
      if (speedPWM[i] < target) {
        speedPWM[i] = target;
      }
    } else {                              // optrekken
      if (speedPWM[i] > target) {
        speedPWM[i] = target;
      }
    }
  }
  speedPWM[i] = mini(maxSpeed, speedPWM[i]);
  speedPWM[i] = maxi(minSpeed, speedPWM[i]);
  analogWrite(pin, int(speedPWM[i]));
}
//===============================================================================
void receiveMessage() {
  int received = recvMsg (fAvailable, fRead, buf, sizeof (buf), 250);
  if (received > 0) {
    if (debugRS485 > 2) {
      Serial.print (" rcv: ");
      if (received < 10 ) {
        Serial.print (" ");
      }
      Serial.print (received);
    }
    if (received != buf[3] + 4) {
      if (debugRS485 > 0) {
        Serial.print ("Afzender ");
        Serial.print (buf[0], HEX);
        Serial.println (" lengte bericht NOK.");
      }
      return;
    }
    if (buf [0] != 1) {
      if (debugRS485 > 2) {
        printBuf (buf, received);
        Serial.print (" Afz  ");
        Serial.print (buf[0], HEX);
        Serial.print (" is niet de master.");
      }
      return;
    }
    if (buf [1] != deviceId) {
      if (debugRS485 > 2) {
        printBuf (buf, received);
        Serial.print (" Ontv ");
        Serial.print (buf[1], HEX);
        Serial.print (" is niet mijn ID");
      }
      return;
    }
    if (!(buf [2] == 2 || buf [2] == 8 )) {
      if (debugRS485 > 0) {
        printBuf (buf, received);
        Serial.print (" Comm ") ;
        Serial.print (buf[2], HEX);
        Serial.print (" niet gekend");
      }
      return;
    }
    //    digitalWrite (LED_PIN, HIGH);
    if (buf [2] == 2) {
      msg[0] = deviceId;          // Sender
      msg[1] = 1;                 // Receiver 1 (naar master)
      msg[2] = 3;                 // Function : return status
      msg[3] = 2;                 // Size Data
      msg[4] = buf[4];
      msg[5] = 1;                 // no reader connected, always true returned
      sendarduino();
      if (debugRS485 > 2) {
        Serial.print (" status ");
        printBuf (msg, msg[3] + 4);
      }
      return;
    }
    if (buf [2] == 8) {
      newMessage = true;
      intToStBV(int(buf[5]), 1, 2);
      intToStBV(int(buf[6]), 3, 0);
      startSpeed[1] = int(buf[7]);
      startSpeed[2] = int(buf[8]);
      startSpeed[3] = int(buf[9]);
      targetSpeed[1] = int(buf[10]);
      targetSpeed[2] = int(buf[11]);
      targetSpeed[3] = int(buf[12]);
      vertragingTrein[1] = int(buf[13]);
      vertragingTrein[2] = int(buf[14]);
      vertragingTrein[3] = int(buf[15]);
      versnellingTrein[1] = int(buf[16]);
      versnellingTrein[2] = int(buf[17]);
      versnellingTrein[3] = int(buf[18]);
      treinID[1] = int(buf[19]);
      treinID[2] = int(buf[20]);
      treinID[3] = int(buf[21]);

      msg[0] = deviceId;          // Sender
      msg[1] = 1;                 // Receiver 1 (naar master)
      msg[2] = 9;                 // Function : Send reply PWM data
      msg[3] = 4;                 // Size Data
      msg[4] = buf[4];
      msg[5] = int(speedPWM[1]);
      msg[6] = int(speedPWM[2]);
      msg[7] = int(speedPWM[3]);
      sendarduino();
      if (debugRS485 > 1) {
        Serial.println ("");
        if (debugRS485 > 2) {
          Serial.print ("Loop: ");
          Serial.print (teller);
          Serial.print (" ID: ");
          Serial.print (deviceId, HEX);
          Serial.print (" snd:  ");
        }
        Serial.print (msg[3] + 4);
        printBuf (msg, msg[3] + 4);
      }
      if (debugRS485 == 2) {
        Serial.println (" ");
      }
      return;
    } // end send
  }  // end if something received
  else {
    if (debugRS485 > 0) {
      if (received == -1) {
        Serial.print (" Bad character ");
      }
      if (received == -2) {
        Serial.print (" Bad crc ");
      }
      if (received == -3) {
        Serial.print (" Overflow ");
      }
    }
    if (debugRS485 > 1) {

      if (received == 0) {
        Serial.print (" Nothing received");
      }
    }
    if (debugRS485 == 2) {
      Serial.println (" ");
    }
    return;
  }
}
//===========================================================================
void sendarduino () {

  digitalWrite (ENABLE_PIN, HIGH);  // enable sending
  delay(2);
  sendMsg (fWrite, msg,  msg[3] + 4);
  digitalWrite (ENABLE_PIN, LOW);  // disable sending
  // send message
  if (debugRS485 > 1) {
    //Serial.print (" Sent:");
    printBuf(msg, msg[3] + 4);
  }
}
//===========================================================================
void emptyMsg (int start) {
  for (int i = start; i < sizeof(msg); i++) {
    msg[i] = 0;
  }
}
//===========================================================================
void intToStBV(int b, int i, int j)
{
  stBV[i] = ((unsigned int)b >> 0) & 0x0F;
  stBV[j] = ((unsigned int)b >> 4) & 0x0F;
}
//=============================================================================
float mini(float a, float b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
//=============================================================================
float maxi(float a, float b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
//===========================================================================
int getIndexBV(byte a) {
  for (int i = 1; i < nmbrOfBV; i++)
  {
    if (PWMtoBV[i] == a) {
      return i;
    }
  }
  return 0;
}
//===========================================================================
void manualSetup(int inChar) {

  Serial.print (" Ingelezen: ");
  Serial.print ((char)inChar);
  Serial.print (" int: ");
  Serial.println (int(inChar));

  if (isDigit(inChar)) {
    if (inputStatus == 1 || inputStatus == 2) {
      inputValue = inputValue * 10 + (inChar - 48);
      return;
    }
  }
  else {
    if (int(inChar) == 61) { // =
      inputID = inputValue;
      inputStatus = 2;
      inputValue = 0;
      return;
    }
    if (int(inChar) == 65) { // A
      inputFunctie = 5; // Debug Bezet
      inputStatus = 1;
      inputValue = 0;
      return;
    }
    if (int(inChar) == 66) { // B
      inputFunctie = 1; // Debug Baanvak
      inputStatus = 1;
      inputValue = 0;
      return;
    }
    if (int(inChar) == 77) { // M
      inputFunctie = 4; // Debug RS485
      inputStatus = 1;
      inputValue = 0;
      return;
    }
  }
  if (inChar == '\n') {
    if (inputStatus == 2) {
      if (inputFunctie == 1) {  // Debug Baanvak
        int i = getIndexBV(byte(inputID));
        if (inputValue == 1) {
          debugBV[i] = true;
        } else {
          debugBV[i] = false;
        }
        Serial.print ("Debug Baanvak: ");
        Serial.print (inputID);
        Serial.print (" value: ");
        Serial.println (inputValue);
        inputStatus = 0;
        return;
      }
      if (inputFunctie == 4) { // Debug RS485
        debugRS485 = inputValue;
        Serial.print ("Debug RS485: ");
        Serial.print (inputID);
        Serial.print (" value: ");
        Serial.println (inputValue);
        inputStatus = 0;
        return;
      }
      if (inputFunctie == 5) { // Debug bezet
        debugBezet = inputValue;
        Serial.print ("Debug Bezet: ");
        Serial.print (inputID);
        Serial.print (" value: ");
        Serial.println (inputValue);
        inputStatus = 0;
        return;
      }
    }
  }
}
//===========================================================================
void printBuf(byte * buffer, int bufferSize) {
  for (int i = 0; i < bufferSize; i++) {
    Serial.print (" ");
    if (buffer[i] < 0x10) {
      Serial.print ("0");
    }
    Serial.print (buffer[i], HEX);
  }
  Serial.print (" ");
}
//==============================================================================
void printBezetBV() {
  if (debugBezet) {
    int a = 0;
    for (int i = 1 ; i < nmbrOfBV ; i++) {
      if (bzBV[i]) {
        printBV(i, 0);
        a++;
      }
    }
    if (a > 1) {
      Serial.println ("-------------------------------------");
    }
  }
}
//==============================================================================
void printDebugBV() {
  int a = 0;
  for (int i = 1 ; i < nmbrOfBV ; i++) {
    if (debugBV[i]) {
      printBV(i, 0);
      a++;
    }
  }
  if (a > 1) {
    Serial.println ("-------------------------------------");
  }
}
//===========================================================================
void printBV(int i, int a) {
  Serial.print (a);
  Serial.print (" BV: ");
  if (pwmPIN[i] == 0) {
    Serial.print (">");
  } else {
    Serial.print ("<");
  }
  printInteger (PWMtoBV[i], 2);
  Serial.print (" bz: ");
  Serial.print (bzBV[i]);
  Serial.print (" st: ");
  Serial.print (stBV[i]);
  Serial.print (" ID ");
  printInteger (treinID[i], 2);
  Serial.print (" start ");
  printInteger (startSpeed[i], 3);
  Serial.print (" sp: ");
  printInteger (speedPWM[i], 3);
  Serial.print (" targ ");
  printInteger (targetSpeed[i], 3);
  Serial.print (" timer: ");
  printInteger (timerSpoor[i], 5);
  Serial.println (" ");
}
//===========================================================================
void printInteger(unsigned long i, int n) {
  if (n >= 5 && i < 10000) {
    Serial.print("0");
  }
  if (n >= 4 && i < 1000) {
    Serial.print("0");
  }
  if (n >= 3 && i < 100) {
    Serial.print("0");
  }
  if (n >= 2 && i < 10) {
    Serial.print("0");
  }
  Serial.print(i);
}

Thanks for any help

There many variations of the modules you mention. Please post links to technical information on them. Your frizzy picture is not readable hence useless. Posting a schematic showing all connections would be a big help in getting your problem solved. Even a picture of a hand drawn schematic as you have it wired would be better. The Max chip is a very rugged device and will take a lot of abuse. Try this link for more information on it. https://www.maximintegrated.com/en/design/technical-documents/tutorials/7/763.html You state: "The MAX485LN modules are connected to each other as it should be. The First and the last module has a resistor of 100 ohm between the A and B ports.", are you sure?

Only the last module should have a 120 R resistor between A & B port. The transmitter shouldn't have one. If you are using a bi-directional bus, there shouldn't be any. Those units probably have a 120 R resistor on them already, and you should remove that.
Also the Max485's do not actually share common ground. The transmitter connects to GND but only for shielding, it does not need to be connected to the receiver.

No. Ground is ground.

No, but i would verify that there is a fly-back diode on the 20v rail (and every individual motor), to prevent spikes.
The 'burning out is probably caused by a lack of resistance between the A & B pins of the max485 (if they have truly 'burned out' that is)

Hi Deva,
Thanks for your attention.
Yes I found out yesterday evening, that the MAX485 modules have already a 120R resistor between A & B port. Called R7.
I will remove it for the modules in between.

I will also remove the common GND between the Arduino's (via the MAX485).

In the past I had just 3 Max485 modules connected. And had never problems with the communication.
Recently I added a 4th and last month a 5th one in the chain. And then there where issues with the data transmitted.
But I never removed one of the R7 resistors on any Max485 module.
Is it possible that the resistance is accumulated and that at the sama voltage the Amp becomes to high and the Max485 burns up. (Sorry I probably don't use the correct words in the last sentence)

What do you think?

Yes the MAX485 modules are connected via a twisted pair Cable.

I found also out that the Module itself has a 120 R resistor between A & B ports. R7.

I found on this site RS485 Pinout following picture

That’s the way I connected the MAX485 Modules with each other

Yes the designer / manufacturer of the PCB has made a goof, and as far as i can tell they made a lot of those units.
R7 should be removed for all units, with the exception of the slave farthest away from the master. It should be removed for the master as well. And there is no harm in removing it from all slaves (including the last)
The terminator can be added at the end of the chain, which also explains it's name.
The transceiver in drive mode creates a voltage difference between A & B, the twisted pair counteracts the effect of capacitance of the cable with the magnetic effect of the coil. In receive mode it measures the potential difference between the 2 inputs. Putting a terminator on the transmitter is a huge reduction of the potential difference on the cable pair.

Well the resistors are in parallel between A & B, so 1 / R total = 1 / (R1 + R2 + Rn etc) so with 4 x 120R you will actually only have 30R resistance. That can burn out the unit.

Yep looks fine, technically speaking the GND does not need to be connected to the slaves.
RS485 is meant for devices which are far apart and / or powered from a different source.
At 250Kbps you can cover a distance up to 300m

Hi again,
While your were replying above, I went to my playground and start with removing of the R7 resistor.
Step by step, and each time I monitored the communication, and yes it keeps working.
So I left the first and the last one. But when I unplugged the 2nd, one connection pin was broken. So I have to fix it tomorrow. To late today.

I removed also the ground between all the Max485 PCB’s.

One question: Is it necessary that the first one in the chain is the Master. In my case it’s the second one.
I think it doesn’t matter.

  • the master is sending and waiting for response
  • the slaves are listening and sending a response if the message was for them.

No it doesn't you're correct, never deal with 2 way systems myself. Mostly i deal with DMX, RDM is the 2 way variant, but is so rarely used. The total length of the cable is the length you use for calculating the maximum baud-rate, but normally that does not come into question.

I know it does. The terminator is in some way optional, (if you go for the 300m at 250kbps you should put one on the last slave probably, and when i use them to transfer 800KHz spi ws2811 signal i put one on the receiver of course) within the last months there have been many people on this forum seeking assistance with similar issues, who bought those same units. So many in fact that i think it may be easier to inform the vendors with customer feedback. So if you post the link of where you bought yours, i'll start on it.

I have blown up one off the arduino's and again a PCB MAX485.
So have to order some new parts before I can continue the expansion and testing....

How have you managed that ?

If I knew it, I should be happy.

Probably by disconnecting a GND connection.

But before I had fixed the connection to the PCB max485 of the master.
Every slave answered to the master except the last one in the chain.
This slave read the message and give a response, but the master don’t receive the response of slave 4.
For you understanding the chain is as follows

  • Slave 1 cable Length to master is 40 cm
  • Master cable length to slave 2 is 1 meter
  • Slave 2 to slave 3 is 4 meter
  • Slave 3 to slave 4 is 30 cm
  • Slave 4

Hi Deva_Rishi,
Can you help me how to add a fly-back diode.

Is it a Zener diode ?
How can I determine the specification for it and where should I put it in the circuit ?

I will add also a schema of the current circuit.

Thanks
Marc

No it's not a Zener-diode ! a Zener diode drains any excess voltage above it's rating and is mainly used in power-supply circuits.
A flyback diode is a diode is a diode where the cathode is connected to the v+ side of the power input, and the anode is connected to the GND. Under normal circumstances no current should flow through it. But a motor (and a relay for instance and some other parts that have a coil) that is switched 'off' from on can create reverse voltages and the fly-back diode is meant to prevent those reverse voltages from influencing any other electronic parts.
For smaller coils like relays usually a 1N4148 will suffice, but given that the motor is maybe a bit bigger, i would choose something like a 1N4007 for this situation. I have those diode types in my box(es) as general purpose diodes and they are easily available.
A fly-back diode should be placed as close to the motor as possible.

To detect a train on the rails I use also a module from Tams Elektronik GBM-1.
Circuit of this module:


With 1 module you can connect and monitor 4 train segments.
Pins: X2-1 till X2-4 are each connected to one right side off the 4 rail segments.
The left side off the rail is connected to power supply +.
X2-5 is connected to the power supply -.

In combination with the L298N the connection is different.


Out2 and Out4 are connected to X2-5
Out1 and Out3 are each connected to the left side of the Rail segments.
The power supply is in this situation connected to the L298n 12V and GND.

Now my question.
In the GBM-1 module there are already 2 diodes of type 1N4004 for each X2-1, -2, -3, -4 pin and the GND.
There is also a diode 1N4148 for each channel on the right side.
Is this sufficient or should also put a fly-back diode between the left side of the rail and the L298n out1/Out3?

GND of L298N is also connected to Arduino,

Create a single circuit schematic with the possible motors. I can't quite see it in my head.
Normally i would just put the fly-back on the motor and if there is some kind of rail switch. put it on that. If you put them on the board you will just need to check if there is a possibility of reverse current, and prevent that from getting to sensitive parts.

I will continue my story…

I bought a new Arduino, and replaced the Uno by a Mega version.
And again a set of 10 MAX485 boards.

First I created a test configuration with 3 Arduino nano and each connected to a MAX485 module.
I removed the R7 resistor of the Max485 module in the middle, first and last I left.
Test was successful.
Then I changed the module in the middle with an original Max485 with the R7 resistor.
Test was also successful
Cable between the modules is a twisted pair, no schield, off +/- 2meter.

But I think it’s important to code a serial write as follow:


  digitalWrite (ENABLE_PIN, HIGH);  // enable sending
  delay(2);
  sendMsg (fWrite, msg,  msg[3] + 4);
  Rs485.flush();
  digitalWrite (ENABLE_PIN, LOW);  // disable sending

So I can install the new Arduino and some new Max485 modules.

Config is as follows:

    1. nano with 2 L298 modules
    1. Mega with 4 L298 modules and master of the communication
    1. Nano with a RFID card reader
    1. Mega with 6 L298N modules

So I could removed the 5th Arduino, because the new Mega has more PWM ports.
I put also a new twisted pair cable between all the MAX485 modules. (Without shield)

After some testing and setting the right port in each Arduino, I succeeded to communicate without any error between all arduino’s and the Master.
At this moment Arduino’s are connected via an USB cable to my laptop. No power to the railway and pwm modules.

When I put in the power toothed railway and PWM itself, I got on the 4th Arduino, bad characters.
But only when there is no message on the Rs485 network.
At this moment no L298N module are connected to the mega where I get the bad characters.
After connecting the pwm’s, the bad characters are gone.

So I connect the other modules to this Mega, And Again bad characters on the serial input via Max485.

I think it becomes a never ending story.

well yeah make sure that the pin is high before starting to send. 2ms is a long time, but there is no need to hurry.
And make sure that the buffer is empty, and then you should probably add another delay. The buffer is empty, but the bits have not all been sent yet. There is 1 in FiFo and 1 on the output register.

Great, still R7 should not be on that unit, and not on both end points. That reduces the resistance between A & B which should be 120R (+ whatever is in the cable) and By adding more 120R resistors you go down to 40R at 3 resistors, that triples the current that flows thru the driver. At 5v logic that is 125mA . At some point the transceivers break, of course. Having 2 units in drive mode can be another cause of course.
Just to make it clear, no current has to flow thru the driver for it to work.

What do you mean, can you explain…

Well at any given moment, only 1 of the units on the bus should be transmitting and the others can only be Receive Enabled. If not than inverted polarity can occur between 2 units, on a bus that does not have a current limiter, that is not good.
The Transceiver inverts the polarity between A & B as logic LOW & HIGH
Basically there should be one unit that dictates the relaying of information, you don't want nodes sending at intervals unrequested.