Shop OBEX P1 Docs P2 Docs Learn Events
FullDuplexSerial issue - help needed — Parallax Forums

FullDuplexSerial issue - help needed

stampedstamped Posts: 68
edited 2007-07-13 12:51 in Propeller 1
I am having an issue receiving data with the FullDuplexSerial. I can upload and download data to my prop through a USB2SER (PropStick?) and all is fine. I can call serial.ser(string("hello from prop!") and my PropTerminal receives the data. I cannot however send any data back to the Propeller with any reliability. I type in the PropTerminal, the lights flash on my USB2SER meaning it is receiving the serial data, but my code is having issues.. My code is as follows:

CON
··· _clkmode = xtal1 + pll16x
··· _xinfreq = 5_000_000


OBJ
··· Serial : "FullDuplexSerial"·


PUB main | rxString, okay
··· ' Time to open the PropTerminal
··· WaitCnt(320_000_000 + Cnt)

··· okay := Serial.start(31, 30, 1, 115200)······ ' The LED turns on..
··· if(okay)
····· ledOn(0)


··· Serial.str(string("Hello from Propeller!!"))····· ' PropTerminal receives my "Hello from Propeller!!"

···
··· repeat until (rxString := Serial.rxcheck) => 0·· ' This fires immediately (if in a repeat block, keeps looping with no data returned)


·

··· Serial.str(string(" RX RECEIVED: "))
··· Serial.str(rxString)·································· ' This value is either nothing, or garbage and is output immediately
return·

---

Alternatively I have tried:

rxString := Serial.rx

But I still have the exact same issue.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-12 13:43
    You are trying to receive a string and FullDuplexSerial can only provide a single character at a time. You have two choices:

    1) Use Serial.tx(rxString) to echo the single character

    2) Use the Extended FullDuplexSerial object from the Object Exchange which acts as a "front end" to FullDuplexSerial and adds several receive routines that handle the reception of strings and numbers for you.
  • stampedstamped Posts: 68
    edited 2007-07-12 14:10
    Thanks Mike for the tip. I had already tried the Serial.tx to send a character to the PropTerminal. But it sends some sort of clear signal and the "Hello from Propeller" is cleared, and nothing is placed on the terminal. Makes me think something very strange is going on. The code is so simple but I have been stuck on this for a few days now.

    I have tried using the Extended_FDSerial with:

    strID := string("c") ' I am not sure what this is meant to be, I guess an Identifier char, so it waits for a 'c'
    rxString := Serial.Rxstr(@strID)

    Serial.str(string(" RX RECEIVED: "))
    Serial.str(@strID)

    The function constantly outputs junk (no idea how, it is not even in a repeat block..) on the PropTerminal. So I am not really sure where to go to from here. As a second test, I have written to the COM Port from Java and it also gets a constant stream of junk back from the prop. It gets the "Hello from Propeller", but then constant junk.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-12 14:17
    Is there some reason why your mode parameter for Serial.start is 1? Usually it's zero or 3 so both transmit and receive are the same.
  • stampedstamped Posts: 68
    edited 2007-07-12 14:44
    I have changed my code a bit and found some stability to a point. With the '3' as the mode parameter it sends constant junk back on the Serial.str, and with a 1 it also does the same. Code is currently looking like this:

    CON
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000

    OBJ
    Serial : "Extended_FDSerial"

    PUB main | rxString, okay, strID ' NOTE MAY NEED TO MAKE myString[noparse][[/noparse]50]
    ' Time to open the PropTerminal
    WaitCnt(320_000_000 + Cnt)

    okay := Serial.start(31, 30, 0, 115200)
    if(okay)
    ledOn(0) ' This method turns on a LED.

    Serial.str(string("Hello from Propeller!!")) ' Outputs just fine to the PropTerminal and Java

    WaitCnt(100_000_000 + Cnt)
    strID := string("c") ' Still unsure about this character? Is it a "wait for this char" character for Rxstr?
    rxString := Serial.Rxstr(@strID)

    Serial.str(string(" RX RECEIVED: "))
    'Serial.str(strID) { Commented out and the PropTerminal does nothing when typing "c", Java gets garbage data back when sending "cccCR" on the third send exactly.. the Prop pumps back random data }

    dira := %1
    outa := 1
    WaitCnt(320_000_000 + Cnt)

    return

    Note, that if I comment out the Serial.Rxstr(@strID) Java and the PropTerminal both receive the " RX RECEIVED" message without any issue.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-12 15:00
    I think the problem you're getting into now is that Rxstr expects the string area to be 16 bytes long and, the way you've written your program, it's only 4 bytes long and the 12 bytes beyond that is getting overwritten. Declare strID as 4 longs like strID[noparse][[/noparse] 4 ].

    The 'strID := string("c")' is not needed. I don't know why you have it.
  • stampedstamped Posts: 68
    edited 2007-07-12 15:19
    This is making more sense... I changed the strID to 16 bytes and it is now stable. The reason I was assinging "c' to the strID was because I thought that the RxStr method took an identifier (wait char), rather than a reference to write to.

    The code now looks like:

    repeat
    rxString := Serial.Rxstr(strID)
    Serial.RxFlush
    Serial.str(string(" RX RECEIVED: "))
    Serial.str(@strID)

    The only issue I have now is that I am not receiving the strID back in Java with ease.. I am just getting a single byte calling Serial.str(@strID). Rather than the string "cat" that I am sending it.

    I just tried sending the first index of the 16 byte string (strID[noparse][[/noparse]0]) and I get the full String "cat". I am unsure why though? It is not an array as far as I know (with my limited knowledge)?
  • deSilvadeSilva Posts: 2,967
    edited 2007-07-13 09:26
    As millions of programmers before you (and after you) you got confused by "addresses" and "dereferencing" them smile.gif
    Parameters can only be "simple" values, thus "strings" are addressed by - their "address".
    strID is an "address"!
    It makes no sense now to use the address of this address, as you did in the last line (@strID) (except you wanted to change it, but you won't!)

    And note that "RxStr" (oficially) returns no value.

    Martin gave good descriptions of his routnes BTW
    x := Serial.RxDec                  Returns decimal string as value
      x := Serial.RxDecTime(ms)          Returns decimal string as value with timeout
      x := Serial.RxHex                  Returns received hex string value as decimal
      x := Serial.RxHexTime(ms)          Returns received hex string value as decimal with timeout
      Serial.RxStr(@myStr)               Passes received string
      Serial.RxStrTime(ms,@myStr)        Passes received string with timeout
    ver 1.1:
      SetDelimiter(char)                 Sets the delimiter character, such as comma or space. it is , by deafult.
                                         CR, or ASCII 13, will also be a delimiter in addition to this.
    
      x := Serial.IntOfString(@myStr)    Returns the integer (whole) portion of a string
                                         "-123.456" returns -123
    
      x := Serial.FracOfString(@myStr)   Returns the fractional decimal portion of a string
                                         "-123.456" returns 456
    
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-13 12:51
    In both cases where you're using a string, you need to pass the address of the string. Also, why add the call to RxFlush?
    If your PC program is sending a CR/LF pair, the LF will end up at the beginning of the next string since Rxstr just reads
    up through the CR and you might want to check to make sure that the extra character is the LF.
    repeat
        Serial.Rxstr(@strID)
        Serial.str(string(" RX RECEIVED: "))
        Serial.str(@strID)
    
    
Sign In or Register to comment.