Shop OBEX P1 Docs P2 Docs Learn Events
FullDuplexSerial Tx problem — Parallax Forums

FullDuplexSerial Tx problem

OlovAOlovA Posts: 23
edited 2009-03-01 22:39 in Propeller 1
Hi. Does anyone know how to check if the "tx-buffer" is ready to receive new data ?

As it is now, i must wait after two byte of data until i put new data there for transmit.

Maybe i do something wrong...

Thank´s / Olov

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-01 17:31
    Here's one example. This would need to be added to the source of FullDuplexSerial
    PUB txflush
    
    '' Wait for transmit buffer to empty
    
      repeat until tx_tail == tx_head
    


    It's not quite what you asked for. Here's one that waits for some room in the buffer
    PUB txwait
    
    '' Wait for transmit buffer to have room for one character
    
      repeat until (tx_tail <> (tx_head + 1) & $0F)
    


    Note that the "$0F" assumes that the transmit buffer is 16 bytes in length. If you're using some other
    buffer size, you'll have to change the constant appropriately.

    Post Edited (Mike Green) : 3/1/2009 5:38:00 PM GMT
  • OlovAOlovA Posts: 23
    edited 2009-03-01 20:29
    Hi Mike, Thank's for the answer. I still have problem.
    What i want to do is, receive 8 bytes of Hex-data from pin 10 ( That works )
    Then i want to do something with it ofcourse, and send that data back to the host...

    If i send it without delay between the byte's, then after 3 byte's it doesn't send anymore.
    But if i insert a delay in the transmission routine it work's ( But then i get timeout at the host-side )

    I'll try to attach two pic's so u might understand what's happening...
    857 x 600 - 64K
    863 x 620 - 65K
  • OlovAOlovA Posts: 23
    edited 2009-03-01 20:36
    CON
     _clkmode = xtal1 + pll16x
      _XinFREQ = 5_000_000
    OBJ
      Serial : "FullDuplexSerialISD"  ' The only difference is that i insert Mike's TxFlush in this one
    VAR
      Byte ModBusStr[noparse][[/noparse]8],Ptr
      word CRC
    PUB Go 
      Serial.start(10,8,0,57600)    ' RxPin,TxPin,Mode,Baudrate
      'Serial.start(31,30, 0, 57600)
      DirA[noparse][[/noparse]9] := 1                  ' My pin for RS485 TxEnable
      repeat                        ' Pointer for received characters
        Ptr := 0
        repeat
          ModBusStr[noparse][[/noparse]Ptr] := Serial.Rx  ' Store in this variable
          ptr++
        while Ptr < 8                  ' Until 8 char. received
        
        Serial.RxFlush                 ' Clear the RX buffer
        
        If ModBusStr[noparse][[/noparse]0] == $01         ' Check to see that the message starts with $01
          Ptr := 0
          OutA[noparse][[/noparse]9] := 1                 ' RS485 TxEnable
          repeat  
            Serial.Tx(ModBusStr[noparse][[/noparse]Ptr])  ' Transmit the received char.
            WaitCnt(Cnt+10000)         ' Wait for some reason ???
            ptr++
          while Ptr < 8                ' Until 8 char. sent
          OutA[noparse][[/noparse]9] := 0 
    '   01040000000131CA               ' A "Dummy" for test via "terminal window"
    
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-01 20:41
    I don't know what changes have been made to FullDuplexSerial to get FullDuplexSerialISD, so that might be an issue.

    With FullDuplexSerial, your "Fail" program should work. I don't know how you've connected the PC to the Propeller.
    From the "485" in the names of your pictures, I suspect that you're trying to use a half duplex RS485 setup to
    communicate. If so, you have to wait for the transmit buffer to empty before "turning the line around", then you
    have to wait for the transmit routine in the assembly cog to finish transmitting the last byte itself. You can approximate
    that by waiting until the transmit buffer is empty, then wait around 1 to 1.5 character times. Essentially use the "txflush"
    routine I showed, then wait (with WAITCNT) around 200us for the last character to be transmitted.
  • OlovAOlovA Posts: 23
    edited 2009-03-01 21:17
    Maaaaaaany Thank's Mike, this problem have made my scull loose some (more) hair. But now it work's thank's to YOU!
    I didn't think of the Tx Cog like that! When u told me it maked the coin fall down ( Swedish to english translation !!! )

    But anyway, yes that's it. Now it works like it should do. Again, MANY thank's Mike. From a snowy and cold Sweden / Olov.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-01 22:39
    From snowy and cold Minnesota to snowy and cold Sweden, you're welcome.
Sign In or Register to comment.