PDA

View Full Version : Is it possible To change baud rate at runtime?



Alberto
- 12th April 2017, 11:19
I need to change The baud rate from 9600 to 115200 and then back to 9600. I did try with define but PBP3 does'nt like it and gives error at compiling. Is there a way To do the baud Switching from 9600 To 115200 and back To 9600? How?

Thank you for any help.

Alberto

HenrikOlsson
- 12th April 2017, 12:45
Absolutely. But you can't use DEFINE because it's a compile time thing.
You can skip the DEFINE altogether and do it manually all the way, what to set the registers to depends on the oscillator speed. For example, setting 9600 baud when running at 8MHz:

RCSTA = $90
TXSTA = $20
SPBRG = 51
SPBRGH = 0
BAUDCON.3 = 1

/Henrik.

Alberto
- 12th April 2017, 15:38
Thank you Henrik, very kind of you.

Alberto