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

Baud rate change

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



Joined: 01 Jan 2007
Posts: 38
Location: Mississauga, Ontario, Canada

View user's profile Send private message

Baud rate change
PostPosted: Thu Feb 10, 2011 10:09 pm     Reply with quote

Hi,

I know how to initialize both hard & soft UARTS on the PIC/CCS platform. I have run into a small problem; I need the ability to change the BAUD rate at one point in my program.

I have a GPS module that by default runs at 9600 baud, however I want to send it a command at 9600 to tell the GPS module to start sending data back to the PIC at a lower baud rate (4800). Once the command is received by the GPS module, my PIC project would then have to slow down to 4800 baud.

Any thoughts on how to code the PIC so the port would then drop to 4800 after all the command issuing business is finished at 9600?
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Feb 10, 2011 10:54 pm     Reply with quote

Hi,

If it's connected to the hardware UART, you can use the Set_UART_Speed(baud) function. For the software UART, just insert another #Use RS232 directive. The code will use the last one prior to outputting data to the GPS.

John
monsters_inc



Joined: 18 Jan 2010
Posts: 14

View user's profile Send private message

PostPosted: Fri Feb 11, 2011 2:02 am     Reply with quote

Hi. for hardware(build-in) uart you can use set_uart_speed (baud, [stream, clock]) to change baud rate.

Best Regards.
Ttelmah



Joined: 11 Mar 2010
Posts: 19503

View user's profile Send private message

PostPosted: Fri Feb 11, 2011 3:11 am     Reply with quote

For software UARTs, you cannot change the baud rate 'on the fly'. The timings are done by tight code loops, with allowances included for the overhead of the read/write instructions, tests etc., all calculated at compile time. Not easy to change.
What you can do, is declare two software UARTs, with different baud rates on the same pins, with different stream names. So:
Code:

#use rs232(baud=9600,parity=N,xmit=PIN_A1,bits=8,stream=SOFT9600)
#use rs232(baud=19200,parity=N,xmit=PIN_A1,bits=8,stream=SOFT19200)

Then just select the required stream for the baud rate you want.

Best Wishes
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