Communication problem using RS232

hi there

I want to control a UPS device using its Rs232 port via Arduino. I am doing this using MAX3232.

When I connect the UPS directly with my PC and send serial commands using a terminal software, the UPS responds very well. One of the basic command is just a 0x0d character. However, when I send the same command using arduino, the UPS fails to respond. I tested the output of arduino by connecting its DB9 connector to the PC, and found that it sends all commands correctly without any illegal character. The settings on the PC terminal are 2400 baud with data size 8, parity none, handshake off. With these settings, the PC communicates with PC and when connects to the arduino, does the same. However, arduino when connected directly to the UPS, fails.

What could be the other reason that is not coming to my mind here?

Here is the software code programmed in the arduino:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(6, 7); // RX, TX
void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Serial.println("Starting!");

  mySerial.begin(2400);
  mySerial.write(0x0d);

  delay(1000);
  if (mySerial.isListening()) {
   Serial.println("Port One is listening!");
  }
}

void loop() // run over and over
{
  while (mySerial.available() <= 0) {
    mySerial.write(0x0d);
    Serial.println("Sent");
    delay(5000);
  }

  if (mySerial.available())
  {
    Serial.write(mySerial.read());
  }
  if (Serial.available())
    mySerial.write(Serial.read());

  if (mySerial.overflow()) {
    Serial.println("Overflow ...");
  }
}

Please help .. thanks

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

What are the specs of the device? (voltage etc)

did you connect the grounds Arduino/UPS so there is a shared reference?

well, the ground is connected thru DB9 connector and UPS device and Arduino are sharing it ... the connector has 3 pins ... one GND and other is Rx and Tx.
I dont know what voltages the UPS produces on the DB9 connector ..
Should I test the Arduino --> Max3232 output using Loop back method to see if it is sending the right bytes ?

I dont know what voltages the UPS produces on the DB9 connector ..

do you have a voltmeter, even the cheap 5$ ones are good enough to protect you against overload!

I have a voltmeter :slight_smile:
I have checked the volts at UPS DB9 connector ... at pin 2 .. its -14.8v, at pin 3 almost zero ...

well finally I got the success ... I attached the pin14 and pin13 of Max3232 to pin3 and pin2 of DB9 respectively ... previously they were other way round ... thats the reason the arduino was communicating well with the PC but not with the UPS device ...

all the circuit diagrams listed on the internet are actually designed to communicate Arduino with PC. I was following: avrprogrammers.com -. My mistake was that the pin connections from Arduino to DB9 were that for PC.

Another problem is that the UPS sends 164 byte data while Arduino is unable to read data beyond 64 bytes ... i think arduino needs some adjustments in the buffer size ...

Thank you everybody for help ..