Shop OBEX P1 Docs P2 Docs Learn Events
FullDuplexSerial programming help — Parallax Forums

FullDuplexSerial programming help

Jared5755Jared5755 Posts: 26
edited 2008-04-04 23:12 in Propeller 1
I'm working with the AVRCam http://www.jrobot.net/Projects/AVRcam.html

How do you all suggest writing a routine that continuously outputs "PG" on the tx pin·until "ACK" is received on the rx pin.· I'm using FullDuplexSerial to do this.· Here's what I've come up with (doesn't work):

  rxAVRcam=8
  txAVRCam=9
  modeAVRCam=%0000
  baudrateAVRCam=115200

  AVRCam.start(rxAVRCam, txAVRCam, modeAVRCam, baudrateAVRCam)

  c1:="P"
  c2:="P"
  c3:="P" repeat until (c1=="A" and c2=="C" and c3=="K")
    AVRCam.str(string("PG"))
    c1:=AVRCam.rxcheck
    c2:=AVRCam.rxcheck
    c3:=AVRCam.rxcheck

I've left some code out from the post.· My two other serial connections work just fine.· So, it has to be either my configuration for this one, or the routine to wait for an "ACK"

Thanks a lot

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2008-04-04 23:12
    hello jared,

    take a look into the comments of fullduplexserial
    as the sourcecode of fullduplexserial says

    PUB rxcheck : rxbyte

    '' Check if byte received (never waits)
    '' returns -1 if no byte received, $00..$FF if byte

    if the AVRCam does not respond "A" "C" "K" faster than the SPIN-code is running down
    c1:=AVRCam.rxcheck
    c2:=AVRCam.rxcheck
    c3:=AVRCam.rxcheck

    you might have the situation that your variables have the result
    c1 = "-1"
    c2 = "A"
    c3 = "C"

    and in the next loopturn

    c1 = "K"
    c2 = "A"
    c3 = "C"

    and then the condition is NEVER true



    you could try this

    PUB Pub1 | RcvdByte, AckCnt
    
      repeat 
        AVRCam.str(string("PG"))
        AckCnt := 0
        repeat until AckCnt => 3
          RcvdByte := AVRCam.rxcheck
          if RcvdByte == "A" or RcvdByte == "C" or RcvdByte == "K" 
            AckCnt := AckCnt + 1
    
    



    or this

    PUB rx : rxbyte

    '' Receive byte (may wait for byte)
    '' returns $00..$FF

    repeat until (c1=="A" and c2=="C" and c3=="K")
        'ATTENTION !
        'its important to flush the receivebuffer !!
        'because there could be still something in the receivebuffer
        'and then the sequence "A", "C", "K" will NOT be received in "c1", "c2", "c3"
    
        AVRCam.rxflush 
        AVRCam.str(string("PG"))
        c1:=AVRCam.rx
        c2:=AVRCam.rx
        c3:=AVRCam.rx
    
    



    best regards

    Stefan


    P.S.:
    for debugging purposes you could have coded something
    that sends the received value to another serial connection or tv_text or something like that
    and THEN you would have recognized the proplem by yourself

    so as a general advice:
    if you don't find the error by looking at the code

    code a feedback that shows you what is REALLY happening
Sign In or Register to comment.