CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Even Parity - Manipulating the 9th bit

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MarcosAmbrose



Joined: 25 Sep 2006
Posts: 38
Location: Adelaide, Australia

View user's profile Send private message

Even Parity - Manipulating the 9th bit
PostPosted: Mon Aug 13, 2007 10:25 pm     Reply with quote

Compiler: PCWH 3.249.
Device: 18F6722

Hi All, I'm using a 18F6722 to talk to a device at 2400bps with even parity.
By opening up the UART in 9 bit mode (see code below) I can reliably recieve data with parity.
Code:
#use rs232(baud=2400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9,Stream=PC)

#int_RDA
RXData()
{
   while(kbhit(PC))
   {
      RX_Buffer[InPointer++]=fgetc(PC);
   }
}


When I transmit data however, if the data contains an even number bits the transmitted data is correct. If however the data contains an odd number of bits, the UART (or putc) pre-pends an 0x3F followed by the data. E.g
Code:
fputc(0x03,PC);   //UART TX's 0x03
fputc(0x02,PC);   //UART TX's 0x3F,0x02
I'm guessing this has something to do with the 9th bit.

Has anyone else encountered this before. I suspect I have to somehow manipulate the 9th bit in the UART to keep the parity correct. If anyone has any thoughts or ideas on this I'd be gratefull to hear them.

-Cheers
Ttelmah
Guest







PostPosted: Tue Aug 14, 2007 5:13 am     Reply with quote

The simple answer, is set the use statemnt up properly for what is wanted at the other end...
Code:

02 send            receive 7bit e   7bit o   7bit n   8bit e   8bit o   8bit n
7bit even   10010000011      02   02(*)   02   82   82(*)   82
7bit odd   10010000001      02(*)   02   02(1)   02   02   02(*)
7bit no      10010000011      02   02(*)   02   82   82(*)   82
8bit even   100100000011      02(*)   02   02(!)   02   02(*)   02
8bit odd   100100000001      02(!)3F   02(*)   02(!)   02(*)   02   02(!)
8bit none   100100000011      02(*)   02   02(!)   02   02(1)   02

Hopefully this will display correctly, but if not, cut and paste it into notepad, using a fixed pitch font.
Hopefully I have got these right...
Now the left hand column, gives what format is being sent. Then the binary pattern generated, then what is received in a number of different formats. The entries marked '*', will have a parity error a the receiving end, while those marked '!', will have a framing error. Note in particular, what is received, by a system expecting 7bits even parity, if you send data using 8bits odd parity, to a system expecting 7bits even parity. Note that this is exactly what is sent, if you select 9bit mode, with the 9th bit set to zero (which since you are not setting it, it is...).
So if you change the use RS232 statement, to:

#use rs232(baud=2400,parity=E,xmit=PIN_C6,rcv=PIN_C7,Stream=PC)

It should start working.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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