Shop OBEX P1 Docs P2 Docs Learn Events
Parity Bits Making Me Punchdrunk... (PASM) -- Problem May Be With BST Serial Terminal — Parallax Forums

Parity Bits Making Me Punchdrunk... (PASM) -- Problem May Be With BST Serial Terminal

JonnyMacJonnyMac Posts: 9,235
edited 2011-09-26 17:31 in Propeller 1
I wrote a simple, half-duplex serial object for RS-485 apps (it enables/disables the transmitter output as required) and it works just great with no parity (8N2). Today I decided I would add Odd (8O1) and Even (8E1) parity so that I could use a derivative object in a MODBUS project (MODBUS spec *requires* even parity).

I'm getting punchy and could use a second set of eyes. Given the tools in PASM this should be pretty simple -- I'm sure it is but I'm missing something. In the terminal window of BST I get "EFX-????" instead of "EFX-TEK"

This the PASM code for the transmitter; again, it works in No parity mode, but odd and even trash parts of my output.
txserial                rdlong  tmp1, txheadpntr                ' tmp1 = txhead
                        rdlong  tmp2, txtailpntr                ' tmp2 = txtail
                        cmp     tmp1, tmp2              wz      ' byte(s) to tx?
        if_nz           jmp     #txenable                       ' yes, enable transmitter

txdisable               andn    outa, txemask                   ' no, disable transmitter
                        jmp     #rxserial                       ' check rx

txenable                test    txemask, ina            wc      ' already enabled?
        if_c            jmp     #gettxbuf                       ' yes, skip txe delay

                        or      outa, txemask                   ' enable transmit
                        mov     txtimer, txetix                 ' set timer
                        add     txtimer, cnt                    ' start it
                        waitcnt txtimer, #0                     ' let timer expire

gettxbuf                mov     tmp1, txbufpntr                 ' tmp1 := @txbuf[0]
                        add     tmp1, tmp2                      ' tmp1 := @txbuf[txtail]
                        rdbyte  txwork, tmp1                    ' txwork := txbuf[txtail]

updatetxtail            add     tmp2, #1                        ' inc txtail
                        and     tmp2, #BUF_MASK                 ' wrap to 0 if necessary
                        wrlong  tmp2, txtailpntr                ' save

txparity                or      txwork, STOP_BITS       wc      ' c = 1 if odd bits
                        cmp     pmode, #0               wz      ' parity = none?
        if_z            jmp     #transmit                       ' yes, ready to go

                        cmp     pmode, #1               wz      ' z = 1 for odd parity
        if_z            muxnc   txwork, PARITY_BIT
        if_nz           muxc    txwork, PARITY_BIT

transmit                shl     txwork, #1                      ' add start bit
                        mov     txcount, #11                    ' start + 8 data + parit + stop
                        mov     txtimer, bit1x0tix              ' load bit timing
                        add     txtimer, cnt                    ' sync with system counter

txbit                   shr     txwork, #1              wc      ' move bit0 to C
                        muxc    outa, txmask                    ' output the bit
                        waitcnt txtimer, bit1x0tix              ' let timer expire, reload
                        djnz    txcount, #txbit                 ' update bit count
                        jmp     #txserial

' -------------------------------------------------------------------------------------------------

STOP_BITS               long    %11_0000_0000                   ' for no parity
PARITY_BIT              long    %01_0000_0000

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-09-26 16:38
    Jon,

    Your code does SET and CLEAR parity, rather than EVEN and ODD parity. For the latter, you have to count the number of one bits in the data, and set or clear the parity bit so the total number of ones is even or odd.

    -Phil
  • JonnyMacJonnyMac Posts: 9,235
    edited 2011-09-26 16:38
    Hmmm.... for grins I tried my demo using the BASIC Stamp terminal window with Even parity and 8 bits set -- it works. Unfortunately, the Stamp Terminal doesn't have an Odd parity setting for me to test with.
  • JonnyMacJonnyMac Posts: 9,235
    edited 2011-09-26 16:44
    For the latter, you have to count the number of one bits in the data, and set or clear the parity bit so the total number of ones is even or odd.

    I'm pretty sure that's what's happening. This line:
    txparity                or      txwork, STOP_BITS       wc      ' c = 1 if odd bits
    

    arbitrarily adds two stop bits and if the 1s in the result is odd, C will be set. This line sets Z to 1 if the parity is Odd
    cmp     pmode, #1               wz      ' z = 1 for odd parity
    

    If I have Odd parity (Z == 1) and and odd # of bits (C == 1), I want to set the parity bit to 0, and vice-versa, correct. Doesn't this code do this?
    if_z            muxnc   txwork, PARITY_BIT
            if_nz           muxc    txwork, PARITY_BIT
    
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-09-26 17:02
    Aaach! I missed the detail with the OR doing the parity computation. Sorry.

    -Phil
  • JonnyMacJonnyMac Posts: 9,235
    edited 2011-09-26 17:07
    This reminds me of the time I swapped out a regulator only to find that the battery in my meter was bad! I tried another terminal program and, cha-ching!, the code seems to work.
    1024 x 640 - 90K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-09-26 17:13
    'Glad you got it working. Not all terminal programs support 8 bits plus parity. For plain-vanilla ASCII, I think it's usually 8 bits including parity. The BST terminal probably croaked when it saw the wrong parity in bit 7 or a 0 parity bit where it was expecting a stop bit.

    -Phil
  • JonnyMacJonnyMac Posts: 9,235
    edited 2011-09-26 17:31
    BST allows you to configure the data bits and parity separately; this is why I assumed the problem was on my end. Now to get the receiver (with parity) working.

    [ Update ] Both sides of the driver code (tx and rx) work fine with the Termite terminal program that I found on the 'net; TX portion still blows up in BST so I'm hoping Brad can have a look at that.
Sign In or Register to comment.