Full-Duplex Serial handshaking
William50
Posts: 22
I need to add a handshaking command to the FDS object to signal to the sending serial device to stop sending because the Prop's buffer is full.
I have not decided whether I will be using hardware (CTS) or software (x-on/x-off) handshaking.
Could someone point out where I can add a test in FDS to determine the position of the receive buffer pointer in relation to the buffer size?
I want to either send an x-off command (or set an output pin to low) when the buffer is full and send an x-on command (or output pin high) when the buffer is say 80% empty.
I have not decided whether I will be using hardware (CTS) or software (x-on/x-off) handshaking.
Could someone point out where I can add a test in FDS to determine the position of the receive buffer pointer in relation to the buffer size?
I want to either send an x-off command (or set an output pin to low) when the buffer is full and send an x-on command (or output pin high) when the buffer is say 80% empty.
Comments
Right after the "receive" label and its jmpret instruction in the assembly code would be the place to put a test for the space left in the buffer and to clear or set CTS based on that. This would be executed between characters when the routine is waiting for a start bit.
I have increased the buffer size to 512 bytes but the serial data comes in quicker than it is processed.
Could you provide some sample code to toggle an output pin to high when the buffer is 50% full and toggle low when full.
Tnx.
At what percentage the signal should be sent really depends on how fast the buffer gets filled, but starting with 75% might be good.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
www.norfolkhelicopterclub.co.uk
You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
BTW: I type as I'm thinking, so please don't take any offense at my writing style
The code to turn CTS off has to be in the assembly language section since that's what is filling the buffer and incrementing the pointer. You theoretically could put the code to turn CTS on either in the assembly language or in the Spin routine that empties the buffer (rxcheck), but it's easier to just turn CTS on when it's not off and that way only one cog is trying to control CTS.
Here's a rough outline of what you might need. You might want it to be more complicated, like to add some hysteresis where you turn off CTS when the buffer becomes 3/4 full, but only turn on CTS when the buffer is 1/2 empty for example. If you want to use x-off / x-on, it becomes more complicated. You would like to "insert" the x-on / x-off ahead of the transmit buffer contents, so you'd need to have a flag for each that the transmit routine would check before fetching a byte from the buffer, "fetch" the x-on / x-off, and reset the flag.
Just one question: What should "bufferMask" be set to ?
Have a look at the FullDuplexSerial object in BoeBotBasic (from the Object Exchange). It already has been modified for variable size buffers with all the constant masks changed to named constants.
I have already successfully increased the buffer to 512 bytes but I will take a look at the object you mentioned.