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

Good way to do 7bits, 2 stop bits

 
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

Good way to do 7bits, 2 stop bits
PostPosted: Tue Oct 10, 2006 6:43 am     Reply with quote

Hi all,
I have just been informed that the protocols I need to use for communications to a pc are 7 data bits, 2 stop bits and no parity. Is there an easy way to do this? I am using the hardware USART and transmit seems fine but RX gives 0x80 above the actual character value.
So if the PC sends 0x31 the PIC "received" 0xB1 as you would expect. Is there any reason why I can't just -128 from the incoming byte?

I am rusty on RS232!

Keep well,

Will
Ttelmah
Guest







PostPosted: Tue Oct 10, 2006 7:35 am     Reply with quote

You should set the MSB to '1' on each byte you send. This then gives the required two stop bits.
Asynchronous serial, uses a 'low' as the start bit, followed by the data sent LSB first, and then followed by 'high' bit(s) for the stop(s). The extra 'stop' bit, is then seen as an extra '1' at the end of the character on receipt. To generate the two stop bits, you should send this extra bit as well.
It sounds as if the system is not checking 'framing', so is not giving an error from having a low, instead of a high for the first stop bit, but to be really safe, it is probably better to send it as well.
So to output a character:

putc(c | 0x80);

and to receive the character:

c=getc() & 0x7F;

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: Tue Oct 10, 2006 8:59 am     Reply with quote

Thanks, clear in my mind now. Keep well.
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