Parity & Stop Bits settings and results


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2017
    Posts
    17

    Default Parity & Stop Bits settings and results

    In my serial application I am setting the second port to 9600 8E1.

    define HSER2_BAUD 9600
    DEFINE HSER2_BITS 9
    define HSER2_EVEN 1
    DEFINE HSER2_CLROERR 1

    These are the only DEFINEs I am using. I am not manually setting HSER2_RCSTA or HSER2_TXSTA.

    What I do not understand is that when I monitor the output using serial port tools like RS232 Analyzer, Teraterm or Termite it doesn't seem to matter what I set those terminal programs to as long as the baud is correct and the databits. The information is received correctly regardless of the settings for parity and stop bits in any of those applications.

    Do I have a misunderstanding of the RS232 protocol? If I set the parity to Even or Odd shouldn't that cause the data to be bad? How about the stop bits?

    I ask because my 18F24K22 will be communicating to an old 386 based PC. An no it isn't the old computer from Hubble. Anyway, that PC will simply not accept any command I send it. I have monitored the communications sent by this PC. If I set the monitor software to 9600 8E1 then the data sent by that 386 is received correctly. If I set it to 8N1 the data displays incorrectly in any of the monitor software. I believe this confirms the 386 pc is using 9600 8E1.

    Am I missing something about how all this works?
    Is there any other way I can better analyze this information?

    Thanks

  2. #2
    Join Date
    Sep 2017
    Posts
    17

    Default Re: Parity & Stop Bits settings and results

    I do want to also ask how does the compiler set the values for baud and parity?
    If I set the TXSTA2 register manually, I think with a 24 then I setting the BAUDCON register can set the baud rate.
    How would one set parity?
    I believe you have to set for 9 bits and the 9th bit is the parity, but does the compiler create all the needed code to calculate the parity and then set the 9th bit accordingly?

    Thanks

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,485

    Default Re: Parity & Stop Bits settings and results

    to use even parity
    Code:
     
    
     DEFINE  HSER_BAUD2 9600
     DEFINE HSER2_CLROERR 1
     
     DEFINE HSER2_TXSTA 60h
     DEFINE HSER2_BITS 9
     DEFINE  HSER2_EVEN 1
    I do want to also ask how does the compiler set the values for baud and parity?
    baud rate is a calculation based on the osc
    parity is done by counting the ones in the data and adding another one if required to make the
    count even or odd as required
    the method can be studied by examining the "prgname".LST file

    I believe you have to set for 9 bits and the 9th bit is the parity, but does the compiler create all the needed code to calculate the parity and then set the 9th bit accordingly?
    yes
    Warning I'm not a teacher

  4. #4
    Join Date
    Sep 2017
    Posts
    17

    Default Re: Parity & Stop Bits settings and results

    Defining HSER2_TXSTA made all the difference. I thought the compiler would set this register according to the defines for the BITS and the EVEN, but apparently not. It also explains why I got poor results without defining that register.

    Thanks

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,485

    Default Re: Parity & Stop Bits settings and results

    I thought the compiler would set this register according to the defines
    me too, with all those defines why leave that crucial piece out . it appears that just the way it is.
    Warning I'm not a teacher

Similar Threads

  1. Config & Oscon settings 16F1825
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th July 2020, 17:18
  2. How to do serial command with 2 stop bits?
    By Pimentel in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2011, 13:44
  3. How to use serout2 command with 4800T82 (2 stop bits)?
    By Pimentel in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st April 2011, 04:15
  4. serout2 with 2 stop bits
    By santamaria in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th December 2009, 06:21
  5. Defining 2 stop bits using HSEROUT
    By yba2cuo3 in forum Serial
    Replies: 1
    Last Post: - 25th September 2006, 13:12

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts