Page 1 of 1
RS232 with different baud rates
Posted: Fri Dec 09, 2011 11:54 am
by Jan Lichtenbelt
I want to use RS232 with starting at 38400 baud rate. But later on in the program I want to change the baud rate to 19200. How can I realise that?
Kind regards
Jan Lichtenbelt
Re: RS232 with different baud rates
Posted: Fri Dec 09, 2011 9:49 pm
by Dan81
Hello Jan
That is for a Hardware solution.
When you want to change the baud rate :
Put a 'C code" icon with :
spbrg = ?? ;
If you want to know the value of ?? :
With the right value of the Quartz frequency. (19.66MHz for a Matrix board)
In the RS232 properties : choose 19200
then
- Chip / Compile to C
- Chip /View C
- search : " SPBRG_VAL "
- the answer will be something like :
. #define RS232_8520508_SPBRG_VAL 69 (here for 19.66MHz)
- replace ?? by your value (here 69)
Then put again 38400 in the RS232 properties.
Be sure that all datas have been sent before changing "spbrg"
Daniel
Re: RS232 with different baud rates
Posted: Sat Dec 10, 2011 8:38 pm
by Jan Lichtenbelt
Dear Daniel
Thanks a lot. This made me to start to look more in detail RS232.
I found the follwoing:
1) The Baud Rate Generator SPBRG can be calculated from the figure below (from datasheet of 12F1840)

- SPBRG.jpg (38.17 KiB) Viewed 2783 times
2) The High Baud Rate Select bit (bit2 of TXSTA register) must be set for baud rates >= 4800. In that case set in C-code: txsta= 0x04; else txsta=0;
3) In my case I found an other difference in the bitbanched baud rates. The bitbanched BAUT Rate Delay is for baud rate >=2400 equal to 998400/baudrate. (for baudrate 1200 this delay is 833). How to change this value in C-code is not clear to me. Perhaps changing the value RS232_66470_SW_BAUD, but I do not know what the meaning is of 66470 values and if this one does not change in other applications (microcontrollers).
Kind regards,
Jan