Controlling a programmable PSU with RS232 cable

Hi everyone!

I have spent quite a portion of time troubleshooting my recent project, which involves having and arduino UNO controlling programmable PSU Rohde&Schwarz®HMP2020. However, I was not successful in establishing a communication with the supply whatsoever. I am using an RS232 cable, the connection being following:

Arduino ---RX,TX,5V,GND--->module with TTL to RS232 converter MAX3232 and a female RS232 port---RS232 cable---PSU.

The cable input: TX(pin 2),RX(pin 3),GND(pin5).
The cable output: TX(pin 2),RX(pin 3),GND(pin5), pins 1+6 to pin 4, pin 7 to pin 8.

The PSU uses SCPI commands in form of strings to set various configurations. I also set the PSU appropriately to RS232 interface, baud rate etc.

Code:

#include <SoftwareSerial.h>
#define rxpin 12
#define txpin 13
SoftwareSerial RS232(rxpin,txpin);
char character;

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

void loop() {

  if (Serial.available() > 0) {
      character = Serial.read();
  }
  if (character == "1") {
    RS232.println("*IDN?") // SCPI command to initialize connection with PSU
    RS232.println("INST OUT1"); //choose output
    RS232.println("VOLTAGE 5"); // Set voltage to 5V
  }

}

If I use a direct USB connection to PC and run the HMP program with terminal, the connection works. However, in my case it does not, and also when the cable is connected, the display of PSU stops working and the cooling runs a little louder, maybe this is a faulty soldering on my part, I will try to find out.

Even when I was using another cable, the communication could not be established. Please, any help will be greatly appreciated! Thanks!

A common mistake with RS232 is to forget to switch RX and TX. TX connects to RX and vice versa. your description suggests that you have TX to TX, which isn't going to work.

The following text appears on page 3 of the user manual.

"In general, there are exist two options for the RS-232 communication: with or without interface
handshake. If you are working without handshake you have to integrate appropriate delays
between the commands to make sure that all commands are executed correctly (approx. 50ms
to 100ms). Without handshake you can have the problem that the interface buffer can overflow
(e.g. missing commands). If you are working with interface handshake (set on both sides, HMP
and PC) you don‘t need to integrate delays."

Perhaps turn off handshake in the device and add delays between commands in your code.

wildbill:
A common mistake with RS232 is to forget to switch RX and TX. TX connects to RX and vice versa. your description suggests that you have TX to TX, which isn't going to work.

I did not think about that at all. I will try this as soon as possible, will update with the result. Thanks for pointing that out.

mikb55:
The following text appears on page 3 of the user manual.

"In general, there are exist two options for the RS-232 communication: with or without interface
handshake. If you are working without handshake you have to integrate appropriate delays
between the commands to make sure that all commands are executed correctly (approx. 50ms
to 100ms). Without handshake you can have the problem that the interface buffer can overflow
(e.g. missing commands). If you are working with interface handshake (set on both sides, HMP
and PC) you don‘t need to integrate delays."

Perhaps turn off handshake in the device and add delays between commands in your code.

I turned it off, but I will add that to my code. Thank you.

Besides that, is the code correct? The char =='1' means I will run multiple iterations from a VB app. If the microcontroller receives 1, the 1st sequence will run e.g. 5V 0.2A