PDA

View Full Version : Changing Baud Rate from within a Program



BobP
- 2nd May 2007, 18:53
Hi,

Have searched and re-read the PBP Manual but can't see the solution!

Using the USART I can't seem to select a Baud rate from within a program.
Am I missing something obvious!!! or can't it be done?
I define the port at the start as shown:

DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_SPBRG 32
DEFINE HSER_CLROERR 1

But any attempt to change these values brings a compiler error.

I had no problems with the software commands SERIN2 or SEROUT2.

Thanks,
Bob

skimask
- 2nd May 2007, 19:20
Hi,
Have searched and re-read the PBP Manual but can't see the solution!
Using the USART I can't seem to select a Baud rate from within a program.
Am I missing something obvious!!! or can't it be done?
I define the port at the start as shown:
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_SPBRG 32
DEFINE HSER_CLROERR 1
But any attempt to change these values brings a compiler error.
I had no problems with the software commands SERIN2 or SEROUT2.
Thanks,
Bob

Change the baud rate generator registers for your particular serial port for your particular PIC directly from within the program...i.e. SPBRG = $90, or whatever...

Charles Linquis
- 2nd May 2007, 21:28
I do this all the time. Just write the appropriate value to the SPBRG register as Skimask suggests.

skimask
- 2nd May 2007, 21:45
I do this all the time. Just write the appropriate value to the SPBRG register as Skimask suggests.

I was just guessing, but thanks for confirming what I was thinking...another tool to use in the future...

BobP
- 2nd May 2007, 22:43
Thanks for the replies. I think my problem was to use the 'DEFINE' statment again.
Will try to update register directly.

Many thanks,
Bob

Darrel Taylor
- 2nd May 2007, 23:21
Hi Bob,

Here's a macro that might help make changing baud rates easier for you.

http://www.picbasic.co.uk/forum/showpost.php?p=10127&postcount=20

HTH,

Added:
Oops, just realized that one was for 18F's only.
Here's one that works on 16F's too...

http://www.picbasic.co.uk/forum/showthread.php?p=17574
<br>

Archangel
- 3rd May 2007, 01:25
Thanks Darrel,
2 more bookmarks and an USART subdirectory in my browser's PBP bookmark directory ! Good tips!

skimask
- 3rd May 2007, 03:56
Thanks Darrel,
2 more bookmarks and an USART subdirectory in my browser's PBP bookmark directory ! Good tips!

No kidding. My bookmark folder is getting fairly large too.