|
|
View previous topic :: View next topic |
Author |
Message |
micro
Joined: 10 Sep 2003 Posts: 13
|
rs232 stream parity bit problem in 18f8720 |
Posted: Mon Feb 07, 2005 8:29 am |
|
|
I wrote a simple code snipped for 18f8720 like below. Although I mentioned "Odd Parity" in built in definition , output data has not odd parity. How do I send data with odd parity ?
#use rs232 (baud=9600, PARITY=N, xmit=PIN_C6, rcv=PIN_C7,ERRORS,stream = PORT1)
#use rs232 (baud=9600, PARITY=O, xmit=PIN_G1, rcv=PIN_G2,ERRORS,stream = PORT2)
void main()
{
while(1)
{
fputc(0x25,PORT2);
}
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 07, 2005 12:51 pm |
|
|
I looked at the ASM code generated by the compiler for your example.
It sends out 9 bits of data. The first 8 bits are the data byte, and the
9th bit is the parity bit.
Remember that for Odd parity, if the parity of your data byte is odd,
then the parity bit will be set = 0. If the parity of your data byte
is even, then the parity bit is set = 1. In other words, the value
of the parity bit is set so that the overall parity of the 9-bit stream is odd.
Your data is 0x25, which has three 'one' bits, which is odd parity.
So the the 9th bit will be set = 0, in order to make the parity of the
entire 9-bit stream be odd.
I used PCH vs. 3.188 to compile the code for a 18F8720 for my tests.
----------
Does this explanation help, or were you possibly expecting the compiler
to generate 7 bits of data and use the 8th bit for parity ? |
|
|
micro
Joined: 10 Sep 2003 Posts: 13
|
I tried this |
Posted: Wed Feb 09, 2005 1:02 am |
|
|
When I wrote this code snipped, I tried it using a PC sw that observes the PC's COM port. The PIC programmed with this code sends the string I want and my PC sw is set 9600,odd parity,8 bit data 1 stop bit. In this condition, I realise that some data in string sometimes corrupts. For example When I send a stream like (0x50, 0x20 ,0xFA), stream sometimes appear like (0x3F 0x20 0xFA). But If I use none parity option in PC sw (a kind of terminal program etc.), all stream looks like allways as it should be and correct. How can I explain and take over this problem ?? |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|