Shop OBEX P1 Docs P2 Docs Learn Events
Tying serial ports together — Parallax Forums

Tying serial ports together

hinvhinv Posts: 1,253
edited 2008-06-25 04:58 in Propeller 1
Hi

I am trying to tie in a 3.3v serial port to the console so that everything that comes in the serial port goes up to the serial console(usb on propdongle) and visa versa.

Right now, I have a main loop that looks like:

repeat
  wireser.tx(usbser.rx)
  usbser.tx(wireser.rx)




The problem is I don't get a character one way without getting a character the other way because usbser.rx waits for a character.
I am sure somebody has done this before. Any hints?

Thanks,
Doug

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-06-24 02:27
    hinv said...
    Hi

    The problem is I don't get a character one way without getting a character the other way because usbser.rx waits for a character.
    I am sure somebody has done this before. Any hints?

    Thanks,
    Doug

    repeat
      wireser.tx(usbser.rxtime(20))
      usbser.tx(wireser.rxtime(20))
    
    





    It's been a while since I've done communication code, but I *think* the above
    should work without stopping and waiting..

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with the Protoboard? - Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card? - PropDOS
    Need a part? Got spare electronics? - The Electronics Exchange
  • Ken PetersonKen Peterson Posts: 806
    edited 2008-06-24 02:27
    @hinv: try using a non-blocking call

    var
    byte char
    
    repeat
      if (char := wireser.rxcheck) <> -1
        usbser.tx(char)
      if (char := usbser.rxcheck) <> -1
        wireser.tx(char)  
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • hinvhinv Posts: 1,253
    edited 2008-06-24 03:26
    Thanks,
    I used
    var
    word n,o
    
    repeat
      if ((n := usbser.rxcheck) > 0)
        wireser.tx(n)
      repeat while (o := wireser.rxcheck) > 0
        usbser.tx(o)
    
    
    


    If I didn't use the later repeat, it dropped a lot more characters coming back from the router I am connecting to. It still drops way too much, but it is a little better with the repeat in there. If I knew how, I would set the serial port on the router (wgt634u running openwgt) to something a little slower, and hopefully fix the dropped character problem. I will also try upping the buffer size to 256 characters instead of 64 to see if that helps. BTW, thanks to whoever modified BB_FullDuplexSerial as I get to make this change.
    It could be my terminal also as I am using propTerminal in "Normal-Terminal Mode", and hyperterm is not available. Next I will try on a real os ie Linux where I have tools to work with(except on the prop side)
  • Jimmy W.Jimmy W. Posts: 112
    edited 2008-06-24 03:38
    I recommend you use (n := usbser.rxcheck() ) > -1
    because 0 is a valid value that can be sent

    Jimmy
  • hinvhinv Posts: 1,253
    edited 2008-06-24 04:30
    Thanks for the tip
  • hippyhippy Posts: 1,981
    edited 2008-06-24 14:53
    Isn't the obvious solution to put each in their own separate Cog / thread so each runs in parallel rather then sequentially ? This is where the Propeller beats most other micros hands down.

    PUB Main
      CogNew( wire2usb, @wire2usbStack )
      CogNew( usb2wire, @usb2wireStack )
      repeat
        twiddleThumbs
    
    PRI wire2Usb
      repeat
        wireser.tx(usbser.rx)
    
    PRI usb2wire
      repeat
        usbser.tx(wireser.rx)
    
    
    
  • Ken PetersonKen Peterson Posts: 806
    edited 2008-06-24 15:16
    Or you can venture into the fun and entertaining world of PASM programming!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • hinvhinv Posts: 1,253
    edited 2008-06-25 02:54
    @hippy: Thanks for the suggestion, but I thought that any time assembly was used, it was started in it's own cog. I thought each instance of BB_FullDuplexSerial ran in it's own cog and the main cog ran the spin tying them together.
    With your example would I be using 5 cogs?

    Thanks,
    Doug
  • hippyhippy Posts: 1,981
    edited 2008-06-25 04:49
    In that case it could be. There's always a compromise, maximum speed and more cogs used or less cogs and slower operation.
  • TimmooreTimmoore Posts: 1,031
    edited 2008-06-25 04:58
    If you are running multiple serial ports and want to save cogs, look for the multiple serial port thread. There is a serial port driver that runs 4 serial ports on 1 cog.
Sign In or Register to comment.