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
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
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
Quote:
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
Quote:
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
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
Re: Parity & Stop Bits settings and results
Quote:
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.