Please assist in Interfacing Rs232 to ttl converter with arduino mega to livestream data i am not getting any feed back

Code
#include <SoftwareSerial.h>
const int txPin = 1; // TX pin on the MAX3232 module
const int rxPin = 0; // RX pin on the MAX3232 module
SoftwareSerial mySerial(txPin, rxPin);
void setup() {
Serial.begin(38400); // Set the baud rate to 38400
mySerial.begin(38400); // Set the baud rate for the MAX3232 module}
void loop() { if (mySerial.available() > 0) {
char c = mySerial.read();
Serial.write(c); }}

Hardware used
-Arduino Mega2560
-Rs232 to TTL module using Max3232(Tx on pin 1,Rx on pin 0, vcc 3.5)
-IDE 1.8.19
-1M rs232 cable from master to rs232to ttl converter module

Data Format and required set up

RS-232 communication settings
The serial interface is according to RS-232C and fulfills the following requirements:
Baud rate: 38 400 ,Data length:8 bits ,Stop bits: 1,Parity: Even ,Data format:Binary ,Handshake: None

Command/Response format
SCI commands are always in ASCII format, unless stated otherwise. The response can be in either ASCII or binary format, as specified per command.

solated RS-232 serial ports. 9 pin D-Sub female connector: output from master

  1. – ,2. RXD_ISO ,3. TXD_ISO ,4. DTR_ISO ,5. GND_ISO ,6. – ,7. RTS_ISO ,8. – ,9. –
    Note that DTR_ISO and RTS_ISO are permanetly high (active).

*Signal Handshake protocol *
The following control characters are used, in order to control the data flow from the SCI:
= 0416 :End of transmission. General character to be used to define the end of an instruction or end of an ASCII response from the SCI. Note: An ASCII string is not null terminated.
= 1B16 :Issued by the computer to interrupt the data transfer from the SCI. Upon reception of ESC, SCI aborts transmission and any running command, e.g. RADC, and sends the error message “Command aborted by ESC”. Transmission is restarted upon reception of the next valid command.
:Calculated checksum. Checksum is sent either as one byte or two bytes; one byte in binary answer or two bytes in ASCII answer.

Performance requirements
The SCI needs to receive any character within set timeout, otherwise the previous characters are ignored.

Support for different SCI Protocol versions
The SCI provides a mechanism for selecting between different protocol versions. The following commands are
used:
• Read Highest Protocol Version, RHVE: Requests information about the highest available SCI Protocol version
for the current System SW version.
• Read Protocol Version, RPVE: Requests information about the SCI Protocol version currently in use.
• Set Protocol Version, SPVE: Configures SCI to use a specific Protocol version.
The lowest selectable protocol version is SCI Protocol version 0001. This protocol version is selected at startup
and when the RCTY command is received.
The difference between protocol versions are that:
• Existing channels can be deleted
• New channels can be added
• The configuration, or switch parameters, for existing channels can be changed
• New commands can be added.

Design/compatibility considerations for driver developers
Command RCCO, shall be used to get the list with actual channels and corresponding
configurations.Use code tags to format code for the forum

please assist i am not getting any feedback is there anything i am missing

  1. Use pins other than 0 and 1 for SoftwareSerial.
  2. Don't use SoftwareSerial with a 'Mega'. Use one of its harware hardware UARTs.
  3. reserved

That is 11 bits per character. Software serial will not do that. Only 10 bits, NO parity.

Please edit your post, select all code and click the <code/> button to apply code tags. Code tags make your code easier to read, easier to copy and the forum software will display it properly.

Check if the following setup (Fig-1) is helpful for you.


Figure-1:

type or paste code here

try this code which uses Mega hardware Serial1

// Arduino Mega serial1 test

// mega Serial1 pin 18 is TX1
//      Serial1 pin 19 is RX1
// for loopback test connect pin 18 to pin 19

// for RS232 shield connect
// Mega pin 18 TX1 to TTL/RS232 Tx
// Mega pin 19 RX1 to TTL/RS232 Rx
// for loopback test connect 9-pin D_type connector pins 2 Tx to 3 Rx (pin 5 is GND)
// connect GND pins together and VCC to 5V

void setup() {
  Serial.begin(115200);     // initialise serial monitor port
  Serial1.begin(9600);//115200);    // initialise Serial1
  Serial.write("Arduino Mega Serial1 test -  for loopback test connect pin 18 to pin 19\n");
  Serial.write("RS232: Mega pin 18 TX1 to TTL/RS232 Tx and pin 19 RX1 to TTL/RS232 Rx\n");
  Serial.write("RS232 - loopback connect 9-pin D-type pin 2 Tx to pin 3 Rx\n");
}


void loop() {
  if (Serial1.available()) {  // read from Serial1 output to Serial
    Serial.write(Serial1.read());
  }
  if (Serial.available()) {  // read from Serial outut to Serial1
    char inByte = Serial.read();
    //Serial.write(inByte);     // local echo if required
    Serial1.write(inByte);
  }
}

you can test the Serial1 by connecting pins 18 and 19 to form a loopback - text entered on serial monitor keyboard is echoed by to the display
if that works connect the TTL-RS232 module as indicated by @GolamMostafa, e.g.

// Mega pin 18 TX1 to TTL/RS232 Tx
// Mega pin 19 RX1 to TTL/RS232 Rx

you can then test the module by connecting pins 2 and 3 of the 9pin Dtype connector to form a loopback test
example output Serial1 connected to TTL-RS232 mudule connected to Quectel EC21 modem

at
OK
at+cgmi
Quectel
OK
at+cgmm
EC21
OK
at+csq
+CSQ: 20,99
OKOK
at+cimi
+CME ERROR: 3

at_cimi fails because a SIM is not fitted

And … if not mentioned ( only scanned the replies ) Tx connects to Rx and Rx to Tx.

As @Horac says …Always try stuff like the loop back test , so you can find the source of any issues , rather than find it doesn’t work when it’s finished .

Thank you ... for you're feedback
However i am still not getting any feedback....

I have use the code provided by @horace and connection provided by @GolamMostafa

I have set/adjusted the baudrate to 38400 for serial1 on the code ...

I do get feedback when testing loopback ,so all the test loop test provided by @horace they work properly (by echoing data sent from the keypad)

But when i connect the rs232 cable to the device(medical ventilator) i am not getting any data or feedback...

The data requirements i have shared on this post is from the ventilator manufacturer ... unfortunately as a new user i cannot attach attachments as i was trying to attach communication protocol requirements pdf....

Not unless if i am missing something

You can when you get to trust level 1.

Get to trust level 1 by…

  • Entering at least 5 topics
  • Reading at least 30 posts
  • Spend a total of 10 minutes reading posts

... and you've read 28 posts already.

if you have a multimeter try checking the voltages on the 9pin Dtype connector
voltages -6 to -12V logical 1 - +6 to +12V logical 0 - idle state is logical 1 (-6 to -12V)

9pin D-type female connector pin 2 Tx, pin 3 Rx and pin 5 is GND (the pins are usually numbered but difficult to read)
image

disconnect the devices and check the Tx voltages are -6 to -12V when idle
the RX signal is usually 0volts when not connected

0927petter,
Welcome to trust level 1. You are able to post attachments now.

1 Like

You need to go step-by-step.

1. Connect RS232<----->TTL converter with MEGA as per Fig-1 of post #6. Short TX-RX at the 9-hole side of the converter.

2. Upload the following sketch (not tested) to verify that the converter is working.

void setup()
{
    Serial.begin(9600);
    Serial1.begin(9600);
}

void loop()
{
    Serial1.print('A');
    byte n = Serial1.available();
    if (n != 0)
    {
           char ch = Serial1.read();
           Serial.println(ch);
    }
    delay(1000);
}

3. Check that the Serial Monitor show A at 1-sec interval.

4. Collect Reference Manual of your UART device that you want to connect with MEGA via the converter module.

5. From the Reference Manual of Step-4, find the UART Protocol and post in this thread.

how have you wired the Mega TTL-RS232 9pin Dtype connector to the external RS232 device?
what type of the connector does the external device have? a female 9pin Dtype?
if it is wired as the female 9pin Dtype shown in post 13 you require cross over connections

1. external RS232 GND pin 5 to TTL-RS232 GND pin 5
2. external RS232  TX pin 2 to TTL-RS232 Rx pin 3
3. external RS232  Rx pin 3 to TTL-RS232 Tx pin 2

e.g. Quectel Mini PCIe EVB Kit connected to a UNO via a TTL-RS232 module
image

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.