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

RS232 7-bits communications

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



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

RS232 7-bits communications
PostPosted: Mon Sep 01, 2008 6:29 am     Reply with quote

Hi all,
RS232 working well with bits=8, however I need bits=7. I set the PC to use 7 bits, I use the bits=7 in #use rs232 but get garbage. I am missing something obvious before I get the oscilloscope out!
Keep well.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Sep 01, 2008 7:17 am     Reply with quote

The obvious thing is, to my opinion, 7-Bit has to be supported by the chip. PIC processors don't.

That means, 7-Bit data has to be received as 8-Bit data. This can only work, if the sender is using either parity or two stop bits (or leaves a gap of 1 Bit length between characters). If this prerequisites are met, some mask action may be necessary, but it can work at least.


Last edited by FvM on Mon Sep 01, 2008 10:09 am; edited 2 times in total
Ttelmah
Guest







PostPosted: Mon Sep 01, 2008 8:49 am     Reply with quote

Yes.
A search here will find quite a few posts about this.
The 'key' is that if you want parity (say 7,E,1), you can send '8,N,1', from the PIC, and generate your own parity bit into the eighth bit, or set the eighth bit, to just generate an extra stop (nothing will normally 'mind' having an extra stop bit). The compiler has at times had various attempts a doing this for you, but with various degrees of success, so 'DIY', is probably safer...

Best Wishes
Will Reeve



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Thu Nov 06, 2008 3:49 pm     Reply with quote

Thanks, 7bits Even parity and 1 stop is what is required...there must be a better way than:

for (i=0;i<7;i++)
if (bit_test(txbyte,i)) parity++;
if (parity) bit_set(txbyte,7);

but I can't think of one at the moment! Any cheats for parity calculation?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Nov 06, 2008 5:45 pm     Reply with quote

If speed of parity calculations is an issue, use a table. It will mainly require 128 bytes of program memory and contains the precalculated data with parity for any 7 bit combination.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 06, 2008 5:53 pm     Reply with quote

There is a parity calulator routine here:
http://www.ccsinfo.com/forum/viewtopic.php?t=21363&start=1

The ASM code comes from Piclist:
http://www.piclist.com/techref/microchip/math/bit/parity.htm
Will Reeve



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Fri Nov 07, 2008 3:30 am     Reply with quote

Thanks, neat code.
One last question. I use printf quite a bit to pipe stuff out of the SCI.
I seem to remember there is a way to direct this through the 7bit parity function and then on to a putc? Is this possible?
Ttelmah
Guest







PostPosted: Fri Nov 07, 2008 3:51 am     Reply with quote

Yes.
Just have a parity function like:
void putc_parity(int8 val)

and call printf, with:

printf(putc_parity,"what I want to send");

The characters will each be sent in turn to your putc, and this can call the 'syste' version.

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