Arduino Forum

Forum 2005-2010 (read only) => Hardware => Interfacing => Topic started by: Mavromatis on Sep 20, 2010, 05:43 am

Title: Serial Question -- TTL for RX and RS232 for TX
Post by: Mavromatis on Sep 20, 2010, 05:43 am
Hey guys... I have one for you!  

I'm trying to interface with a device and noticed that the serial RX signal is TTL.  So if plug in the RX and TX line into the Arduino and I get events.   Now, if I try to send something I can't because the TX line needs RS232 signal.  So if I plug the TX line into the RS232 TX driver I can send.

Here is the problem.   If I plug the TX line into the RS232 driver and leave the RX directly to the Arudino as TTL signal, I don't get any incoming events.  I can send fine but can't receive.   If I plug the RX and TX directly on the Arduino again I can receive but not send.  Once I remove the TX from the Arduino it floats and I start getting a bunch of 0's and noise.  Do I need some kind of pull up/down resistor to make this work with both.

I need a solution when I can keep the RX line connected to the serial RX on the Arduino and the TX line through a TTL to RS232 driver.   Any suggestions?
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: Mavromatis on Sep 20, 2010, 06:42 am
Hi Richard,

Not sure how much more I can describe.  But I'll try...

The incoming wires (tx/rx) come in via RJ45 Jack - don't have circuit detail of this device trying to figure out.  I took the blue wire which is the RX and plugged it into the Mega board serial 1 rx.  Connecting blue & white wire to tx pin on mega.  Writing a simple when serial.available loop receives data fine since the incoming data is TTL based.

If I remove the TX line... The rx signal seems to float because I get weird values coming in when there shouldn't be.   Problem is keeping the tx line connected to ttl doesn't work because it needs rs232 signal.  So if I plug the tx line into a TTL to rs232 converter (max232) it can send data however keeping the rx plugged into the arduino I no longer receive.

Does that help more?
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: Grumpy_Mike on Sep 20, 2010, 12:02 pm
I think you are confused over what needs what. If you have an RS232 device you will need to convert it to TTL both on the RX and the TX.  Not only is there a voltage change but also a logic inversion. You can plus an RS232 output into an arduino input and appear to get something. However that something will be rubbish and also will be over stressing the output.
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: mpeuser on Sep 20, 2010, 12:31 pm
By inference:
- As the RCV works fine, there is no level inversion.
- As there is no magic smoke, it is most likely 5V
- The needed connection to TX indicates an ad-hoc ground to low-level.
This will be disturbed by sending characters, with the reported results.
- As Mike and Richard pointed out, there is no such thing receiving with one level and sending with another.
Also the unusual connector is an indicator for non-RS232.

So simply find out what line is ground, and connect it correctly.
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: Grumpy_Mike on Sep 20, 2010, 03:31 pm
Quote
- As there is no magic smoke, it is most likely 5V


There have been quite a few cases reported here where people have connected an RS232 TX directly to the arduino's input. The result is they think the characters being received are strange.

No smoke issues and it works when they feed it the right voltage the right way up. It looks like something is saving them from their errors but I don't know what.
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: Mavromatis on Sep 20, 2010, 04:06 pm
There really is no magic here...  I'm trying to figure out a proprietary communication protocol.   The model is that you can loop in and out essentially allowing unlimited devices to share the "serial" data.   So keeping the rx as TTL 5v makes sense as the receeving devices can Listen and the tx line makes sense being rs232 signal because having a buffer is important. I never said this is a regular rs232 or ttl device... If that were the case I would have had it working.

As I stated, I did not connect anything I have not posted about.  I simply use a prebuilt ttl to rs232 converter. For the tx side which is powered and connected to gnd on the arduino.  The device is not connected to gnd of the ardunio.

I did not connect gnd.  That could be my problem.  I'll test and report back.
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: mpeuser on Sep 20, 2010, 04:59 pm
Quote
The amazing part at this point is that you got this far without the grounds connected together.

Not really... He needed the - as I called it - "ad-hoc" ground from the RX low pin of the Arduino.
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: mpeuser on Sep 20, 2010, 05:04 pm
Quote
So keeping the rx as TTL 5v makes sense as the receeving devices can Listen and the tx line makes sense being rs232 signal because having a buffer is important.

This still makes little sense to me.
You have three ingredients here:
* 0/5V vs. +/- 15V
* Signals inverted vs. signals proper
* Push/pull vs. Open Collector

Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: Mavromatis on Sep 20, 2010, 06:22 pm
This is how I currently have it connected:

RX TEST: When plugged in as follows I get correct RX values but cannot send
--
RX PIN FROM DEVICE > MEGA RX1  (confirmed this is TTL 5v signal)
TX PIN FROM DEVICE > MEGA TX1  (confirmed this is RS232 as the device responds when I send data to it)
GND PIN FROM DEVICE > MEGA GND (which seems to not affect anything when plugged in)
--

TX TEST: When plugged in as follows I can TX correctly but cannot receive
--
RX PIN FROM DEVICE > MEGA RX1  (confirmed this is TTL 5v signal)
MEGA TX1 > TX INPUT OF RS232 Shield (MAX232) > TX PIN OF DEVICE TO PIN 2 OF DB9  
GND PIN FROM DEVICE > MEGA GND (which seems to not affect anything when plugged in)
--

Also note:
- If I remove the TX PIN FROM DEVICE (PIN 2 OF DB9) signal floats and I get a bunch of weird data

So my only option is to add some switching circuitry (transistor) to make it so when sending I switch to the RS232 driver and when done, I switch back to the TX1 Pin of the Mega.   I wonder if that is by design so the device can only send or receive but not both at the same time?   Not 100% sure because I don't have their design, but it seems like the only logical method to make this work.  Unless you guys see something I may be missing...
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: Mavromatis on Sep 20, 2010, 07:31 pm
Richard,

I appreciate all your help and feedback on this however, you are assuming I have the source design!  I have said it numerous times that I do not have the source schematic diagram so I am running blind here.   I am trying to FIGURE OUT what they are doing.   I cannot get access to the schematic or port details so I'm trying to figure it out.

That being said, you don't need to worry about DB9 and RJ45 ... just what is coming from them.   I have connected every other wire coming from the device and the GND does not affect anything, thus my conclusion that they are doing something unorthodox given the mixing of TTL and RS232 hence a "proprietary connection".

The only thing I have that are KNOWNS are exactly what I have written:
- RX from device is TTL
- TX to device is RS232
- Connecting the RX and TX wires to Arduino Serial receives data perfectly (but cannot send)
- Removing the TX wire causes RX signal to float (as you asked why do I connect the TX when testing RX -- this is why)
- Connecting device "GND" does nothing
- Connecting the TX line into RS232 driver (TX pin 2 on RS232 shield) sends data perfectly however cannot receive anything via TTL when connected.

That is all I have... there is no schematic diagram unless you want the Arduino and/or the RS232 shield which is available here: http://www.cutedigi.com/pub/Arduino/arduino_RS232.pdf ... I'm just plugging wires from the source device via trial and error and have found everything I need -- RX and TX the problem is I cannot use both at the same time -- could be by design, hence my question to people with more experience.  I just used my troubleshooting skills to come up with this.

Again, I do not have the source schematic, I repeat, I do not have the source schematic thus I'm trying to figure it out.   I think I'm almost there... however, doing a switching model is not ideal, I'd like to just be able to use RX and TX at the same time.  
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: Mavromatis on Sep 20, 2010, 08:04 pm
Quote
Frankly, I don't think you have the RX, TX, and GND identified properly from the mystery source device. I'd bet even money that you have GND confused with either TX or RX.


Could be the case, I will look at this again!  

Since I'm dealing with a "Proprietary Connection" (not Apple or MSFT -- I am the first one to do this based on the company) I'd rather not disclose the device as I'm also trying to go down the legit path of obtaining the details.   I'm asking here on the basis of understanding what could be causing the issue.  

Any way to detect this besides just plugging wires and testing like I did?  What are the best tools to do this?
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: Mavromatis on Sep 20, 2010, 08:12 pm
Quote
1) "Just plugging in wires" is a dangerous method. You are lucky you haven't destroyed the serial interface of the mystery box.
2) What is powering the mystery box?  Are there any other electrical connections to it?  Specifically, is there anything that might be GND?  Use your meter and try to see which wire seems to be connected to GND.
3) Can you look inside the mystery box? Can you trace the wires back to whatever chip they are using to drive the serial port?


1) Yes I know, but I'm a professional ;)
2) I've determined it is ground by the basis of the color coding used on other devices used with the system and connection - however, i will dig deeper
3) Yes, that is my next step, was taking the lazy route of not having to take another device apart.  I felt like I got close enough -- maybe I was wrong.  :-/
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: mpeuser on Sep 20, 2010, 08:14 pm
Quote
Any way to detect this besides just plugging wires and testing like I did?

But did you? There have been three wires to be identified.
(1) Ground. This device must be powered somehow. Ground should show a stable 0V WRT the power supply ground.
(2) Transmit (from the point of that device) That can be toggling, it depends on the activity of the device. As you said you have already received somthing useful, this is easy!
(3) Receive (from the point of that device) That is  (can be) a high impedance input. It should NOT read 0V but some100 milivolts. You can further check be pulling it up and down with a 10k resistor, and you should have 0V and 5V there.

Note: Those hints base on the assumption that there is no RS232 interface involved.
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: Mavromatis on Sep 20, 2010, 08:19 pm
Quote
But did you? There have been three wires to be identified.
(1) Ground. This device must be powered somehow. Ground should show a stable 0V WRT the power supply ground.
(2) Transmit (from the point of that device) That can be toggling, it depends on the activity of the device. As you said you have already received somthing useful, this is easy!
(3) Receive (from the point of that device) That is a (can be) a high impedance input. It should NOT read 0V but some100 milivolts. You can further check be pulling it up and down with a 10k resistor, and you should have 0V and 5V there.

Note: Those hints base on the assumption that there is no RS232 interface involved.


1) Ground - I will verify GND for sure -- this is my next task.   I only have 8 wires to check... probing another device revealed that only 3 pins were actually connected to the RJ45 to traces.
2) TX (from the point of device) works stable only when RX from device is also plugged into the Arduino serial. (as stated before)
3) RX (from the point of the device) -- this is the real unknown.  I have successfully sent a command only when sending it RS232 signal from the Ardunio.  Sending TTL directly does nothing.
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: Mavromatis on Sep 20, 2010, 08:49 pm
Also, why do you guys think that a Half-duplex model would not be a possible source design for RX/TX? Could it be that bringing Arduino TX LOW sets the receiver in source device to RX mode and TX HIGH in TX mode?  Maybe that is by design of the source device to keep an endless loop from potentially happening and keeping a device from sending data while receiving, etc.?  Reason why I thought of this is because data lines can be daisy-chained and a half-duplex model seems more fitting. Just a thought.
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: Mavromatis on Sep 22, 2010, 04:22 am
Well... took a device apart... looks like they are using a MAX3082 (RS422) driver... no clue why it's working.  guess because it has failsafes (http://www.maxim-ic.com/datasheet/index.mvp/id/1522)

Also, the MAX3082/MAX3085/MAX3088 are intended for halfduplex communications....

These devices feature fail-safe circuitry, which guarantees a logic-high receiver output when the receiver inputs are open or shorted. This means that the receiver output will be a logic high if all transmitters on a terminated bus are disabled (high impedance).
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: Mavromatis on Sep 22, 2010, 04:33 am
Still unclear why it works using TTL and RS232 but I'll stick with RS422 to keep things "in spec".
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: Mavromatis on Sep 22, 2010, 06:12 am
Agree.  Just ordered some more parts... I'll report back how it turns out.   Thanks again!
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: RockStar on Sep 22, 2010, 08:49 am
Agree with that
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: Mavromatis on Sep 28, 2010, 06:57 am
Got it working with rs422... Thanks.
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: yashar on Jan 21, 2011, 10:02 am
Hi,

I have got a USB to Serial (TTL)  module, Can I use this TTL module to write and read from Arduino Board in serial mode ?

Thanks in advance for your help.
Yashar
Title: Re: Serial Question -- TTL for RX and RS232 for TX
Post by: retrolefty on Jan 21, 2011, 10:51 am
Quote
But Half-duplex went out of style with the old mechanical telegraph before any of us were born.


Half-duplex communications links lived well past the mechanical telegraph age, on to the magic age of electro-mechanical teletype machines, then on to the wonderful world of time-shared computing.

I worked on many half-duplex serial loops using both 20ma and 60ma current loop and RS-232 voltage levels, up until the mid 70s.

In that era if you needed to have a cost effective communications link between two nodes too far to run your own cable, or off your property, you leased a private datalink from the phone company or possibly western union. Cost for a single wire pair link was less then for a two wire pair (go figure!) so if cost were a factor, you would lease the single pair and run the modems in half duplex mode.

110 to 1200 baud were common speeds, but with higher cost 'equalized' lines (cost more!) one could make it up to 9600 baud with proper modems. Which by the way in the early 70s, a 9600 baud modem, if purchased would set your back around $10,000+ (adjust that to today's dollars!), and it was the size of desk top PC laid on it's side, usually rack mounted.

And even back then we were converting current loop and RS-232 links to and from TTL voltage levels, some things don't change!

[edit]What cost $10000 in 1970 would cost $54639.18 in 2009.[/edit]

Yes, I'm old, and yes my lawn is off limits.