Pages: [1]   Go Down
Author Topic: Communication problem using RS232  (Read 1151 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
#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: [code] [/code] tags added.
« Last Edit: August 29, 2013, 02:13:46 am by Coding Badly » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12430
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?

Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12430
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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!
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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: http://avrprogrammers.com/doc-max232-arduino.php. 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 ..
Logged

Pages: [1]   Go Up
Jump to: