Menu

R: [gcbasic:discussion] Software Serial TX baud rates are incorrect.

Max
2014-06-25
2014-06-25
  • Max

    Max - 2014-06-25

    William
    this is a peace of code that work on serial SW ; i tested with cable USB to
    Serial
    (prolific chip).
    I do not why but if i use:

    define SendAHigh Set SerOutPort On

    define SendALow Set SerOutPort Off

    define RecAHigh SerInPort On

    define RecALow SerInPort Off

    InitSer 1, r9600, 1 + WaitForStart, 8, 1, none, normal

    doesn't work and if I use this IT WORK

    define SendAHigh Set SerOutPort Off

    define SendALow Set SerOutPort On

    define RecAHigh SerInPort Off

    define RecALow SerInPort On

    InitSer 1, r9600, 1 + WaitForStart, 8, 1, none, invert

    any idea ?

    this is a peace of code that work on serial SW

    ;Chip Settings

    chip 16F876A,20

    config OSC=HS

    'Serial settings

    define SerOutPort PORTB.0

    define SerInPort PORTB.4

    ;Chip Settings

    chip 16F876A,20

    config OSC=HS

    'Serial settings

    define SerOutPort PORTB.0

    define SerInPort PORTB.4

    define SendAHigh Set SerOutPort Off

    define SendALow Set SerOutPort On

    define RecAHigh SerInPort Off

    define RecALow SerInPort On

    ;Set pin directions
    Dir SerOutPort Out
    Dir SerInPort In

    ;Variables

    dim RX_DATO as byte

    InitSer 1, r9600, 1 + WaitForStart, 8, 1, none, invert

    'with out this line after reset the first char is dirty
    Set SerOutPort On

    ;Interrupt Handlers
    'interupt work only port B 0 4 5 6 7
    On Interrupt PORTBChange Call serial_in

    start:
    goto start

    Sub serial_in
    serReceive 1, RX_DATO
    SerSend 1, RX_DATO
    End Sub

    ########################################################à

    Massimo

    ----Messaggio originale----
    Da: williamroth@users.sf.net
    Data: 25/06/2014 1.58
    A: "[gcbasic:discussion] "596084@discussion.gcbasic.p.re.sf.net
    Ogg: [gcbasic:discussion] Software Serial TX baud rates are incorrect.

    When Using a both a PIC16F684 and PIC 16F690 when the baud rate is set for
    9600 the actual TX baud rate is ~10,500. This represents an error of about %10
    and is too high for most devices work with when set to 9600 baud,
    To temporarily work around this, I tracked (at least part of the problem) to
    the
    RS232.h library in the script where "SerFullDelay" is calculated. I changed
    the formula:
    From: SerFullDelay9600 = int(104 - 4 / ChipMHz * 50)
    To: SerFullDelay9600 = int(104 - 4 / ChipMHz * 38)
    This got the 9600 baud rate pretty close as reported by Saleae Logic, with the
    bit times between 103 to 105us. This only corrected the 9600 TX rate.
    I also noticed a comment in the rs232.h file that says:
    'Bit rate delays Moved to stdbasic.h'r* is us delay/52 for 1 bit
    So I looked in stdbasic.h and found this in the script:
    'Bit rate delays #define r300 64 #define r600 32 #define r1200 16 #define
    r2400 8 #define r4800 4 #define r9600 2 #define r19200 1 'Number to multiply
    above by to get correct delay length (us) #define rBitRateUnit 52
    I searched all of the files in the GCBASIC directory and could not find any
    other occurrences or references to "rBitRateUnit" in any other files, so my
    best guess is that this group of lines is not doing anything.
    Changing the value from 52 to 40 had no effect at all upon serial data TX.
    Software Serial TX baud rates are incorrect.
    Sent from sourceforge.net because you indicated interest in https:
    //sourceforge.net/p/gcbasic/discussion/596084/
    To unsubscribe from further messages, please visit https://sourceforge.
    net/auth/subscriptions/

     
  • William Roth

    William Roth - 2014-06-25

    When "Normal" is used in "initSer" , the data is incorrect.

    "Invert" must always be used in "initSer".

    Even with normal or true RS232, if the signal needs to be inverted RS232, the serial data must be inverted by swapping the values of define SendAHigh and define SendALow.

     

    Last edit: William Roth 2014-06-25

Log in to post a comment.