|
|
View previous topic :: View next topic |
Author |
Message |
maxrate
Joined: 01 Jan 2007 Posts: 38 Location: Mississauga, Ontario, Canada
|
Baud rate change |
Posted: Thu Feb 10, 2011 10:09 pm |
|
|
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
|
|
Posted: Thu Feb 10, 2011 10:54 pm |
|
|
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
|
|
Posted: Fri Feb 11, 2011 2:02 am |
|
|
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
|
|
Posted: Fri Feb 11, 2011 3:11 am |
|
|
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 |
|
|
|
|
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
|