Shop OBEX P1 Docs P2 Docs Learn Events
serial input/output help — Parallax Forums

serial input/output help

beardcmbeardcm Posts: 12
edited 2005-04-11 23:36 in General Discussion
Does anyone know how to alter the following code segment·to change it from 8 data bits and one stop bit to seven data bits and two stop bits.

UART1
rs232Transmit
··_bank·rs232TxBank··;2 switch to serial register bank

··sb ·rs232Tx1FLag··;1
··jmp·rs232Receive1··;1
··decsz·rs232Tx1Divide··;1 only execute the transmit routine
··jmp·rs232Receive1··;1
··mov·w,#UARTDivide1··;1 load UART1 baud rate (50MHz)
··mov·rs232Tx1Divide,w·;1·
··test··· rs232Tx1Count··;1 are we sending?
··snz····;1·
··jmp·rs232Receive1··;1
:txbit··clc···························· ;1 yes, ready stop bit
··rr····· rs232Tx1High··;1· and shift to next bit
··rr····· rs232Tx1Low··;1·
··dec···· rs232Tx1Count··;1 decrement bit counter
··snb·rs232Tx1Low.6··;1 output next bit
··clrb·rs232TxPin1··;1·
··sb·rs232Tx1Low.6··;1·
··setb·rs232TxPin1··;1·
··test··· rs232Tx1Count··;1 are we sending?
··snz····;1·
··clrb·rs232Tx1Flag··;1,22
rs232Receive1
··_bank·rs232RxBank··;2
········ sb·rs232RxPin1··;1 get current rx bit
········ clc····;1·
········ snb·rs232RxPin1··;1·
········ stc····;1·
··test··· rs232Rx1Count·········· ;1 currently receiving byte?
··sz····;1·
··jmp·:rxbit················· ;1 if so, jump ahead
··mov···· w,#9··················· ;1 in case start, ready 9 bits
··mov···· rs232Rx1Count,w··;1 it is, so renew bit count
··mov···· w,#UARTStDelay1··;1 ready 1.5 bit periods (50MHz)
··mov···· rs232Rx1Divide,w·;1·
:rxbit········· decsz·rs232Rx1Divide··;1 middle of next bit?
········· ·jmp·:rs232RxOut1··;1
··mov·w,#UARTDivide1··;1 yes, ready 1 bit period (50MHz)
··mov·rs232Rx1Divide,w·;1·
··dec···· rs232Rx1Count·········· ;1 last bit?
··sz····························· ;1 if not
··rr····· rs232Rx1Byte··········· ;1· then save bit
··snz···························· ;1 if so,
··setb··· rs232Rx1Flag·········· ;1,23· then set flag
:rs232RxOut1

Comments

  • PJMontyPJMonty Posts: 983
    edited 2005-04-11 23:36
    Beardcm,

    When you are transmitting, you just need to make sure that the most significant bit of the data is high. I think. It may need to be low. Confused? Well it's just that I can't remember off the top of my head whether the raw data from the UART has stop bits as low or high. This is something you can easily research for yourself via Google. The trick is that the data comes out of the UART one way, and then the level convertors invert the entire data stream. On the receiving end, the data is inverted again and than sent to the UART there.

    Anyway, the point is that sending 7 data bits and 2 stop bits is the same as sending 8 data bits and 1 stop bit except that the first of the two stop bits is just stuffed into the data itself. The key is that you're still sending the same number of bits, so no modification is needed for the UART code.

    As for the receiving code, it's going to be the exact same thng. You're receiving the same number of bits whether it's 8 data and 1 stop or 7 data and 2 stop bits. All you have to do is mask off the high bit (which your sender considers the first of 2 stop bits) and you're in business.
      Thanks, PeterM
Sign In or Register to comment.