|| Back to Support & Help Documentation ||

M-Duino RS-232

Serial Communication Standard

RS-232 protocol formally defines the signals connecting between DTE (Data Terminal Equipment) such as a computer terminal, and DCE (Data Circuit-terminating Equipment or Data Communication Equipment), such as a modem.

Our Arduino Based PLCs incorporate the integrated circuit MAX232.

MAX232 converts signals from to TIA-232 (RS-232) serial port to signals suitable for use in TTL-compatible digital logic circuits. The MAX232 is a dual transmitter / dual receiver that is used to convert the RX, TX, CTS, RTS signals.

MAX220, MAX232, MAX232A: Pin Configuration and Typical Operating Circuit 


MAX232 Pin Configuration and Typical Operating Circuit


Hardware

Check the M-Duino Family products now!

IMPORTANT: Make sure that your Ethernet PLC is powered (12-24Vdc).

Switch configuration 

For the RS-232 communication protocol there isn't any switch that affects it. So it does not matter the configuration of the switches to implement a RS-232 communication.

 

Used pins

For RS-232 communication protocol the defined Arduino Mega pins are showed in the chart below:


M-Duino Ethernet PLC pinoutArduino Mega pinout
TX16 (Serial2 TX)
RX17 (Serial2 RX)


You can access easily to RS-232 pins in our Ethernet PLCs, you can see their position in the following image:



Connections





Software

IMPORTANT: Make sure to download the Arduino based PLC boards for Arduino IDE.

Software Configuration

Once the hardware configuration is done, it's possible to proceed with the software configuration and also its usage. Firstable it's necessary to include the RS232.h library provided in our boards.

#include <RS232.h> 

Then don’t forget to implement the proper initialization of your communication on the setup() function:

 RS232.begin(9600);


RS-232 Library - Functions

* Remember that both devices have to communicate on the same baud rate. 

Now everything is ready to start using the RS232 functions or methods. RS232 is a class that can use the same methods than Serial class. Take a look on Arduino web site references to see the different available functions. The most used methods that every Industrial Shields developed has to know are:



RS232.begin(baud); //sets the baud rate for RS232 data transmision
RS232.read(); //reads incoming RS232 data
RS232.write(byteToSend); //write binary data to RS232 port
RS232.write(dataToSend, dataLength); //write binary data to RS232 port
RS232.available() //returns the number of bytes available for reading on RS232 port


 This is all it’s necessary to know to use RS232 on Industrial Shields equipment’s. Finally it is showed an example using RS232.

Example codes


Basic RS-232 write example:

// Include Industrial Shields libraries
#include <RS232.h>

//// IMPORTANT: check switches configuration

////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
  // Begin serial port
	Serial.begin(9600);

  // Begin RS232 port
  RS232.begin(38400);
}

////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
  // Wait bytes in the serial port
  if (Serial.available()) {
    byte tx = Serial.read();

    // Echo the byte to the serial port again
    Serial.write(tx);

    // And send it to the RS-232 port
    RS232.write(tx);
  }
}

 Basic RS-232 read example:

// Include Industrial Shields libraries
#include <RS232.h>

//// IMPORTANT: check switches configuration

////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
  // Begin serial port
	Serial.begin(9600);

  // Begin RS232 port
  RS232.begin(38400);
}

////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
  // Print received byte when available
  if (RS232.available()) {
    byte rx = RS232.read();

    // Hexadecimal representation
    Serial.print("HEX: ");
    Serial.print(rx, HEX);

    // Decimal representation
    Serial.print(", DEC: ");
    Serial.println(rx, DEC);
  }
}

By following these steps carefully, you will be able to achieve the use of the RS-232 protocol using the Industrial Shields equipments.


1 Star 2 Star 3 Star 4 Star 5 Star