View previous topic :: View next topic |
Author |
Message |
domdom
Joined: 06 Sep 2006 Posts: 29
|
Changing the baudrate |
Posted: Mon Oct 22, 2007 7:39 pm |
|
|
Hi all,
I did some search in the forum, but i failed to find any example related to my project.
My PIC will receive a data from a GPS with 9600bps and transmit the data to PC with 4800bps.
How can I change the baudrate in between receive and transmit of the PIC with device?
Thanks! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
grasspuddle
Joined: 15 Jun 2006 Posts: 66
|
|
Posted: Wed Oct 24, 2007 9:20 am |
|
|
It might be easier to use 2 #use commands.
Try:
#use RS232(baud=4800,parity=N,xmit=PIN_C6,bits=8,STREAM=OUT_UART)
#use RS232(baud=9600,parity=N,rcv=PIN_C7,bits=8,STREAM=IN_UART)
Of course, replace the 2 pins with your pins. I haven't tested hardware IO pins before, but it does seem to compile. |
|
|
frequentguest Guest
|
|
Posted: Wed Oct 24, 2007 11:17 am |
|
|
If you don't specify both hardware UART pins in the #use rs232 statement, then it will automatically create a soft UART.
To use the hardware on the PIC, you will have to use the set_uart_speed (baud, [stream, clock]) function to change the hardware UART baud rate.
You can specify two different #use rs232 statements with only one pin each (as grasspuddle suggested), but it won't take advantage of the PIC's hardware UART. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Oct 24, 2007 1:46 pm |
|
|
To clarify: The hardware UART requires both its Xmit and Rec to run at the same baud rate. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
frequentguest Guest
|
|
Posted: Wed Oct 24, 2007 1:58 pm |
|
|
Thanks... It made more sense in my head. |
|
|
grasspuddle
Joined: 15 Jun 2006 Posts: 66
|
|
Posted: Thu Oct 25, 2007 12:58 pm |
|
|
what sherpa said ^^^
use rec for hardware, and try to use another pin for software xmit
receive is important for hardware, but you can usually get away with a software xmit |
|
|
libor
Joined: 14 Dec 2004 Posts: 288 Location: Hungary
|
|
Posted: Thu Oct 25, 2007 2:01 pm |
|
|
GPS sends its data (sentences) only once a second. I suppose you are doing some operation on these data (e.g. logging) and you are also sending them to the PC.
If you make it in a way that you are not receive and transmit at the same time (this is how you would do it anyway, isn't it ?), then you can use the hw usart for both operations switching the speed in between.
(the only caveat here is that the PIC will be deaf to any 9600 bps incoming data while it transmits at 4800, if you make the transmit in the timeframe the GPS is not talking anyway, it will result no drawback) |
|
|
|