Shop OBEX P1 Docs P2 Docs Learn Events
Full Duplex Serial Question — Parallax Forums

Full Duplex Serial Question

TimHTimH Posts: 48
edited 2010-09-22 16:43 in Propeller 1
Hello all.
I want to be able to change the baud rate of the Full Duplex Serial - on the fly.

example:
com1.Start(15,16,0,9600)
"receive data here"
com1.Stop

com1.Start(15,16,0,4800)
"send data here"
com1.Stop

Would this work ? Is there a way to do it without starting and stopping the FDS object.
I want to be able to change the baud rate based on a switch setting.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-20 18:51
    The FullDuplexSerial I/O driver is not written to be able to change the Baud or mode without stopping and restarting the assembly routines involved (in their own cog). The non-buffered serial routines in the BS2 Functions object (in the Object Exchange) can handle changing Baud from character to character as I remember. You could easily set them up to run in a separate cog to get the buffering. Since they're written in Spin, you'd be limited to about 19,200 Baud, but that's usually not a problem.
  • TimHTimH Posts: 48
    edited 2010-09-20 19:03
    Mike

    OK - so keeping with the FDS object (because that seems to work for me), I could start and then stop the FDS object each time I wanted to change the baud rate - how much time would that use ?
    or
    run 2 instances of FDS one at 9600 and one at 4800 baud and call which ever one I needed for that baud rate.
    Is that correct ?
  • anhingusanhingus Posts: 10
    edited 2010-09-20 19:26
    you might be interested in looking at the firmware for vince briel's pocket terminal:

    http://www.brielcomputers.com/wik/images/9/9e/PTfirmware.zip

    full-duplex vt-100 emulation. i bought one - nice piece of work.

    can't see any difference looking at a dipswitch to set baud or pressing a function key as in pocket terminal.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-20 20:30
    It takes about 100us to startup a cog. Everything else needed in your situation is a small fraction of this (stopping existing cog and setting up to startup the cog).
  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-20 20:33
    It won't work to setup two instances of FDS because they're both running and accessing the same I/O pins at the same time. They'll interfere with each other. You really want to either produce a modified version of FDS that can reconfigure itself without stopping and restarting the cog or use a Spin-only routine that reconfigures its delays from character to character.
  • TimHTimH Posts: 48
    edited 2010-09-21 15:40
    OK - I've had some more time playing with this.

    I can get FDS to work on different baud rates for RX and TX just by starting a new instance of FDS when I want to send and then again when I want to receive with no stop used
    So I always TX at 115200 and RX at 9600 but I don't stop the FDS.

    example

    com1.start(18,19,0,115200)

    send some data here

    com1.start(18,19,0,9600)

    receive some data here

    I'm not sure why this works but it does - I wrote the code when I was starting out with the Prop and didn't really know what I was doing and because it worked I had no reason to look at it closely. Anyone have any comments on why this seems to work OK.
    Is it because I'm only using the FDS in simplex mode ie I never receive and transmit at the same time?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-21 15:44
    It works because the .start method calls .stop before it does anything else.

    9600 Baud is one bit every 100us roughly. That's about what it takes to stop and restart FDS ... not bad. At 115200, you're going about 10 times faster. In 100us, you can send or receive one byte. The time it takes to restart FDS is not huge compared to these other actions.
  • TimHTimH Posts: 48
    edited 2010-09-21 16:08
    OK Mike that makes sense now. I can definitely live with 100uS - as you say only 1 bit at 9600. Thanks for all the input.
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-09-22 02:11
    TimH: Is what you want a Rx at 9600 and a Tx at 115200? That is possible using 2 instances of FDX and just reading from the 9600 one and transmitting using the 115200 one.
  • TimmooreTimmoore Posts: 1,031
    edited 2010-09-22 12:20
    The standard fullduplexserial doesn't support only using 1 of rx or tx pin. The 4 port version does allow a pin to be set to -1 if not used.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-22 12:44
    You could use the 4-Port serial driver and setup one port for receiving at 9600 Baud with no transmitting pin (-1) and a second port for transmitting at 115200 Baud with no receiving pin (-1). There'd be only one instance and it would use only one cog and it would do what you want.
  • TimHTimH Posts: 48
    edited 2010-09-22 16:06
    Mike / Cluso99 / Tim

    Because my project was quite small I had a couple of unused pins available, so I used them as "dummy" RX and TX for 2 instances of FDS ... it worked fine. I also have spare cogs so 2 instances of FDS was not a problem on this project.
    The 4 - port serial driver looks like a better way of doing it though so I will start playing with that.
    On another note - is there a serial driver that allows me to change the timing values.
    I have a device that is slightly off on its 9600 baud timing.
    Bit timing for 9600 should be 104 uS - this particular device has a bit timing of around 102 uS. Almost all PC ports work fine with this, but some 4-port pci type cards have problems with it.
    Back in my PIC bit banging days it was able to just change the delay loop for the bit width but and am wondering if any of the serial drivers in the OBEX can do this easily. Only need to go to 9600 baud.

    Tim
  • TimmooreTimmoore Posts: 1,031
    edited 2010-09-22 16:29
    Just set the baud rate to 9800 that should be close to 102us. You can set the baud rate to anything and it calculates the timing needed.
  • TimHTimH Posts: 48
    edited 2010-09-22 16:43
    OK Great - I didn't realize I could enter "non standard" values here.

    Tim
Sign In or Register to comment.