PDA

View Full Version : RS232 level shifter circuit



dodger
03-20-2009, 07:06 AM
http://www.parallax.com/Portals/0/Images/SerialToPropeller.jpg (http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/SerialtoPropeller.pdf)

I am using this circuit to interface a serial device to my propeller.· I cant seem to send data though.· The device i am using does not have a DTR connection. So currently i have nothing connected to· RESn or DTR. Could this cause the propeller to·not transimit?·

Peter Jakacki
03-20-2009, 07:23 AM
This circuit was only ever suitable for programming the Prop but not as a general-purpose RS-232 interface. The reason is that the Prop tool holds the DTR line negative to provide a negative pull-down for the transmit transistor. However practically all communications software and terminals assert DTR positive when they are ready which means the TX line is always positive (break condition) and can never go negative (IDLE).

In your case however I suggest that you at least pull DTR down to Vss and hopefully this will work. Alternatively I would just use a 1K from pin 2 to 5 to do the same thing but achieve a stronger pull-down.

*Peter*

virtuPIC
03-20-2009, 08:47 PM
As Peter wrote, this circuit is only meant for bootloading the prop. For RS232 you need negative signal voltage which is here generated from the DTR signal - in the hope that the other side conforms to standard. If you don't have a DTR it won't work.

However, this circuit still looks a bit strange to me. connecting NPN transistors to negative BE / CE voltages... On the net you can find a number of level converter schematics. Or use a MAX3232 with a few caps for a clean implementation.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Airspace V - international hangar flying!
www.airspace-v.com/ggadgets (http://www.airspace-v.com/ggadgets) for tools & toys

dodger
03-24-2009, 06:42 AM
Im still having trouble transmitting anything from the prop to my device.· I was wondering it the 3.3v on the emiter of the 2N3906 should be higher.· I know that RS232 normally works on 12V.· So wouldnt i need to shift my prop serial level up to 12V?· I'm not too sure why this side of the circuit is not working properlly.· Any suggestions?

Beau Schwabe (Parallax)
03-24-2009, 07:01 AM
dodger, (http://forums.parallax.com/member.php?u=53687)

The circuit that you posted was derived from what is currently built into all the BS2 modules.· The DTR pin supplies a negative voltage via the 10K resistor.· If you omit the DTR connection to the PC serial port you will not be able to program the Propeller, but if you supply a negative voltage, you should at least be able to communicate via the serial port.· Simply connecting the pull-down to ground will not provide enough voltage potential for the PC to communicate.

One method to generate a negative voltage is to use a diode/capacitor off of the PC ports TX pin.· Again, you still won't be able to program the Propeller, but you should be able to establish serial communication.
·
·


Notice the capacitor polarity, the + side is on the Vss.

+
TX >----|<---o---||----> Vss
| 10uF
|
|
o--/\/\---> RX
10K


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

Peter Jakacki
03-24-2009, 08:01 AM
Beau,
The 1K resistor to ground is sufficient as the PC's RS-232 input circuit is only looking for a low of anything less than 1V or so. A stronger pull-down of 1K or less is needed to ensure that it pulls-down hard enough and fast enough. If he has indeed done this properly and it does not work, yet works with a negative voltage, then I will concede that you were right (in this instance anyway) :)

*Peter*

virtuPIC
03-24-2009, 01:39 PM
Okay. What about this one: picprojects.org.uk/projects/simpleSIO/ssio.htm (http://picprojects.org.uk/projects/simpleSIO/ssio.htm)? It generates the negative voltage necessary to transmit via RS232 from received signal. You might ask: What if both sides of the connection use such a circuit? Well, it would work anyway. You would get a 0 to VDD level signal since the most positive level transmitted 'negative' signals might have in this circuit is GND. Might be less noise resistant due to lower level difference but who cares about that anyway - if I am looking at serial line code...

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Airspace V - international hangar flying!
www.airspace-v.com/ggadgets (http://www.airspace-v.com/ggadgets) for tools & toys

Beau Schwabe (Parallax)
03-25-2009, 12:40 AM
virtuPIC,

That's the same thing that I suggested, only they used a different value resistor and a cap.

I have read several articles where most of them state....

"The RS232 physical specification gives a logic 1 at the receiver input as -3 to -25 volts and logic 0 as +3 to +25 volts."

...The region between -3V and 3V is usually stated as undefined, and some, not all, serial PC cards may not be able to deal with signals in this undefined range. Thus why creating a negative voltage usually solves the problem.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

Post Edited (Beau Schwabe (Parallax)) : 3/24/2009 5:46:32 PM GMT

Beau Schwabe (Parallax)
03-25-2009, 12:44 AM
dodger

What are the specs on your serial device?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

dodger
03-25-2009, 04:53 AM
Here is the specs from the manual.



RS-232-C

RS232 Transfer Protocol
Protocol Value
Cable 9 pin to miniplug.
Baud 9600
Parity None
Bits 8
S Bit 1

Flow None

RS232 Cable Pinouts
Pin # Description· Pin # Description
1 Unused··········· 6 Unused
2 Transmit········ 7 Unused
3 Receive········· 8 Unused
4 Unused··········· 9 Unused

5 Ground

Beau Schwabe (Parallax)
03-25-2009, 04:55 AM
dodger,

Hmm... Nothing that indicates any voltage thresholds?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

kwinn
03-25-2009, 07:50 AM
Beau, Dodger, the "RS232C" part of the spec indicates the thresholds voltages since they must be between +-3 to +-25V to be considered RS232C compliant. FYI, I have found that not all equipment that is supposed to be "RS232" will work at +-3V, but I have never had any problems at +-5V or higher.

dodger
03-28-2009, 12:40 PM
The addition of a cap and·resistor solved the problem. I can now send a character from my prop and it is recieved by my serial device.


Thanks for the help.·

Peter Jakacki
03-28-2009, 12:49 PM
Good, but what resistor and what cap and where?

Just curious as to why it wouldn't work and why it works now.

Remember dodger, the forum's 3 ways, the original poster, the respondents, and the lurkers (at least for the thread).

*Peter*

dodger
03-28-2009, 11:21 PM
I added the schematic that Baeu suggested (the post on 3/32 at 5:01 pm) to thel schematic in the original post. Baiscally a 10uF cap and 10k resistior. If's not to clear i can try to make an updated schematic of the complete circuit. This was also linked to me a few post up and is bascally the same circuit. http://picprojects.org.uk/projects/simpleSIO/ssio.htm

dodger
03-31-2009, 06:03 AM
Here is a combined schematic of what i used to interface my serial device.· Seems to work fine.. Its in an word file attatchment...



Post Edited (dodger) : 3/30/2009 11:15:37 PM GMT

Peter Jakacki
03-31-2009, 07:54 AM
Dodger,

I can't see how you get it to work as you misread Beau's diagram which needs a diode in there. It looks like he used a "---|<---" symbol for the diode which you might have missed.
If you copy his diagram and paste it into a Spin window it will look clearer.

Still, with the way you have wired it the capacitor directly across the TX will degrade the transmit signal terribly to the point that it can't work.

I still maintain that you only need a 1K resistor (not 10K) or less from the collector of the PNP to ground for it to work.

*Peter*

P.S. I mean the "TX" from the PC of course

Post Edited (Peter Jakacki) : 3/31/2009 1:07:52 AM GMT

stevovee
08-04-2013, 10:13 PM
I need to interface with a PC serial port but not for programming. Can I simply make a level shifter circuit for the RX and TX lines and then directly connect ground and be fine? I will be using this with different pins than 31 and 30 as this project will call for me to input from a pc serial port on two other pins and then output to usb (which i will do with an FTDI chip circuit on pins 31 and 30 as well as use this to program the chips)

stevovee
08-04-2013, 11:04 PM
Would it just be easier to use a MAX3232 to get the levels safe for my propeller.

kwinn
08-05-2013, 12:44 AM
Either way will work but a MAX3232 would be the more reliable way to go. It is pretty much guaranteed to work with any PC serial port.

PJ Allen
08-05-2013, 12:50 AM
...but a MAX3232 would be the more reliable way to go. It is pretty much guaranteed to work with any PC serial port.

Too Right. [+1]

Peter Jakacki
08-05-2013, 01:35 AM
I need to interface with a PC serial port but not for programming. Can I simply make a level shifter circuit for the RX and TX lines and then directly connect ground and be fine? I will be using this with different pins than 31 and 30 as this project will call for me to input from a pc serial port on two other pins and then output to usb (which i will do with an FTDI chip circuit on pins 31 and 30 as well as use this to program the chips)

If you don't need to be standards compliant and just want it to work then use a non-inverting logic gate (I use 74HCT1G86) for the transmitter and a 10K series current limit resistor for the receiver with a 47K pulldown at the Prop end. Works every time.

Why there is nothing "standard" about the RS232 standard:
This modern RS232 "standard" and being "safe" is total rubbish. There is no need at all for a negative voltage as there is no way at all for the receiver to detect it or for any communications to benefit from it. Switching threshold is around +1.8V, no voodoo, no mumbo-jumbo about this figure. Your standard MAX232 type chip under actual load will output +/-6V and knowing the characteristics of the receiver you already know that the negative part is because of the original 60's standard which did require it back then. Many of my products have RS232 just because they need to be conpliant for the standards but the most I do to communicate to RS-232 othertimes is provide a buffer to output 0..5V as I normally have 5V available and then 2 resistors (pulldown + current limit) for the receiver. In fact one commercial product with standard RS232 had to be pressed into accepting 5 receive channels for digital radio broadcast use and my product only had 2 "proper" RS232 inputs (RXD+CTS) and the others were of the resistor kind. With the flexibility of the Prop and a bit of software these units have been running without a hitch 24/7 for years.

PJ Allen
08-05-2013, 03:00 AM
Get thee behind me, Satan.

You can't get the distances with 0/5 that you can with +/-12.
Short runs? Meh. Probably not as important as getting that Pin2-Pin3 deal right.

Maxim makes a good deal of cash producing these devices and it's not because people are being duped by an "RS232" hoax.
Please.

Dr_Acula
08-05-2013, 03:24 AM
Would it just be easier to use a MAX3232 to get the levels safe for my propeller.

Another +1 to that.

I bought whole lot some years back. Simple to use. Quicker to solder up than using discrete transistors and other components as you don't need to be checking tiny writing on transistors and getting them round the right way. MAX3232s are cheap. Uses 4 0.1uF caps (and I like to put another one across the supply pins) and if you are already buying 0.1uFs in bulk for bypassing ICs then they are cheap too. What else? You get two ports in one chip so if you want to add another port you can do it for free. You can short RS232 pins, cross them over, feed 12V AC or DC down the pins and it won't zap the propeller chip.

Peter Jakacki
08-05-2013, 03:54 AM
Get thee behind me, Satan.

You can't get the distances with 0/5 that you can with +/-12.
Short runs? Meh. Probably not as important as getting that Pin2-Pin3 deal right.

Maxim makes a good deal of cash producing these devices and it's not because people are being duped by an "RS232" hoax.
Please.

They are not +/-12V, they never have been, at absolute best they are +/-9V without load and with 1uF caps. Unlike the very first transatlantic cable where they tried using higher and higher voltages to go the "distance" until they had damaged the cable, it turned out that the solution was not voltage but having a more sensitive receiver, that is a better method. Anyhow, right at the moment I am running and powering a Prop and VGA display at the end of a 100M phone cable and I would never ever think of using RS232 to go the distance, never, just good old 0..5V for that thank-you. RS232 is limited in speed and distance and noise immunity because the standard is almost as old and misapplied as the first transatlantic cable methods were.

Stop propagating this RS232 "safe" nonsense although I agree that Maxim do make a lot of money out of propagating the "need to be safe" nonsense. The standard should have been redefined decades ago to fit in with modern "RS232" where the chips are designed to work with 0..5V "RS232" signals, it's a de-facto standard that the need for the negative part was dropped back in the early days of micros for compatibility with logic powered devices. Read the datasheets of any RS232 receiver and tell me different if you can.

kwinn
08-05-2013, 05:47 AM
@Peter

I am not disputing the validity of what you are saying. Most equipment manufactured in the last 25 years or so will work quite well with a 0 to +5V signal. On the other hand if you want to be absolutely certain that your RS232 serial I/O will be compatible with any piece of equipment that has an “RS232” connector then you will need to have an output signal that goes between at least +3 to -3 volts. Even then, I have had some truly ancient equipment (35 years old and only recently retired) that will only work with a serial signal that is at least +-5V.

It is much simpler to use a MAX3232 or equivalent and be sure it works with whatever is connected to it than to rely on something that may or may not work.

Peter Jakacki
08-05-2013, 06:50 AM
@Peter

I am not disputing the validity of what you are saying. Most equipment manufactured in the last 25 years or so will work quite well with a 0 to +5V signal. On the other hand if you want to be absolutely certain that your RS232 serial I/O will be compatible with any piece of equipment that has an “RS232” connector then you will need to have an output signal that goes between at least +3 to -3 volts. Even then, I have had some truly ancient equipment (35 years old and only recently retired) that will only work with a serial signal that is at least +-5V.

It is much simpler to use a MAX3232 or equivalent and be sure it works with whatever is connected to it than to rely on something that may or may not work.

The point is that I will use a MAX232 when it needs to be compliant. The fact is that I don't think we are talking about ancient equipment either as I am well aware of stuff that was made in the 70s and even 80s that did have receivers that required the negative voltage as part of their switching threshold. None of this applies and especially when you have someone who wants to cobble together an interface to "RS232" which invariably means a PC or something made in the last 25 years (a 10 year old PC i regarded as ancient) which have been following the unpublished "mum's the word" de facto standard of 0..5V. So whenever someone asks how they can cobble together an RS232 interface you could tell them to go out and buy a special chip or they could do it with bits they have laying around. KISS - without being "dangerous" (as opposed to safe). We may know what the standard is and isn't but there is no need to propagate this RS232 mystery.

Loopy Byteloose
08-05-2013, 06:40 PM
Because of Peter's minimalist approach, I did locate a 'two resistor' serial interface that should work for the Propeller. But the author warns that things might go wrong.

While the Max3232 solution is in many ways ideal, the chip is hard to get here in Taiwan... so Beau's two transistor solution seems a very good choice. One can use the 2n2222 and 2n2907 for this as alternative parts without trouble.

Meanwhile, Peter can destroy something by exploring the absolute minimum of two resistors for a RS232 to Propeller interface.

The real problems is that all the manufacturers abandoned providing the +12/-12 power supply that true RS232 requires and decided to ignore the -12 requirement completely. It is so much cheaper to have the signal swing between +3.3 and 0.

And then suddenly, we had the USB port with a more expensive and more complex chip forced upon us and the RS232 and the PS/2 ports just disappeared.

++++++++
If you have trouble with reading the image, copy it to your computer and then zoom in on it. My browser zoom won't enlarge it.