Shop OBEX P1 Docs P2 Docs Learn Events
RS232 level shifter circuit — Parallax Forums

RS232 level shifter circuit

dodgerdodger Posts: 37
edited 2013-08-05 11:40 in Propeller 1
SerialToPropeller.jpg

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?·

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2009-03-20 00:23
    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*
  • virtuPICvirtuPIC Posts: 193
    edited 2009-03-20 13:47
    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 for tools & toys
  • dodgerdodger Posts: 37
    edited 2009-03-23 23:42
    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 SchwabeBeau Schwabe Posts: 6,566
    edited 2009-03-24 00:01
    dodger,

    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

    IC Layout Engineer
    Parallax, Inc.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2009-03-24 01:01
    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) [noparse]:)[/noparse]

    *Peter*
  • virtuPICvirtuPIC Posts: 193
    edited 2009-03-24 06:39
    Okay. What about this one: 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 for tools & toys
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2009-03-24 17:40
    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

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 3/24/2009 5:46:32 PM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2009-03-24 17:44
    dodger

    What are the specs on your serial device?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • dodgerdodger Posts: 37
    edited 2009-03-24 21:53
    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 SchwabeBeau Schwabe Posts: 6,566
    edited 2009-03-24 21:55
    dodger,

    Hmm... Nothing that indicates any voltage thresholds?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • kwinnkwinn Posts: 8,697
    edited 2009-03-25 00:50
    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.
  • dodgerdodger Posts: 37
    edited 2009-03-28 05:40
    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 JakackiPeter Jakacki Posts: 10,193
    edited 2009-03-28 05:49
    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*
  • dodgerdodger Posts: 37
    edited 2009-03-28 16:21
    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
  • dodgerdodger Posts: 37
    edited 2009-03-30 23:03
    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 JakackiPeter Jakacki Posts: 10,193
    edited 2009-03-31 00:54
    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
  • stevoveestevovee Posts: 18
    edited 2013-08-04 15:13
    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)
  • stevoveestevovee Posts: 18
    edited 2013-08-04 16:04
    Would it just be easier to use a MAX3232 to get the levels safe for my propeller.
  • kwinnkwinn Posts: 8,697
    edited 2013-08-04 17:44
    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.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2013-08-04 17:50
    kwinn wrote: »
    ...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 JakackiPeter Jakacki Posts: 10,193
    edited 2013-08-04 18:35
    stevovee wrote: »
    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.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2013-08-04 20:00
    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_AculaDr_Acula Posts: 5,484
    edited 2013-08-04 20:24
    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 JakackiPeter Jakacki Posts: 10,193
    edited 2013-08-04 20:54
    PJ Allen wrote: »
    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.
  • kwinnkwinn Posts: 8,697
    edited 2013-08-04 22:47
    @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 JakackiPeter Jakacki Posts: 10,193
    edited 2013-08-04 23:50
    kwinn wrote: »
    @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.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-08-05 11:40
    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.
    1024 x 500 - 50K
Sign In or Register to comment.