Shop OBEX P1 Docs P2 Docs Learn Events
RS232 communication with PC/PPC — Parallax Forums

RS232 communication with PC/PPC

CrosswindsCrosswinds Posts: 182
edited 2010-10-13 06:55 in Propeller 1
Hello Everyone!

Just wanted to see if there is any information about using the FullDuplexSerialPlus object for simple communication to a PC´s serial port, and a terminal as reciever program?

It should be pretty simple, but it would be nice to know what pins to use, and if there is some tips out there about protocol.

This will just be simple serial strings though.
«13

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-10-07 14:53
    You can use any pair of pins as long as you use a USB to serial adapter like the PropPlug. When you start the FullDuplexSerial object, you have to supply the pin numbers to be used. If you're not using USB for this, but a standard RS232 serial port, you'll need some kind of level converter from 3.3V logic to RS232 voltage level. A MAX3232 can provide this. Find this chip on Maxim's website. Their datasheet has some sample circuit diagrams. Most logic to RS232 adapters invert the signal, so you'd need to start FullDuplexSerial with the mode bits set for inverted receive and transmit.

    Parallax also has a transistorized level converter circuit on their Propeller Download page. This is not strictly RS232 compatible, but does work in most cases. It also inverts the signal.

    If you want to use the existing programming port, you'd use pins 30 and 31 when you initialize FullDuplexSerial
  • CrosswindsCrosswinds Posts: 182
    edited 2010-10-07 15:42
    Hi mike, and thanks for your answer!


    I will be using just a standard serial cable.

    And by pins i meant, sorry i should have specified this, the diagram of a standard PC serial cable. Please see this link for an image:
    http://www.aggsoft.com/rs232-pinout-cable/images/9-pinout.gif

    Im a bit unsure if i really have to use a MAX circut to get this to work. RS232 standard says that anything between 3-5v is okey. And since the prop puts out 3.3 i think this should work?

    I have communicated with an old RS232 reciept-printer, that worked great with 3.3 from the prop.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-10-07 15:57
    It's very very risky to use RS232 without some kind of interface circuitry. Yes, the Prop can put out 0 / 3.3V signals, but the serial port on the other end can put out -15V / +15V signals which can instantly destroy the Prop. If you cut the wires in the cable so the only wires are ground and receive (to the PC), you're probably safe. Remember that the Prop's output voltage is closer to 3.0V, so things might be close. You're better off with some kind of interface circuitry.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-10-07 16:10
    Communicating with a PC is such a useful thing to do. I've added it as a 'standard' addition to a board design - schematic here http://smarthome.viviti.com/files/documents/Propeller_v5.pdf and board http://smarthome.viviti.com/propeller

    Ok, ignore most of the schematic but take a look at the max232 part. This combines the download circuit with a second RS232 circuit using another two pins. There is a multi serial port object in the Obex by Tim Moore that can handle both serial connections in one cog (actually it can handle up to four).

    RS232 to USB adaptors are on ebay for only a couple of dollars each.

    I've found this is very handy for debugging as you can have one serial port as the download port and have a terminal program permanently connected to the other port and send debugging messages to that second port. You can also debug to the programming port as well.

    Re pins, you can add all 9, but there is a much simpler circuit using 3 pins. You can see it on the second port on that schematic above. Join pins 7 and 8, and join pins 1,4,6. Ground is pin 5 and pins 2 and 3 are the data.

    There are good reasons to use a max232 or other interface circuit as the lines can be shorted, you can feed 20 volts down a line (even 20V AC) and nothing bad will happen, you can accidentally cross the Tx and Rx lines and you can even mix up a data line and ground, and nothing bad will happen. It makes everything so much more robust and protects the propeller from damage. A max232 chip costs $1 or less.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2010-10-07 17:03
    I know I can get by with 3.3V on almost any RS232 interface as the MAX232'ish receivers are simple positive threshold devices. Anything over 1.5V or so will make the output of the receiver go low. So in many designs I have 100K series resistors connected straight from the RS232 signal back to the Prop pin. This 100K takes good care of any "dangerous" and "risky" voltages (as if RS232 is the only interface prone to this). BTW, some of my commercial designs do have MAX chips but the other signals on the DB9 just use resistors. I have found that the simple resistor inputs when used as extra receivers work just as well in many different setups as the "proper" MAX receivers.

    The same goes for the transmit signal from the Prop, it may inadvertently be connected to the transmit signal from the RS232 device and even though it won't supply much current it may still damage the Prop. Or you could short the signal inadvertently. For outputs (general-purpose and otherwise) always use a series resistor for protection. I find a value of 220R always handy as it still provides enough current to drive an LED etc and has no trouble with driving RS232 receivers. All RS232 spec drivers have the equivalent of 300R series resistance built-in.

    Summing it up you are going to do whatever you want anyway so use the MAX232, or use transistors, or use resistors, but unless you like magic smoke and replacing Props don't ever connected the Prop pins directly to the outside world, which includes RS232.
  • CrosswindsCrosswinds Posts: 182
    edited 2010-10-08 11:22
    Hi guys and thank you for your very informative answers!

    Firstly, ofcourse i will use a resistor for safetyreasons!

    That is was i did with the printer.

    I have test it out today, but i cant get it to work.

    The only live i get from it is that it puts about 5characters of bull if i pull the input pin from it socket on the demo board. Thats all.

    Can this be that the ipaq expects alot higher voltage than props 3.3v? or am i looking at another problem here?

    (What is the output voltage of a PC´s serial port?)
  • Mike GreenMike Green Posts: 23,101
    edited 2010-10-08 11:33
    It's quite possible that your serial port requires more than 3V. Strictly speaking, RS232 uses voltages from 3 to 15V both above and below ground level (see here). The region between -3V and +3V is specifically undefined. As IC supply voltages have dropped over the years, more and more serial ports have made some use of this undefined region. The older your serial port, the less likely it will work with these low voltages.

    These limits are important. They provide some protection against noise and poor connections. It's best to use some kind of interface circuitry designed for this. You can sometimes get by with just a protective resistor, but not always ... and, if it doesn't work reliably, it's your fault for cheating on the standard.
  • CrosswindsCrosswinds Posts: 182
    edited 2010-10-08 12:19
    Hi Mike and thanks for your fast reply.

    I will have to look in to what voltages it needs. I read somewhere that a PC serial port puts out 12 volts? The iPaq PDA (wich im planning to feed with data, im only feeding just now, output to prop not used, becouse of the danger) must in that case be compatible with that. My guess had not been higher than 5v though.


    I will get my hands on a MAX232 circut this evening, and really hope it will work.

    Do you think its a voltage problem, considering the symptoms i wrote before?
  • CrosswindsCrosswinds Posts: 182
    edited 2010-10-08 13:25
    I have now measured the pins on the Ipaqs cable.

    Both RX and TX pins, measure -5v

    Glad i used a beefy resistor on this!

    But anyway, i think its confirmed now that the 3.3v with a resistor wont cut it!
  • CrosswindsCrosswinds Posts: 182
    edited 2010-10-08 15:26
    Hey!

    I didnt get my hands on a max, but i did get my hands on this:
    http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/SerialtoPropeller.pdf

    I have those components.

    The question is though, do i need to exchange the TX/RX pins with eachother? Have seen discussions about this, like a null-modem.

    After a fast look in the schematics, (not good with late night reading) it looks like TX and RX are wired differently. How should i adopt this if i need to exchange them?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-10-08 15:49
    "Exchange TX/RX with each other" ... why? The existing diagram is intended for use in having a Prop communicate with a PC. If you're not going to do programming with this adapter, you can use any other pair of I/O pin. I'd stay away from pins 28/29 because they're used for an EEPROM during the boot process, but any other pair would do.

    If you were going to use a Prop to replace the PC (act as a data terminal instead of a data modem), you would change some of the DB-9 pins around, but that's not what you're doing.
  • CrosswindsCrosswinds Posts: 182
    edited 2010-10-08 16:32
    Hello.

    The reason for exchangeing them is if it should work as a null-modem (PC-PC) or not.

    But since this would act as a PROP-PC, it should not be necessery then.

    The only thing i want is to send data from the prop to the pc (pocketpc), then this diagram should work right?

    And if im not way out, i should ignore the RESn part of it right? Thats just for programming the prop?
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-10-08 16:54
    RS232 can get very confusing with the Tx and Rx. Some simple rules of thumb:
    1) Use only three wires - ground, Tx and Rx.
    2) Use D9 plugs and sockets
    3) Ground is always pin 5.
    4) On a male D9, data comes out of pin 3 (it will usually be minus 12V if you measure it).
    5) On a male D9, data goes into pin 2.
    6) Conversely, on a female D9, data comes out of pin 2 and goes into pin 3. A female D9 will have minus 12V on pin 2.

    A null modem adaptor becomes quite simple. Take two female D9s and join pin 5 to 5 and cross over pins 2 and 3.

    Or

    Take two male D9s and do the same thing.

    I have made up both male/male and female/female null modem adapters and use both depending on the situation.


    But you may not need to do any of the above. If you can program a propeller (with whatever circuit works) then you can use the same cable for data communications. Use the propeller terminal, or use any terminal program. The only minor problem I've found doing this is that there is some disagreement on the propeller terminal as to whether you need carriage return or carriage return and line feed. Depending on the code you use, sometimes you find double spacing or no new lines. It is easy to tweak this in software though.


    re voltages, minus 5V is the same as minus 12V as far as RS232 is concerned. The 'undefined' voltage is -3 to +3V, so 0V is not a standard RS232 voltage. RS232 signals are resting when the volts are negative, and are positive when data is going through.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-10-08 17:25
    Use the diagram you have and leave out the /RES stuff (2N3904, 2 - 10K resistors, 0.01uF capacitor). You do need to keep the 10K resistor between DTR and RX on the DB-9. This is used as a source of negative voltage for the output transistor.
  • alimanaliman Posts: 2
    edited 2010-10-08 19:36
    Hi Mike, I'm new to this forum and I need a little help with a circuit I'm trying to build on a breadboard. It's a RS232 serial level converter using the MAX232chip from Texas Instruments. I have the datasheet for MAX232 and it has a schematic in it showing it's Basic construction. The problem that I'm having is getting my PC serial port to "SEE the MAX232 circuit I built.
    I'm suppling the circuit with 5v from a USB port, on my PC.
    I'm trying to build a ALDL interface ,( Assembly Line Data Link ) using the
    MAX232 . The ALDL uses TTL protocol to communicate. I'm trying to build this ALDL interface to Scan my automobile through my Laptop.
    I have tried the LOOPBACK TEST, using Hyper Terminal, but no success.
    I can't figure it out, I've built the circuit from scratch twice but no change.
    Here is the data sheet link.
    http://datasheets.maxim-ic.com/en/ds/MAX220-MAX249.pdf

    Any help would be great

    Sincerely Aliman
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2010-10-08 19:51
    Aliman,

    Can you repost this request on a new thread without "hijacking" Crosswinds thread. With a little more actual information I am sure someone can help you.
  • alimanaliman Posts: 2
    edited 2010-10-08 21:07
    Sorry about that!

    Aliman
  • CrosswindsCrosswinds Posts: 182
    edited 2010-10-09 04:05
    Dr_Acula wrote: »
    RS232 can get very confusing with the Tx and Rx. Some simple rules of thumb:
    1) Use only three wires - ground, Tx and Rx.
    2) Use D9 plugs and sockets
    3) Ground is always pin 5.
    4) On a male D9, data comes out of pin 3 (it will usually be minus 12V if you measure it).
    5) On a male D9, data goes into pin 2.
    6) Conversely, on a female D9, data comes out of pin 2 and goes into pin 3. A female D9 will have minus 12V on pin 2.

    A null modem adaptor becomes quite simple. Take two female D9s and join pin 5 to 5 and cross over pins 2 and 3.

    Or

    Take two male D9s and do the same thing.

    I have made up both male/male and female/female null modem adapters and use both depending on the situation.


    But you may not need to do any of the above. If you can program a propeller (with whatever circuit works) then you can use the same cable for data communications. Use the propeller terminal, or use any terminal program. The only minor problem I've found doing this is that there is some disagreement on the propeller terminal as to whether you need carriage return or carriage return and line feed. Depending on the code you use, sometimes you find double spacing or no new lines. It is easy to tweak this in software though.


    re voltages, minus 5V is the same as minus 12V as far as RS232 is concerned. The 'undefined' voltage is -3 to +3V, so 0V is not a standard RS232 voltage. RS232 signals are resting when the volts are negative, and are positive when data is going through.

    Man thanks for that explanation!

    I hope that with this circuit i will be able to communicate with the PPC. and get by with just these componets, since i want to try this out this weekend, and couldnt get a hold on a MAX.

    This would rule out any issues with voltage then, right?
    Mike Green wrote:

    Use the diagram you have and leave out the /RES stuff (2N3904, 2 - 10K resistors, 0.01uF capacitor). You do need to keep the 10K resistor between DTR and RX on the DB-9. This is used as a source of negative voltage for the output transistor.

    Thanks Mike for clarify how i should modify the circut!
  • CrosswindsCrosswinds Posts: 182
    edited 2010-10-09 07:15
    Hello!


    I have now hooked up the curcuit and having somewhat more luck with it now.

    The ipaqs recieves, but it puts out puke on the screen. just jibberish.

    Could that be that i have missed something on my circuit? (Have checked it 4 times) or something else?

    The reciever settings in the iPaq lookes like this:
    COM1
    Baud: 115200
    Parity: None
    Flow Control: None
    Data Bits: 8
    Stop Bits: 1

    I set the props code for 115200 and mode 0 (Actually i have tested both 0,1,2,3 modes.

    Any ideas?

    Edit:

    It seems like it gets the amount of characters right.
    If i send Hello World
    That exact same amount of characters (including the space) shows up on the ipaq, but they are totaly off..
  • CrosswindsCrosswinds Posts: 182
    edited 2010-10-10 06:44
    Hey Guys! What am i doing wrong here
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2010-10-10 07:04
    It would help you know if you showed us the characters that are garbled as that would give us some indication at least anyway. Sending a single character and repeats of the same character is another way to get a bit more of an idea. What happens if you change your baud rate to something much slower first just to make sure it works at the slow speed.
  • CrosswindsCrosswinds Posts: 182
    edited 2010-10-10 07:11
    Hey, Peter!

    Actually the charcters that it spews is not often the same from time to time. they are almost always changing. For some reason? And the strange thing is that its not often it even shows a letter, its mostly like {[( and like that.. But it always shows the right amount of characters.

    The lowest baudrate i can use is 9600 i think, i get the same fault, below that nothing shows up. (But this is like when i try to the regular PC with Parallax serial terminal, same thing)
  • Mike GMike G Posts: 2,702
    edited 2010-10-10 07:14
    Unexpected receive characters is usually a configuration issue baud, parity… It can also be encoding or connection. Try communicating at a lower baud 2400 or 9600. Use an O-Scope and verify the output from the Prop and your level circuit. Lastly, if your send the uppercase letter H, that’s ASCII; 0x48 hex, 72 decimal, or 01001000 binary. Make sure you’re using the appropriate FullDuplexSerialPlus method.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2010-10-10 07:28
    Are you using that 2 transistor circuit? This circuit is only suitable for programming as the DTR is manipulated by the Spin tool to provide a negative voltage while programming. Unfortunately the standard mode of operation when a serial port is opened such as with a serial terminal is that the DTR goes positive. Simplest solution is to take that 10K (BETWEEN db9 4 & 2) resistor out of the circuit or else ground it instead of tying it to DTR.

    The PNP transistor provides the inversion necessary when programming but you can also achieve the same effect by using the simple resistor circuit mentioned earlier and setting the mode to 3. Just try it.

    DB9.2 <----220R(ish)
    P30
    DB9.3 >----100K(ish)
    P31
  • CrosswindsCrosswinds Posts: 182
    edited 2010-10-10 07:33
    Are you using that 2 transistor circuit? This circuit is only suitable for programming as the DTR is manipulated by the Spin tool to provide a negative voltage while programming. Unfortunately the standard mode of operation when a serial port is opened such as with a serial terminal is that the DTR goes positive. Simplest solution is to take that 10K (BETWEEN db9 4 & 2) resistor out of the circuit or else ground it instead of tying it to DTR.

    The PNP transistor provides the inversion necessary when programming but you can also achieve the same effect by using the simple resistor circuit mentioned earlier and setting the mode to 3. Just try it.

    DB9.2 <----220R(ish)
    P30
    DB9.3 >----100K(ish)
    P31



    Yes im using the circuit from Parallax with the modifications Mike Green specified.

    Let me get this straight.

    Should i just throw that circuit away, replace it with the two resistors that you specify above, and just ground pin 4?
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2010-10-10 07:39
    I have just looked back over Mike's post but the trouble with the DTR resistor is just as I said unless the perhaps the terminal emulator can set the DTR to the right mode. Which terminal emulator are you using?

    Because it is so easy to do I would just use the 2 resistor circuit and ground pin "5" of the DB9. This is the simplest circuit there is and if it didn't work then your problem lies elsewhere.
  • CrosswindsCrosswinds Posts: 182
    edited 2010-10-10 07:41
    Im using Putty, and also a standard TTY (they both do the same)
    The putty is actualy a special port from standard Putty to pocketpc.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2010-10-10 07:47
    Ok then, just put the transistor circuit aside and try the 2 resistor circuit. Alternatively with the transistor circuit just remove the DTR end of the 10K and ground the 10K instead. That way at least the Tx data from the Prop will swing 0-3V.
  • CrosswindsCrosswinds Posts: 182
    edited 2010-10-10 08:03
    Just threw away that circuit. Connected this up.


    2.3 to my pins, and grounded 5. Changed mode in the prop to 3,
    Now nothing comes up. Stone dead.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2010-10-10 08:17
    If the Prop is transmitting to pin 2 of the PC's DB9 then it should be working. If you have a db9 and you are not sure which way around the rx and tx are hooked up then the easiest way to find out is to measure the voltage on the unconnected db9. Pin 3 should measure a negative voltage normally (around -6 to -12V nominally). Your prop tx on P30 through the 220R resistor should go to the receive pin (normally pin 2) which should NOT have a voltage reading when you test it unconnected.

    With just the PC and forget the Prop circuit try a loopback between 2&3 of the PC's db9 and make sure anything you type is being echoed.
Sign In or Register to comment.