Shop OBEX P1 Docs P2 Docs Learn Events
Propeller Serial Communication question. — Parallax Forums

Propeller Serial Communication question.

JMLStamp2pJMLStamp2p Posts: 259
edited 2007-10-26 23:20 in Propeller 1
Good evening,

I have been using a BS2 for serial communication and it is working well but I would like to use a Propeller for the speed and parallel processing. I know nothing about assembly language, do I have to use some assembly for serial communication with a propeller ?
Could someone give me a simple code sample to recieve data into a propeller using 9600 baud, 8-data bits, no-parity and 1 stop bit. I have a propeller board that I can test the program out on.

Thanks,
JMLStamp2p

Comments

  • Ken PetersonKen Peterson Posts: 806
    edited 2007-10-26 01:03
    JML:· The Propeller tool comes with two objects that you will probably find useful:

    SimpleSerial
    FullDuplexSerial

    They do all the heavy lifting for you.· All you have to do is call a function to send or receive a byte on the serial connection.· SimpleSerial is a half-duplex object if your requirements are minimal.· FullDuplexSerial launches another cog and maintains a receive buffer.· It can communicate over 100 Kbaud.

    You only need to know SPIN to use either.

    Hope this is helpful.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    The more I know, the more I know I don't know.· Is this what they call Wisdom?

    Post Edited (Ken Peterson) : 10/26/2007 1:09:21 AM GMT
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-10-26 01:28
    Thanks,
    Could you give me a simple code example that would set up a cog to run in a loop, look for serial data and turn on a specific led on the propeller board after I have loaded Full Duplex Serial.

    JMLStamp2p
  • AribaAriba Posts: 2,685
    edited 2007-10-26 06:18
    This is a very simple example:
    {{ Serial Test }}
    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      LED_PIN         = 16
    
    OBJ  ser    :       "FullDuplexSerial"
      
    PUB Main  | b
    
      ser.start(31,30,0,9600)       'start the serial driver
      dira[noparse][[/noparse]LED_PIN] := 1            'LED Pin = output
    
      repeat
        b := ser.rx
        outa[noparse][[/noparse]LED_PIN] := b & 1      'set LED from received Bit0
    
    



    Andy
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-10-26 14:35
    Thank You for your help, I am studying the prop manual, a good forum makes it so much easier to learn.

    JMLStamp2p
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-10-26 16:27
    Ariba,
    I have installed your code but I get a "Circular Referance" Error when I try and load it into Ram. I am probally installing the code in the wrong place. Could you please tell me where I need to install the code, I have it installed at the top of the FullDuplexSerial
    code right under the varibles declarations.

    Thanks,
    JMLStamp2p
  • LeonLeon Posts: 7,620
    edited 2007-10-26 16:50
    You need to put it in a separate file.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-10-26 21:27
    Thanks,
    I have put the code example in a seperate file and have downloaded it into the propeller with no faults. As far as downloading several files or Objects into the propeller such as FullDuplexSerial and the code sample above. Does pressing F10 download both files into the prop at once if I have both of them open in the editor? I have a Propeller Demo board with outputs 0 - 7 on the Header and would like to transmit a byte of "INVERTED DATA" out of pin 7 once every second and also blink an LED "PIN(16)" on the demo board folowing the serial transmission. Could someone adjust the following code sample to accomplish this, and what does the code fragment
    | b accomplish following the MAIN statement ?
    and
    b := ser.tx

    ser.start(31,30,1,9600)

    From what I understand 30, 31 in the above statment is the recieve & transmit pins to be used, am I correct ?
    If I want to use Pin "7" to transmit data out of the propeller do I need to change these accordingly or is this just the way the traces are set up on the Demo board?

    thank's so much for the help.
    ........................................................................................................................................................................................

    {{ Serial Test }}

    CON
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000

    LED_PIN = 16

    OBJ ser : "FullDuplexSerial"

    PUB Main | b

    ser.start(31,30,1,9600) 'start the serial driver, Mode "1" for Inverted Data ?
    dira[noparse][[/noparse]LED_PIN] := 1 'LED Pin = output

    repeat
    b := ser.tx
    outa[noparse][[/noparse]LED_PIN] := b & 1 'set LED from received Bit0
    ....................................................................................................................................................................................
  • LeonLeon Posts: 7,620
    edited 2007-10-26 21:37
    If you use pins 30/31 you can test the serial I/O with a Prop Plug connected to a Proto board (or something similar), using a suitable terminal program running on the PC. Modify your program to echo every character received and get that working first.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-10-26 22:24
    I have downloaded the following code and the LED's are blinking as expected, I am getting a RED blink on the USB port so I suspect that the " b:= ser.tx(01) " code is sending data out the port. I believe that I may have to adjust my scope, the propeller is so fast :>)

    Does anyone know if I should change pin 30 to pin "7" since I am using a propeller demo board and have a scope attached to the header ?

    .......................................................................................................................................................................................

    {{ Serial Test }}

    CON

    _CLKMODE = RCSLOW


    LED = 16

    OBJ ser : "FullDuplexSerial"

    PUB Main | b

    dira[noparse][[/noparse]16]~~
    dira[noparse][[/noparse]17]~~

    ser.start(31,30,1,9600) 'start the serial driver, Mode "1" for Inverted Data ?
    dira[noparse][[/noparse]LED] := 1 'Make pin 16 an Output output

    repeat 3

    b:= ser.tx(01)

    !outa[noparse][[/noparse]16]
    waitcnt(10000 + cnt)

    b:= ser.tx(07)

    !outa[noparse][[/noparse]16]
    waitcnt(10000 + cnt)

    .........................................
  • LeonLeon Posts: 7,620
    edited 2007-10-26 22:28
    You need the correct clock setting for the serial routines to work, they won't work with the RC clock.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-10-26 22:35
    Thanks Leon,
    Im getting somewhere, but slow :>)

    JMLStamp2p
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-26 22:38
    At least not with RCSLOW...
    Gosh , this is 20kHz! A SPIN line would execute in >20 ms smile.gif
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-10-26 23:20
    Leon, Everything is working with the following code. Transmitting data out pin "7" and showing on my scope great. I have the sample time set at "100 us." I have to input waitcnt commands to slow it down enough to view it on the scope, anything slower
    and it's just a "Blink" :>)
    Thanks for your help,
    JMLStamp2p

    {{ Serial Test }}

    CON

    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000

    LED = 16

    OBJ ser : "FullDuplexSerial"

    PUB Main | b

    dira[noparse][[/noparse]16]~~
    dira[noparse][[/noparse]7]~~

    ser.start(31,7,1,9600)

    waitcnt(10000000 + cnt)

    repeat
    !outa[noparse][[/noparse]16]
    waitcnt(100000000 + cnt)
    b:= ser.tx(01)
    waitcnt(100000000 + cnt)
    !outa[noparse][[/noparse]16]
    b:= ser.tx(82)
Sign In or Register to comment.