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

Changing the baudrate

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



Joined: 06 Sep 2006
Posts: 29

View user's profile Send private message

Changing the baudrate
PostPosted: Mon Oct 22, 2007 7:39 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Oct 23, 2007 10:17 am     Reply with quote

For the hardware UART, use the setup_uart() function. It's in the manual.
For software UART, see this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=31754
grasspuddle



Joined: 15 Jun 2006
Posts: 66

View user's profile Send private message

PostPosted: Wed Oct 24, 2007 9:20 am     Reply with quote

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







PostPosted: Wed Oct 24, 2007 11:17 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Oct 24, 2007 1:46 pm     Reply with quote

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







PostPosted: Wed Oct 24, 2007 1:58 pm     Reply with quote

Thanks... It made more sense in my head.
grasspuddle



Joined: 15 Jun 2006
Posts: 66

View user's profile Send private message

PostPosted: Thu Oct 25, 2007 12:58 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Oct 25, 2007 2:01 pm     Reply with quote

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)
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