Shop OBEX P1 Docs P2 Docs Learn Events
prop and rs232 — Parallax Forums

prop and rs232

ZetsuZetsu Posts: 186
edited 2012-11-06 20:07 in Propeller 1
Hello I am working on a project from work where I will receive a decimal number via a serial port and would like to have a prop receive that signal and set a pin high or low depending on decimal received.

This question is in regards to wiring for rs-232, First of all can i wire up the rs-232 connection using any arbitrary pins that are available or does it in fact have to be the p31 32 comms pins for the prop ?

I am aware of needing a rs232 to ttl converter chip and i have one of those... so I would suppose it would just be a matter of connecting 1 of the tx lines and rx lines off that chip to the prop and visa versa for a DB9 connector...

I would like to use other pins then the default ones on the prop because i would like to keep the usbplug available for console debugging functionality.

I hope I explained that right ( It was simple setting this up on a basic stamp and programming it... although there is no real info on how this is done on the prop as far as I could find)...
«1

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-09 13:27
    It's not a problem using other pins for your RS-232 connection other than 30 and 31.

    Here's a link to a serial port merger. It might give you some ideas of how to receive and send data.

    I'll edit this post in a bit with a link to Tracy Allen's version of a four port serial driver that works really well. So check back here in a couple of hours (maybe minutes).

    Edit: Here's Tracy's thread. He has a couple of versions attached to post #1 of the thread.
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-10-09 13:38
    Hi Zetsu;
    Zetsu wrote: »
    Hello I am working on a project from work where I will receive a decimal number via a serial port and would like to have a prop receive that signal and set a pin high or low depending on decimal received.
    Yes, there are several rs-232 objects in the obex.
    This question is in regards to wiring for rs-232, First of all can i wire up the rs-232 connection using any arbitrary pins that are available or does it in fact have to be the p31 32 comms pins for the prop?
    Completely arbitrary as long as the pins are not used for something else. You will have to have a separate object for each use with a different name.
    I am aware of needing a rs232 to ttl converter chip and i have one of those... so I would suppose it would just be a matter of connecting 1 of the tx lines and rx lines off that chip to the prop and visa versa for a DB9 connector...
    Correct if you need true "Legal" rs-232 voltage levels.
    I would like to use other pins then the default ones on the prop because i would like to keep the usbplug available for console debugging functionality.
    Of course. P31..32 are for loading and debugging.
    I hope I explained that right ( It was simple setting this up on a basic stamp and programming it... although there is no real info on how this is done on the prop as far as I could find)...
    The description on how to do it is usually in the object documentation.

    Duane J
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-10-09 13:42
    Having a TTL converter means that it'll convert to 5V, so, don't forget to use resistors to 'convert' to propeller-voltage.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-09 14:11
    MagIO2 wrote: »
    Having a TTL converter means that it'll convert to 5V, so, don't forget to use resistors to 'convert' to propeller-voltage.

    True.

    But there are converters that convert to 3.3V (MAX3232) (of course then it's not TTL).
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-10-09 14:14
    There are converters that work on 3.3V and have 3.3V outputs. See:
    MAX3221-MAX3243
    And others.

    Duane J
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-09 14:17
    Duane Degn wrote: »
    But there are converters that convert to 3.3V (MAX3232) (of course then it's not TTL).
    There are converters that work on 3.3V and have 3.3V outputs. See:
    MAX3221-MAX3243
    And others.

    Great Duanes think alike.
  • ZetsuZetsu Posts: 186
    edited 2012-10-09 14:22
    https://www.sparkfun.com/products/589

    I
    s what I am using to convert..
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-10-09 16:30
    Is what I am using to convert..

    That will be perfect. So you need one of those chips, four 0.1uF capacitors, one D9 connector and that is it. Pick any two propeller pins and wire it up. Then in the software, tell the program which pins you are using.

    That chip can do two RS232 ports, so you can wire up another one with another D9 plug.

    On the D9, use pins 2 and 3. Pin 5 is Gnd. Is your D9 a male or female plug?
  • ZetsuZetsu Posts: 186
    edited 2012-10-09 16:36
    male.
    There is a little more to the story i guess.... This is an existing system, the original designer has passed on and is no longer available in any form to ask how he did stuff...
    Some of the issues I am going to run into tonight are, he doesn't use any sort of start or stop bit for comms, ( he wrote his own rs-232 standard ) as well as no clock.
    I tried doing this with a basic stamp last year, and due to the variation in the rs232 standard I had no luck.
    My idea was to just read the values in off the pin one at a time into an array then combine them together in a variable then convert to decimal and take the required action. Thus skipping all the standards that I can't adhear too.
    Sure rewriting the other 1/2 of this would fix the standard issue, except its about 10k line C program, that was written in 1983 ( year I was born ) and I don't want to spend the amount of time it would take to change it.
    Hopefully I can somehow tailor this object to work with this mess ;x


    C program executed on a server and spawned to a dumb terminal on the shop floor ( vecmar vt-100), db25 pin from that to db9 to a zilog processor,( current setup)
    we have 24 of these processes running on our server and each is being spawned to a different vt-100 which has the option to sound a fire alarm or a tornado alarm, ( over sized time clock )

    This is my first real (outside of lighting up leds, and college projects etc.. etc.. ) Embedded system
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-10-09 16:40
    Since you are only receiving from the serial port then why bother with any RS232 chip at all? Just feed the signal into a 10K pull-down and a 100K series resistor into the port pin. The signal will appear inverted so set the appropriate mode bit in the serial driver. The Prop's input thresholds are very similar to an RS-232 receiver so there is nothing to gain by using an external chip plus there is no other magic involved.

    BTW, just read your latest post, I doubt very much that the signal would not have any start or stop bits but I think you may mean it does not have any start or stop characters that may be used to define a packet. If you give us some details about what is being sent then I'm sure someone can help you out a bit more or at least offer a tip.
  • ZetsuZetsu Posts: 186
    edited 2012-10-09 18:50
    The only input the chip would receive is a 4, 3, and a 9 ( I captured these values using the prop serial terminal). There is no preceding or trailing characters, as well as no carriage return to denote the start or stop of communications. Thats the exact issue which seemed to hold me up on using a stamp. I decided to approach the project using a prop, and figured it might just be easier to try to intercept the binary value off the pin and just convert to decimal.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-10-09 18:58
    Zetsu wrote: »
    The only input the chip would receive is a 4, 3, and a 9 ( I captured these values using the prop serial terminal). There is no preceding or trailing characters, as well as no carriage return to denote the start or stop of communications. Thats the exact issue which seemed to hold me up on using a stamp. I decided to approach the project using a prop, and figured it might just be easier to try to intercept the binary value off the pin and just convert to decimal.
    I'm a bit confused but maybe it's the terminology you are using. Are you saying that the serial communications only sends the ASCII characters for 4, 3, and 9? If so then I'm not sure why you are talking about intercepting binary values and converting to decimal. If they are printable characters and decimal digits at that then they are extremely simple to deal with.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-10-09 18:59
    There are lots of propeller objects that can convert bytes to strings, to decimal values etc. So for instance, you could take the ascii values for 4, 6, 9 and look them up on the ascii table http://www.asciitable.com/ and then write a few lines of spin. One trick is to note that zero is ascii 48, so if you subtract 48 then you get the actual number. So if you happened to have ascii 52, 54 and 57, subtract 48 off each, then multiply the first one by 100 and the second one by 10 and then add all three together you would have a number 469.

    There are objects that can do all that automatically.

    There are lots of other things you can do too and very easily in Spin. Just let us know your input values and what you want it to be turned into.

    Oh, and if you can read these with the prop terminal then that is very good news because it means it is standard RS232 with start and stop bits, so all the objects are going to work right out of the box.

    Your whole code might only be 10-20 lines.
  • dr hydradr hydra Posts: 212
    edited 2012-10-10 08:03
    So could you use the MAX3232 to serial program the propeller from your PC serial port without using any external resisitors? The output from the MAX 3232 should be at 3.3V...correct?

    PC 5v->MAX3232->propeller at 3.3v
  • ZetsuZetsu Posts: 186
    edited 2012-10-10 08:09
    thats how I was going to attempt it.

    I have to wait for the chips to show up tonight, hopefully everything goes well and I wont be having to order another prop to replace ;x
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-10-10 08:17
    Yes, that could be done.
    However, most PCs don't have rs-232 serial ports anymore. Most have USB ports now which need a USB to Serial adapter.
    OK, PCs that do have rs-232 ports will, generally, require at least the resistor protection or the MAX3232 powered from 3.3V.
    Note! Don't power the MAX3232 from 5V as it will then output 5V to the prop pins. It's in the spec.

    Duane J
  • ZetsuZetsu Posts: 186
    edited 2012-10-10 10:46
    Yes, that could be done.
    However, most PCs don't have rs-232 serial ports anymore. Most have USB ports now which need a USB to Serial adapter.
    OK, PCs that do have rs-232 ports will, generally, require at least the resistor protection or the MAX3232 powered from 3.3V.
    Note! Don't power the MAX3232 from 5V as it will then output 5V to the prop pins. It's in the spec.

    Duane J

    Cant i just power it off the 3.3v regulator that supplies my prop power ?
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-10-10 11:54
    Hi Zetsu;
    Zetsu wrote: »
    Cant i just power it off the 3.3v regulator that supplies my prop power ?
    Yes, the props 3.3V regulator is the preferred power source.

    Duane J
  • ZetsuZetsu Posts: 186
    edited 2012-10-10 17:22
    looks like this project is on hold for another day or two ;x the chips i ordered i guess are smd mounts, and i needed to plug them into a breadboard :) fun times...
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-10-10 17:29
    Zetsu wrote: »
    looks like this project is on hold for another day or two ;x the chips i ordered i guess are smd mounts, and i needed to plug them into a breadboard :) fun times...
    If you are simply receiving then the MAX chips are totally redundant. Here is a circuit you can whip up in a jiff.
    Simple RS232 receive circuit.jpg


    The MAX chip will not improve anything at all. It's high threshold is 1.7V and it's low is 1.2V, it doesn't do anything with negative voltages at all.

    EDIT: I noticed that I shrunk the text box a little in the screenshot so here are the complete figures:
    [FONT=courier new]RS232          PROP          LOGIC
    +24V          +3.75V          HI 
    +9V           +3.73V          HI
    +5V           +3.68V          HI
    +3.3V         +3.3V           HI
    +1.45V        +1.4V           HI
    +1.3V         +1.3V           LO
    
    -9V           -0.3V           LO
    -24V          -0.3V           LO[/FONT]
    
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-10-10 19:00
    So could you use the MAX3232 to serial program the propeller from your PC serial port without using any external resisitors? The output from the MAX 3232 should be at 3.3V...correct?

    Absolutely. I use a max3232 on all my boards for the download instead of the prop-plug. Then once it is programmed, you get a RS232 port for nothing :)

    Re not needing a max3232, as Peter points out, you can get away without one if you know the voltages on your device. The official RS232 standard is that resting volts are anything more negative than -3V, and a data pulse is anything more than 3V. Voltages between -3V and +3V are not allowed.

    However, even more than 20 years ago, there were exceptions, eg 0V counted as a negative voltage.

    A RS232 to TTL converter changes the negative volts to TTL high, and the positive volts to zero (ie an inverter. Sort of)

    One reason RS232 is useful is that "TTL" volts above is undefined. For many years it was 5V. But now it is more likely to be 3.3V. With the new propeller chip, it will be even lower.

    So people stick with the RS232 standard because you don't have to worry about this. Another reason is RS232 is more tolerant of faults. You can short pins together. You can mix up the Tx and Rx and join two Tx pins together. You can muddle up Gnd, Tx and Rx. You can put 12V AC down a pin and nothing will happen. You can't generally do any of things to a chip like the propeller.

    There are ways to bend the rules. The picaxe chips have a download circuit that consists of a 22k and a 10k resistor. You can feed a true RS232 signal, minus 12V and plus 12V into the picaxe chip with those two resistors and it won't mind. But that won't work for programming a propeller because the signal is inverted.

    As Peter says, if you have two boards next to each other and they are both powered from the same volts, no need to use max3232 chips. You can do the signal inversion in software.

    And if one board happened to be powered by 3.3V and the other by 5V, there is a cunning trick using a 2K7 resistor that does the voltage translation.

    As a general rule, if I build a box and I put a D9 socket on the side and I don't know what is going to connect to that, I do that with proper RS232 voltage levels. However, within that box, if I know all the specs and I happen to have two devices that use serial (eg a propeller and a picaxe chip), then no need to use RS232 chips.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-10-10 19:16
    Dr_Acula wrote: »
    Absolutely. I use a max3232 on all my boards for the download instead of the prop-plug. Then once it is programmed, you get a RS232 port for nothing :)

    Re not needing a max3232, as Peter points out, you can get away without one if you know the voltages on your device. The official RS232 standard is that resting volts are anything more negative than -3V, and a data pulse is anything more than 3V. Voltages between -3V and +3V are not allowed.

    However, even more than 20 years ago, there were exceptions, eg 0V counted as a negative voltage.

    A RS232 to TTL converter changes the negative volts to TTL high, and the positive volts to zero (ie an inverter. Sort of)

    One reason RS232 is useful is that "TTL" volts above is undefined. For many years it was 5V. But now it is more likely to be 3.3V. With the new propeller chip, it will be even lower.

    So people stick with the RS232 standard because you don't have to worry about this. Another reason is RS232 is more tolerant of faults. You can short pins together. You can mix up the Tx and Rx and join two Tx pins together. You can muddle up Gnd, Tx and Rx. You can put 12V AC down a pin and nothing will happen. You can't generally do any of things to a chip like the propeller.

    There are ways to bend the rules. The picaxe chips have a download circuit that consists of a 22k and a 10k resistor. You can feed a true RS232 signal, minus 12V and plus 12V into the picaxe chip with those two resistors and it won't mind. But that won't work for programming a propeller because the signal is inverted.

    As Peter says, if you have two boards next to each other and they are both powered from the same volts, no need to use max3232 chips. You can do the signal inversion in software.

    And if one board happened to be powered by 3.3V and the other by 5V, there is a cunning trick using a 2K7 resistor that does the voltage translation.

    As a general rule, if I build a box and I put a D9 socket on the side and I don't know what is going to connect to that, I do that with proper RS232 voltage levels. However, within that box, if I know all the specs and I happen to have two devices that use serial (eg a propeller and a picaxe chip), then no need to use RS232 chips.

    By that reason then Drac we would never be able to communicate at logic levels to other systems??? That is not the case and unfortunately RS232 is bandied around as a solution and yet the chips that people employ for RS232 don't even adhere to the standard. BTW, the output from the RS232 chip using standard 0.1uF caps and into a load is only around +/-5 or 6V anyway and we have already deduced that the chip accepts +1.3V as a "low". The resistor circuit can easily take 24VAC with nary an eyebrow raised, I use something similar for PLC circuits.

    The point here is that the OP can grab a couple of resistors, any old resistors almost, and have the circuit up and running in minutes rather than discussing ad nauseam without ever getting hands on.
  • ZetsuZetsu Posts: 186
    edited 2012-10-11 06:58
    Thanks for the help so far, I was able to capture my rs-232 signal with my O-scope using a pulldown resistor and a voltage divider as suggested. Tonight Ill work on getting some logic into place. ;) thanks.
  • ZetsuZetsu Posts: 186
    edited 2012-10-11 21:22
    Okay developing my code and I am seeing something that kind of concerns me..

    If i use the FullduplexSerial driver.. and call Rx to recieve my byte
    then at a pc enter the number 9 into the serial terminal i get a dec 57 returned ( i am well aware of ascii so i dont need an explanation )
    but..
    If i connect up my computer to the dumbterminal at work and wait for it to output i get the 9 in the serial terminal(parallax)..
    now is this because the serial terminal(parallax) is converting this for me (from 57 to 9 ) .. or is the dumbterminal really sending dec 9 ??
  • Mike GreenMike Green Posts: 23,101
    edited 2012-10-11 21:36
    The dumbterminal is probably sending a byte with the value 9. This is a tab character. On those devices that interpret control characters, this is "displayed" as a horizontal tab, usually with a tab stop spacing of 8 columns.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-10-11 22:22
    I've got a serial port sniffer program that I have found quite useful. Some characters won't display and you can set the terminal to display in hex (yes, another protocol to learn, but who doesn't dream in hex. I know I do...) At least then you can see values 0 to 31 and 127 to 255. I've got a few terminal program (search free terminal program) and some let you display in hex, or ascii and hex, or even binary.
  • ZetsuZetsu Posts: 186
    edited 2012-10-12 06:03
    I just added to my code a small routine that just checks to see if the value is over 9 if so it subtracts 48 from it, ( ascii conversion ) I think this will get me where i need to go, because all characters received are coming in as dec. so if the value is actually 9, program just continues on... if its 57 it subtracts the 48 to get 9 and then continues..

    This should work well for me because i never expect to have a 'real' value > 9
  • ZetsuZetsu Posts: 186
    edited 2012-10-12 08:05
    If you are simply receiving then the MAX chips are totally redundant. Here is a circuit you can whip up in a jiff.
    Simple RS232 receive circuit.jpg


    The MAX chip will not improve anything at all. It's high threshold is 1.7V and it's low is 1.2V, it doesn't do anything with negative voltages at all.

    EDIT: I noticed that I shrunk the text box a little in the screenshot so here are the complete figures:
    [FONT=courier new]RS232          PROP          LOGIC
    +24V          +3.75V          HI 
    +9V           +3.73V          HI
    +5V           +3.68V          HI
    +3.3V         +3.3V           HI
    +1.45V        +1.4V           HI
    +1.3V         +1.3V           LO
    
    -9V           -0.3V           LO
    -24V          -0.3V           LO[/FONT]
    

    question about your post:
    obviously you are correct ( because it works ) but when I look up the signaling specs of rs-232 it seems to conflict directly with your chart ( is this where inverting the signal comes in to place ??)

    What i found:

    Signal State Voltage Assignments - Voltages of -3v to -25v with respect to signal ground (pin 7) are considered logic '1' (the marking condition), whereas voltages of +3v to +25v are considered logic '0' (the spacing condition). The range of voltages between -3v and +3v is considered a transition region for which a signal state is not assigned.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-10-12 08:12
    Yes, this is where the inversion occurs. The table that Peter showed reflects the logic signal that the Propeller sees. Voltages at or above 1.4V are seen as high (1) and voltages below this are seen as low (0). RS232 considers any voltages at or below -3V as high (1) and voltages at or below +3V as low (0). The software can do the inversion. FullDuplexSerial has a mode value supplied at initialization to do so.
  • ZetsuZetsu Posts: 186
    edited 2012-10-12 08:15
    removed, silly question.
Sign In or Register to comment.