Shop OBEX P1 Docs P2 Docs Learn Events
My Serial comms program not working — Parallax Forums

My Serial comms program not working

Lee MarshallLee Marshall Posts: 106
edited 2007-10-04 15:50 in Propeller 1
i have written a simple program which inputs 5 characters from the PC over RS232, and then displays them, unfortunately, something weird is happening:
'Recieves and Transmits 5 characters to PC


CON
  _CLKMODE = XTAL1 + PLL4X
  _XINFREQ = 14_000_000

OBJ
  SLink : "Simple_Serial"
  Num : "Numbers"

VAR

  Byte char
PUB Main
  SLink.start(31,30,9600)
    SLink.tx(12) 'Form Feed
    SendLine(string("Input 5 Characters"))
    char[noparse][[/noparse]0] := SLink.rx
    char := SLink.rx
    char := SLink.rx
    char := SLink.rx
    char := SLink.rx

    SLink.tx(char[noparse][[/noparse]0])
    waitcnt(cnt+1_000_000)
    SLink.tx(char)
    waitcnt(cnt+1_000_000)
    SLink.tx(char)
    waitcnt(cnt+1_000_000)
    SLink.tx(char)
    waitcnt(cnt+1_000_000)
    SLink.tx(char)
  

PUB SendLine(straddr)
  SLink.str(straddr)
  SLink.tx(10) 'Line Feed
  SLink.tx(13) 'Carriage Return



It starts by sending the string: Input 5 characters, this works fine.
I enter 5 characters:
nothing happens at all if i use hyperterminal, and if i use PuTTY it gets the 2nd and 3rd letters wrong in a strange sort of way.
I enter aaaaa.
I get aueaa.
if i enter bbbbb.
i get bvfbb.
if i enter zzzzz.
i get z~~zz.

EDIT:
I have found something which could point to a cause. if i remove the definition of the Numbers object, the output is different.
i enter aaaaa
i get a

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-04 14:30
    I suspect the problem is the crystal frequency you're using. The Propeller is not designed for an input greater than 8MHz with the PLL running. The fact that you've been able to get it to run at a higher frequency doesn't mean that it does it reliably. The behavior you're seeing looks like a timing problem. If you want to run the Propeller with the 14MHz crystal, try using it without the PLL running.
  • Lee MarshallLee Marshall Posts: 106
    edited 2007-10-04 14:35
    Without the PLL, it doesnt send anything at all, not even the "Input 5 characters" message.
    also the forum seems to be messing up the code.
    i have defined char as a 5 pos array "byte char [noparse][[/noparse] 4 ]"
    and i am writing to the array like so:
    char[noparse][[/noparse] 0 ] := SLink.rx
    char[noparse][[/noparse] 1 ] := SLink.rx
    char[noparse][[/noparse] 2 ] := SLink.rx
    char[noparse][[/noparse] 3 ] := SLink.rx
    char[noparse][[/noparse] 4 ] := SLink.rx

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Holy parallel processing, Batman!

    Post Edited (Mr Crowley) : 10/4/2007 2:46:28 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-04 14:46
    Try it at a lower Baud ... like 2400 ... or use the assembly language serial driver "FullDuplexSerial". It's functionally the same except that the start method takes an extra mode parameter ... you can just supply a zero in this case. Look at the comments for the start method.
  • Lee MarshallLee Marshall Posts: 106
    edited 2007-10-04 15:02
    2400 baud gives the same results.
    however, using fullduplexserial instead of simpleserial fixes the problem.

    thanks for help.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Holy parallel processing, Batman!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-04 15:50
    It may be that 2400 is still too fast for a 14MHz clock with the Simple_Serial routines. The FullDuplexSerial routines can handle in excess of a 230KBaud rate with an 80MHz clock, so, at 14MHz, it should handle something on the order of 56KBaud. The Simple_Serial routines can handle 19.2KBaud with an 80MHz clock. At 14MHz, that's about 3000Baud, so it ought to work, but may be marginal.
Sign In or Register to comment.