Shop OBEX P1 Docs P2 Docs Learn Events
Simple Serial Maximum Delay — Parallax Forums

Simple Serial Maximum Delay

tpw_mantpw_man Posts: 276
edited 2008-07-30 17:08 in Propeller 1
What is the maximum delay in clock cycles that I can wait with Simple Serial before I miss a byte? I am doing this at 80 MHz and 19.2K baud. Do I have to do an unrolled loop, or can I wait a few dozen spin instructions before I will miss the byte?
I will do something like this:

repeat until ser.rx == "!"
repeat 2
  buffer := ser.rx
if compare(@buffer, string("HI"),2)
  repeat 50



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I am 1011, so be surprised!


Advertisement sponsored by dfletch:
Come and join us on the Propeller IRC channel for fast and easy help!
Channel: #propeller
Server: irc.freenode.net or freenode.net
If you don't want to bother installing an IRC client, use Mibbit. www.mibbit.com
tongue.gif

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-30 16:10
    Simple Serial works much like the Stamp serial input statement. It starts reception of a character at the beginning of the start bit and finishes after the middle of the last data bit. Ideally, it should test for a valid stop bit by waiting until the middle of the 1st or only stop bit, but it doesn't. As a result, there's about 1.5 bit times available until the next start bit may come along. At 19.2KBaud, that's roughly 75us. Considering that it takes quite a few spin byte code instructions to actually do the call to ser.rx before the input pin is examined, you don't really have much time. I would strongly suggest that you use FullDuplexSerial instead. Because it's written in assembly, it can handle much higher Bauds (up to 230KBaud) and it's buffered as well which gives you plenty of time to process the incoming data.
  • tpw_mantpw_man Posts: 276
    edited 2008-07-30 16:15
    I cannot use FullDuplexSerial because I need RX and TX pin to be the same. I am kinda thinking of a hybrid between SimpleSerial and FullDuplexSerial, so the input is buffered, but the input buffering/receiving is disabled when transmitting.

    EDIT: Would my idea work?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I am 1011, so be surprised!


    Advertisement sponsored by dfletch:
    Come and join us on the Propeller IRC channel for fast and easy help!
    Channel: #propeller
    Server: irc.freenode.net or freenode.net
    If you don't want to bother installing an IRC client, use Mibbit. www.mibbit.com
    tongue.gif

    Post Edited (tpw_man) : 7/30/2008 4:28:24 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-30 16:43
    Your idea would work. You would have a buffered serial I/O object, but one written completely in Spin that starts a Spin cog to do the actual I/O. You could use the Spin part of FullDuplexSerial, just use the Simple Serial routines plus your own code to put the data into the buffer or remove it from the transmit buffer.

    You would need some variable that is TRUE if in transmit mode or FALSE if in receive mode and the Spin cog that's actually doing the I/O would check this variable before starting the next character and choose either the transmit or receive routine to do next (and switch the direction of the I/O pin appropriately). If it's in transmit mode, the receive buffer will not get filled. If it's in receive mode, the transmit buffer will not get emptied. You'll want to add some kind of error checking so the tx routine won't continue to wait if the transmit buffer is full and it's in receive mode. Similarly, you'll want to make sure the receive routine won't continue to wait if the receive buffer is empty and it's in transmit mode.
  • TimmooreTimmoore Posts: 1,031
    edited 2008-07-30 17:08
    You could try using fullduplexserial and setting the tx to be open collector (with a pullup), then you shold be able to use the same pin for tx and rx.
Sign In or Register to comment.