Shop OBEX P1 Docs P2 Docs Learn Events
Strange happenings in FullDuplexSerial — Parallax Forums

Strange happenings in FullDuplexSerial

william chanwilliam chan Posts: 1,326
edited 2009-07-29 15:32 in Propeller 1
I don't know why, but when I change the receive buffer size from 16 to 24 bytes, the transmitted bytes using the 2 transistor circuit become erratic.
When I change both buffer sizes back to 16, the transmit works well.
Should the buffer sizes be multiples of a certain number?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my

Comments

  • BradCBradC Posts: 2,601
    edited 2009-07-20 13:39
    william chan said...
    I don't know why, but when I change the receive buffer size from 16 to 24 bytes, the transmitted bytes using the 2 transistor circuit become erratic.
    When I change both buffer sizes back to 16, the transmit works well.
    Should the buffer sizes be multiples of a certain number?

    Aside from changing those numbers in the tx & rx buffer size, what other changes did you make to the object to let it properly mask and wrap the buffers?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <This space for rent>
  • Nick MuellerNick Mueller Posts: 815
    edited 2009-07-20 14:11
    Full duplex serial only takes powers of two and you'll have to tweek the ASM to to get rid of the magic numbers.


    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • william chanwilliam chan Posts: 1,326
    edited 2009-07-21 07:58
    Thanks nick.
    That was the answer I needed.

    I think there should be a comment near the buffer settings to warn the user to use only powers of two.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • william chanwilliam chan Posts: 1,326
    edited 2009-07-29 10:09
    I am really confused now....
    I am running Propeller at 40mHz and 19.2k baud.

    I set both the receive and transmit buffers to 32 bytes each.
    The transmit no longer works. Isn't 32 a magic number?

    I set both buffers back to 16 bytes and everything works again.
    I double checked and triple checked.

    What could be wrong?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • Nick MuellerNick Mueller Posts: 815
    edited 2009-07-29 10:28
    Did you change the magic numbers?
    It's not enough just to change the buffer size, you'll also have to look for the masks ($F)!

    Frankly speaking, thats an example of very bad coding-sytle. Instead of declaring a single constant like bufferLen = 16, there are several incarnations with some deviation that could be derived from that constand (for example "bufferLen - 1").

    "Magic Numbers":
    The meaning is, that there are pure numbers spread in the code that aren't depending on some constant. In this example, it's the number "16" or the matching mask $F


    > 40mHz

    Thats damned slow! wink.gif


    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO

    Post Edited (Nick Mueller) : 7/29/2009 10:35:33 AM GMT
  • JonnyMacJonnyMac Posts: 9,197
    edited 2009-07-29 14:54
    The attached update seems to work fine. I marked all the lines (8 of them) I changed (with *) -- it's possible you may have missed one or two when you attempted the update.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-29 15:19
    There are several "improved" versions of FullDuplexSerial that use named constants for the "magic" values so make it easy to change the buffer sizes to other powers of two. There's also a serial driver that uses cog memory for the buffers.
  • Nick MuellerNick Mueller Posts: 815
    edited 2009-07-29 15:32
    Here's a better explanation than mine:
    <http://en.wikipedia.org/wiki/Magic_number_(programming)#Unnamed_numerical_constants&gt;


    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
Sign In or Register to comment.