RS-485 test on M-Duino PLUS version
2 January, 2019 by
RS-485 test on M-Duino PLUS version
Alejandro Jabalquinto


Introduction


In this post it is showed how to test the RS-485 on M-Duino PLUS version.

The first thing that you need to know is that the  RS-485 PLUS version have Full and Half-Duplex communication. Controlling the dip switch, you must select if you want to work on Full or Half-Duplex. There is internally installed a Half duplex MAX485 and MAX485 transmitter. If you are working on Full-Duplex you will use the MAX485 Half-Duplex to receive data and MAX485 transmitter to send the data.

The pin mapping is showed below:

Max485Arduino Pins
RX (RO)RX Serial3 (15)
TX (DI)TX Serial3 (14)
RE (inverted logic)11
DE46

 

Requirements 

Configuration

To do the Full-Duplex test, you must connect the A, B (receivers) to the Y, X(transmitters). For Half-Duplex, you must connect with another device with RS-485 and select if you want to transmit or receive data with comment or uncomment “#define” command:

In Half-Duplex sketch:

  • For transmitting:

#define TEST_RS485_TX
//#define TEST_RS485_RX
  • For receiving:

//#define TEST_RS485_TX
#define TEST_RS485_RX


Software

Next it is showed the test sketch for Half-Duplex: 

(by default it is in transmitter mode)

#define TEST_RS485_TX
//#define TEST_RS485_RX
 
int _rs485DE = 46;
int _rs485RE = 11;

///////////////////////////////////////////////////////////////////////////////
void setup() {
  Serial.begin(9600L);
  Serial.println("M-Duino PLUS RS-485 test started");
  
  Serial3.begin(9600L);
  pinMode(_rs485RE, OUTPUT);
  digitalWrite(_rs485RE, LOW);
  pinMode(_rs485DE, OUTPUT);
  digitalWrite(_rs485DE, LOW);
}
//////////////////////////////////////////////////////////////////////////////
void loop() {

#if defined TEST_RS485_TX
  digitalWrite(_rs485RE, HIGH);
  digitalWrite(_rs485DE, HIGH);
  Serial3.write(0x12);
  Serial3.flush();
  digitalWrite(_rs485DE, LOW);
  digitalWrite(_rs485RE, LOW);
  delay(1000);
#endif // TEST_RS485_TX

#if defined TEST_RS485_RX
  if (Serial3.available()) {
    if (Serial3.read() == 0x12) {
      Serial.println("RX");
    }
   }
#endif // TEST_RS485_RX
}

 

Next it is showed the test sketch for Full-Duplex:

int _rs485DE = 46;
int _rs485RE = 11;

///////////////////////////////////////////////////////////////////////////////
void setup() {
  Serial.begin(9600L);
  Serial.println("M-Duino PLUS RS-485 test started");
  
  Serial3.begin(9600L);
  pinMode(_rs485RE, OUTPUT);
  digitalWrite(_rs485RE, LOW);
  pinMode(_rs485DE, OUTPUT);
  digitalWrite(_rs485DE, LOW);
}
//////////////////////////////////////////////////////////////////////////////
void loop() {
  digitalWrite(_rs485RE, HIGH);
  digitalWrite(_rs485DE, HIGH);
  Serial3.write(0x12);
  Serial3.flush();
  digitalWrite(_rs485DE, LOW);
  digitalWrite(_rs485RE, LOW);
  delay(1000);

  if (Serial3.available()) {
    if (Serial3.read() == 0x12) {
      Serial.println("RX");
    }
   }
}


See also

M-Duino Family RS-485 Help Page

RS-485 test on M-Duino PLUS version
Alejandro Jabalquinto
2 January, 2019
Share this post
Archive

Looking for your ideal PLC?

Take a look at this product comparison with other industrial controllers Arduino-based.

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>

Do you want more information?

Just fill the form!

Tell me more!