|
|
View previous topic :: View next topic |
Author |
Message |
mauro Guest
|
Serial communications and stop bits |
Posted: Thu Dec 16, 2004 3:48 am |
|
|
Hi
Is there a way to set the number of stop bits in serial
communications? Apparently, with high baud rates (115200)
I loose the communication with my device (who uses
a 2 stop bits protocol, while PIC uses 1). Lower baud
rates (9600) are much better (almost 90% of success in
sending messages) but I need to switch to 115200
Thanks in advance, ciao!
mauro |
|
|
Ttelmah Guest
|
Re: Serial communications and stop bits |
Posted: Thu Dec 16, 2004 4:09 am |
|
|
mauro wrote: | Hi
Is there a way to set the number of stop bits in serial
communications? Apparently, with high baud rates (115200)
I loose the communication with my device (who uses
a 2 stop bits protocol, while PIC uses 1). Lower baud
rates (9600) are much better (almost 90% of success in
sending messages) but I need to switch to 115200
Thanks in advance, ciao!
mauro |
There is one way of 'cheating' this.
The UART on the PIC, only supports one stop bit. However it supports 9bit comms. If you set the ninth bit, this gets sent as another 'high' bit before the single stop bit, generating effectively two stop bits. The chip will then receive the extra stop bit as the ninth data bit, which can be ignored.
Set the UART up to use 9bit comms, and when you would call 'putc', instead call a 'wrapper' function, like:
Code: |
#bit ninth_bit = RS232_ERRORS.7
void putc9(int8 val) {
ninth_bit=1;
putc(val);
}
|
This then ensures the ninth bit is set for each byte, and generates the required effect.
Best Wishes |
|
|
mauro Guest
|
Re: Serial communications and stop bits |
Posted: Thu Dec 16, 2004 7:33 am |
|
|
Ttelmah wrote: |
There is one way of 'cheating' this.[...]
|
thank you very much, it works perfectly!
I had already tried the 9-bit data solution but hadn't
managed to get it working...
ciao and thanks again
mauro |
|
|
Ttelmah Guest
|
|
Posted: Thu Dec 16, 2004 9:37 am |
|
|
Glad it worked. :-) |
|
|
|
|
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
|