Serial rx/tx port setting

Hi all,

Is there any way to change the Rx and Tx ports used for the HardwareSerial? Effectively, I have to DTE devices that need to talk to each other - but I don't have a null modem handy. I figure that if I can get my Arduino to reverse these two pins (Rx on 0, Tx on 1), I won't need it.

One option is to use SoftwareSerial, in which you can allocate any ports, but I'd like to use the built-in USART if possible..

Is this possible?

You can just hook the RX from one side up to TX on the other. What devices do you need to link and what sort of ends do they have?

I have to DTE devices

Lets back up. Is that TWO DTE devices that need to talk to each other? Are they using RS-232 voltages or TTL voltages? What kind of connector is each device using (number of pins, male or female) ?

Is an Arduino required for some logic to perform on the data to pass between the two devices?

Lefty

Aw yeah, I could wire Rx to Tx and effectively build myself a null modem, but I was hoping to do it in software. The reason for this is that I've a load of nice 9-pin D-Subs that all plug into each other nicely and I'd prefer to use them over a mess of a wiring job that I'd do :slight_smile:

Is that TWO DTE devices that need to talk to each other?

I may have the terminology wrong, but I think this is the situation

Are they using RS-232 voltages or TTL voltages?

+/- 12v RS232 ones. Actually, this is a good reason for not using SoftwareSerial, as I haven't any voltage shifters around..

What kind of connector is each device using (number of pins, male or female) ?

Both my Arduino board and the phone I want to connect it to have a female 9-pin DSub. I have a gender changer but this dosen't invert the signals. Both devices happily talk to my PC (male 9-pin DSub).

Well it seems to be a little overkill to use an Arduino to just function as a null modem. Plus as you said you will need to deal with voltage and logic level conversion issues.

Just build a null modem with two of your connectors and a short piece of cable.

Lefty

Oh, sorry, I was unclear. I'm not looking to use the Arduino only as a null modem - that would be overkill indeed!

I guess my question was more, "I need a null modem between these two DCE devices; I could do it with a cable, but perhaps there's an easy way to do it in software. Can I swap the Rx and Tx pins used by the HardwareSerial interface in software to quick-and-easily make the Arduino into a DTE device?"

I tried wiring up a crossover cable but mysteriously it didn't work. Probably bad soldering - I'm rubbish at that. I was crossing Rx and Tx while letting GND straight through - I gather that'll suffice? RTS and CTS are optional, no?

Is that TWO DTE devices that need to talk to each other?

I may have the terminology wrong, but I think this is the situation

No, I lie, both the Arduino and the phone are DCE devices. Same problem though.

Can I swap the Rx and Tx pins used by the HardwareSerial interface in software to quick-and-easily make the Arduino into a DTE device?"

In short no. Not in software any way.
These pins have defined hardware functions inside the chip and are not assignable. You would have to use software serial to do that sort of thing.

Cheers Mike.

I think a trip down to Maplins's null modem aisle is in order then!

both the Arduino and the phone are DCE devices

Yes we have a terminology problem here. An Arduino is neither a DCE nor a DTE device, it's just a TTL compatible serial port using two I/O pins. The Arduino pin numbers used are fixed for the hardware serial port or user defined if using a softserial library routines.

What determines a node being a DTE or DCE node is which RS-232 signal pins it outputs on and what signals pins it inputs on (used in either 9 pin or 25 pin type D connectors.

Either way for a RS-232 DTE or DCE device to interface directly with a Arduino serial port you have to deal with the voltage differences between RS-232 and TTL signal levels and you have to deal with the logic inversion needed for send and receive, but RS-232 control signals (DTE, RTS, etc, if the device requires any control signals) do not require logic inversion but still require voltage conversion.

So we are going to have to know specifically what the two devices you want to use with your Arduino are using for their electrical signaling levels (connector type, pin numbers used, what pins are inputs and which are outputs, and voltage levels used) if we are going to really be able to help you.

Lefty

Ah, thanks for the explanation. I though the difference between the two was the pin allocation for Rx, Tx, RTS and CTS - naturally, these will have to vary depending on if you're receiving data or sending it. I called my Arduino a "DCE" as I expected my PC was a "DTE" and these two devices would happily talk to each other (for the voltage levels, I've a Max232 performing level shifting and inversion).

I think you and Mike answered my question though - the pins are hard coded, which means any needed crossover needs to be done "externally" to the Arduino.

The two devices are:

  • Arduino, going via MAX232. Female DB9
  • Phone (M55), going via data cable, Female DB9

Both hook up to my PC (Male DB9). I've not measured the voltage levels but I assume everything is happily running at +-12V.

I though the difference between the two was the pin allocation for Rx, Tx, RTS and CTS -

It is, on the RS-232 connector only, The DTE/DCE definition is defined by what pins are inputs and outputs back to the devices on the other end of the connector. But has nothing to do with the Arduino I/O connections and voltage levels. All wiring and voltage conversions to the Arduino I/O pins have to be done via hardwiring wiring and voltage conversion (typically using a MAX232 type chip).

An exception of this is if you have an older Arduino type board (or clone like this one: http://www.nkcelectronics.com/freeduino-serial-v20-board-kit-arduino-diecimila-compatib20.html ) that uses a RS-232 serial connection for connecting to the PC for downloading, etc. These older boards have a MAX232 type chip or other components on board, rather then a USB serial chip as the newer boards do. In that case the Arduino would be considered a true DCE device.

I think you have a good handle on what you have to do to proceed. If not make some electrical drawings up and post them here. Also be sure to let us know what model Arduino you have, USB or RS-232.

Good luck
Lefty