|
|
View previous topic :: View next topic |
Author |
Message |
Will Reeve
Joined: 30 Oct 2003 Posts: 209 Location: Norfolk, England
|
Good way to do 7bits, 2 stop bits |
Posted: Tue Oct 10, 2006 6:43 am |
|
|
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
|
|
Posted: Tue Oct 10, 2006 7:35 am |
|
|
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
|
|
Posted: Tue Oct 10, 2006 8:59 am |
|
|
Thanks, clear in my mind now. Keep well. |
|
|
|
|
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
|