Shop OBEX P1 Docs P2 Docs Learn Events
Serial communication on the Prop — Parallax Forums

Serial communication on the Prop

CumQuaTCumQuaT Posts: 156
edited 2009-02-28 05:51 in Propeller 1
Hi all,

I have some software that I've written for my PC that outputs single character packages via serial port (just like telnet) and I need it to make things happen on my propeller based on what that character is. Since I am an absolute beginner at the propeller, I was wondering if I could get some help with wiring and coding for this sort of functionality.

Thanks heaps in advance!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who are you, and why are you reading my signature?

Comments

  • JohnBFJohnBF Posts: 107
    edited 2009-02-19 01:57
    For coding ideas, take a look at http://forums.parallax.com/forums/default.aspx?f=25&m=329128

    /John
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2009-02-19 02:10
    What object are you using in the Propeller to receive the transmission? Is it Full duplex serial? If so, and I haven't done this myself, then I would write a program that waits for data to show up in the incoming Full Duplex serial buffer. Hold and wait for data to arrive. When the data arrives move the character (8-bit, a byte) to a variable and then do a CASE statement to process the action for the Propeller.

    Just some thoughts to help you along.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto for SunSPOT, BitScope
    www.tdswieter.com
  • JasonDorieJasonDorie Posts: 1,930
    edited 2009-02-19 02:17
    The PropPlug programming interface shows up on the PC as a serial port.· With the chip running, you already have the wiring you need.· It's attached to pins 30 & 31 on the Prop, so using FullDuplexSerial set to use those pins is what you need.

    On the Prop side (taken from SimpleDebug.spin):
    OBJ
      uart  : "FullDuplexSerial"
    
    PUB Main | okay
      '' Starts uart object (at baud specified) in a cog
      '' -- uses Propeller programming connection
      '' -- returns false if no cog available
        okay := uart.start(31, 30, 0, 9600)   'using 9600 baud here
    
    

    From there, you can occasionally call uart.rxcheck in a loop.· If the return value is -1, you didn't receive anything since you last checked.· If the return value is something other than -1, it's the next character in the receive buffer.

    repeat
      x := uart.rxCheck
      if x => -1
        ' Do something here, based on the value of x
      else
        waitcnt( constant(80_000_000/100) + cnt )  'wait for 1/100th of a second (assuming 80MHz)
    

    In between that 'if' and the 'else' would be the magic bits of your code.

    Jason
    ·
  • Cluso99Cluso99 Posts: 18,069
    edited 2009-02-19 03:41
    As Jason said, try FullDuplexSerial - works nicely. Run at 115,200 baud (same as PropTool).

    And I suggest you use PST (Parallax Serial Terminal) at the PC end. Other software may control the DTR and reset your prop (with the propplug interface). PST will share the port with PropTool nicely.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps (SixBladeProp)
    · Prop Tools under Development or Completed (Index)
    · Emulators (Micros eg Altair, and Terminals eg VT100) - index
    · Search the Propeller forums (via Google)

    My cruising website is: ·www.bluemagic.biz
  • CumQuaTCumQuaT Posts: 156
    edited 2009-02-19 04:17
    Thanks guys, I'll give these ideas a go...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who are you, and why are you reading my signature?
  • CumQuaTCumQuaT Posts: 156
    edited 2009-02-19 07:58
    How about wiring? I really don't want to use the prop plug for this. It needs to be serial if at all possible. What pins does the propeller need to receive serial? Would it just be 3,4,7 and 8? Where would these all go in regards to the prop and how would one code the reception?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who are you, and why are you reading my signature?
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2009-02-19 09:18
    The Propeller can receive serial on any pins. Pick your pins, design your RS-232 to TTL device, but the Prop Plug is really good at this, and then initialize the Full Duplex Serial to the correct pins.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto for SunSPOT, BitScope
    www.tdswieter.com
  • JasonDorieJasonDorie Posts: 1,930
    edited 2009-02-19 09:41
    Don't connect a real serial port's pins directly to the Propeller chip.· The Propeller can easily handle the serial 'protocol', but a real serial port uses 12V, which will damage your Prop.· You'll need something like a MAX3232 chip (voltage level shifter for RS232) to make the physical connection, which is another good reason to use a PropPlug.· [noparse]:)[/noparse]

    Jason


    Post Edited (JasonDorie) : 2/19/2009 9:49:34 AM GMT
  • CumQuaTCumQuaT Posts: 156
    edited 2009-02-19 10:52
    Yeah, good advice. I was planning to use a USB to serial converter for this purpose. I just wanted to know which pins on the serial port to connect to which pins on the propeller for it to work... If I was to send serial packets via telnet, which pins on the serial port would receive them?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who are you, and why are you reading my signature?
  • Cluso99Cluso99 Posts: 18,069
    edited 2009-02-19 11:18
    To get started I really suggest you use PST and the propplug. Once you understand this your other questions will become more apparent.
    The prop doe not have special serial pins, you just tell the FullDuplexSerial software which are the in and out pins (and inversion, if required). The prop uses a 3.3V interface and you will need a converter to RS232 voltages. There are lots of articles how to do this on this forum.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps (SixBladeProp)
    · Prop Tools under Development or Completed (Index)
    · Emulators (Micros eg Altair, and Terminals eg VT100) - index
    · Search the Propeller forums (via Google)

    My cruising website is: ·www.bluemagic.biz
  • CumQuaTCumQuaT Posts: 156
    edited 2009-02-19 11:45
    I know that the prop plug would be my best bet, but for the application I am using the propeller in, it needs to be able to receive telnet signals from a PC.

    Just to clarify, I'm not talking about programming the propeller with the serial, just letting a program I write on it talk to a computer via serial.

    I have built a device to control a lighting system, it needs to find out what color to make the lights via a serial connection to a computer.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who are you, and why are you reading my signature?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-02-19 14:45
    As Timothy said, pick any pair of available pins to use for receive and transmit. The various serial I/O drivers all are configurable with arbitrary pin numbers. You will need appropriate interface circuitry depending on how you want to connect the Prop to your PC. If it's 3.3V logic, you should be able to connect it directly. If your PC has an RS232 serial port, you'll need a MAX3232-based RS232 to 3.3V converter. If you need to use a Telnet connection from the PC, you'll need some kind of Telnet to serial adapter with a 3.3V logic output.

    There are several objects in the Propeller Object Exchange that can handle the serial I/O for you. FullDuplexSerial comes with the Propeller Tool. Simple_Serial has the advantage that it's simple. The BS2 Compatibility Library has similar routines to Simple_Serial and other useful routines. All of them have some documentation in the source code itself and some (like the BS2 Compatibility Library) has some demo code.
  • WNedWNed Posts: 157
    edited 2009-02-19 15:15
    ...In case it might help, here's a link to the pinouts for several types of serial connectors. You'll probably be most interested in the DB25.
    http://www.connectworld.net/rs232.html
    ...Also, you'll most likely want to look into these topics:
    http://forums.parallax.com/forums/default.aspx?f=25&m=208245
    "Computer guy's hardware guide for the beginner", is very useful, especially items relating to interfacing a 5v signal to your 3.3v Propeller.
    ...Read the comments in the FullDuplexSerial code, you'll see that you can assign any available pin as Receive (RX), or Transmit (TX) on your Propeller, you then code your program accordingly.
    ...I've found the RS232 to USB adapter, available from Parallax, to be very useful. You can still use the USB connection from your PC with the Prop Serial Terminal, HyperTerminal, or even VB, and use any pins you want on the Propeller to configure as your RS232 port.
    ...Also worth noting, if you're using a Prop Demo Board and the FullDuplexSerial object, assign Pin 30 for TX and 31 for RX to use the same connection you use to download programs to the Prop for serial communications without having to muck around with any hardware. Hit the [noparse][[/noparse]F7] key while in the Propeller IDE to find out which serial port is assigned to your Propeller.
    That's about all I've got...

    ...Oh, wait. If you don't have a Prop Demo Board and you really want to rock your project, download the schematic for the Prop Demo Board and duplicate the circuitry for the USB connection. It's all still serial IO as far as the Prop and PC are concerned, and you'll know you have a proper and robust serial port.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "They may have computers, and other weapons of mass destruction." - Janet Reno

    Post Edited (WNed) : 2/19/2009 3:44:38 PM GMT
  • Andrew E MileskiAndrew E Mileski Posts: 77
    edited 2009-02-19 20:54
    If you are looking for a simple voltage level-shifting circuit, look at the Propeller Datasheet, page 5, section 2.3.2 "Alternative Serial Port Connection". Pretty hard to beat 4 resistors, 2 transistors, and a capacitor for price too.
  • CumQuaTCumQuaT Posts: 156
    edited 2009-02-21 03:10
    Thanks Andrew.

    All I'm really trying to do is this. I want to send characters through telnet (or hyperterminal) on a pc through the pc's serial port (i think it's DB9?) and have those characters be retrieved on the propeller. Let's for argument's sake say I will be displaying them in a debug window.

    I've received some great coding examples which I'll be diving into asap (thanks guys) but what I'm after is how to wire that up. Which pins on the serial port do I connect to what on the propeller? Does someone know of a schematic I can use? I don't mind getting extra parts like a MAX232 or whatever to make this happen.

    If anyone can help me out here, that'd be amazing!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who are you, and why are you reading my signature?
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2009-02-21 03:36
    CumQuat - In the previous posts there have been several example and references that you can search on for schematic and parts. In the Propeller Datasheet there are examples of the circuit you are requesting.

    I highly recommend just using the Prop Plug as your serial connection if you have one since you won't have to add any wires or ICs or any other circuit. Just write your code to use Full Duplex serial or one of the other serial routines mentioned. Point that code to pins 30/31 that the Prop Plug attaches to. When the Prop Plug is plugged into your computer USB port it shows up at a COM port. You can open that COM port in Hyperterminal or other terminal programs (I prefer the terminal program that Parallax provides).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto for SunSPOT, BitScope
    www.tdswieter.com
  • WNedWNed Posts: 157
    edited 2009-02-21 03:49
    The really short answer to your question is: download the data sheet from this page,
    http://www.parallax.com/tabid/442/Default.aspx
    Look at page 5, specifically 2.3.2. Alternative Serial Port Connection. That is the schematic you're looking for. The right side of the schematic is the Propeller side, The left side is the connection to the PC. That's it.
    In addition to the really short answer; the schematic uses pins 30 and 31 on the Prop. You can use any pins you want. Also, for asynchronous comms, the DTR signal is not necessary. All I ever use is RX, TX, and Ground, but I'm a barbarian...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "They may have computers, and other weapons of mass destruction." - Janet Reno

    Post Edited (WNed) : 2/21/2009 4:28:55 AM GMT
  • CumQuaTCumQuaT Posts: 156
    edited 2009-02-21 12:11
    Ah, cool. Sorry, I hadn't read it right. I'll look at the datasheet. Thanks very much.

    Timothy, I've mentioned a couple of times that I don't, for my own reasons for this particular project, wish to use the propplug. I use it for my prototyping, yes, but I can't for this project. It needs to be serial.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who are you, and why are you reading my signature?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-02-21 14:47
    The serial PropStick used a MAX3232 for RS232 to 3.3V interfacing. Attached is the documentation for it. You could copy that circuit for you needs.
  • sderycksderyck Posts: 6
    edited 2009-02-27 22:06
    a little off the subject but this is the closes forum I could find to ask this question
    I have used a basic stamp for a long time. always had problems with serial communications with hyper and/or other terminals and had to put together a little circuit from this forum to get the pins to go fully low or high whatever the case may be.
    I am about to receive a propellor chip where i must include a circuit in order to communicate with a serial port. that circuit was mentioned earlier in this forum... it's on page 5 of the propellor speck documument.

    anybody know if this circuit would also work on the basic stamp serial communication?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-02-27 23:15
    It won't quite work. The Propeller uses 3.3V logic levels while the Stamp uses 5V logic levels.

    The OEM BS2 schematic (www.parallax.com/Store/Microcontrollers/BASICStampOEM/tabid/135/CategoryID/10/List/0/SortField/0/Level/a/ProductID/21/Default.aspx) shows a typical RS232 interface circuit used for the programming port on the Stamp that can be used on other I/O pins. Check the Stamp manual in the chapters on SERIN and SEROUT. They show how to interface a Stamp to an RS232 port. You may be able to get away with just using a series resistor between input Stamp I/O pin and the RS232 line.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2009-02-28 05:51
    Re "...I've mentioned a couple of times that I don't, for my own reasons for this particular project, wish to use the propplug. I use it for my prototyping, yes, but I can't for this project. It needs to be serial."

    Ok, keep the serial simple. Three wires - Tx, Rx and ground. Use D9 plugs. Pin 5 is ground. Data comes out of pin 3 if the plug is male. Data comes out of pin 2 if it is female. Take a male plug, eg the one from your PC. Maybe make an extension lead (use D9IDC plugs and rainbow cable as it takes less than 1 minute and no soldering). Put the earth lead of a multimeter on pin 5. You will get minus 12V on pin 3. You will get nothing on pin 2 because pin 2 is the input. RS232 rests at negative volts and is active with a positive voltage. Anything less than minus 3V or more than plus 3V is a valid signal. 0V is not a valid voltage in RS232. If you use a max232 you will get 5V out and you want 3V out so use a max3232. Put in minus 12V and you want +3.3V, and put in plus 12V and you want 0V. So after the signal goes through a max3232 the -12V turns into a resting value of +3.3V. It is essentially the circuit of the propstick except we are ignoring R1in and R1out and pin 4 of the D9 is not connected and the 2N3904 and associated components are not used. It is just the max3232 with the 4 capacitors and a D9. Now you have two wires with logic levels of 0V and 3.3V. On the prop stick they go to pins 40 and 39, but they can go to any pin on the prop. Just make sure that you set the pins up as inputs or outputs in the right way. And recode the code to suit those two pins. If you are worried about two outputs fighting (does the prop boot up with pins set as inputs or outputs?), then you could put series resistors in eg anything from 220R to 10k would work.

    So start with Mike Green's propstick and just leave some components out. Max3232s are cheap on ebay. 0.1uFs are even cheaper. And a D9 female is only 45c. That will be all you need.

    Post Edited (Dr_Acula (James Moxham)) : 2/28/2009 6:02:22 AM GMT
Sign In or Register to comment.