If you need to change the baud rate during run time do not use defines. Deal with the registers directly.
Code:X VAR WORD START: RCSTA.4 = 0 : RCSTA.4 = 1 RCSTA=$90:TXSTA=$24:SPBRG=129 HSERIN [dec X] HSEROUT [DEC X.7,13] blah blah
 Re: HSER baudrate
 Re: HSER baudrate
		If you need to change the baud rate during run time do not use defines. Deal with the registers directly.
Code:X VAR WORD START: RCSTA.4 = 0 : RCSTA.4 = 1 RCSTA=$90:TXSTA=$24:SPBRG=129 HSERIN [dec X] HSEROUT [DEC X.7,13] blah blah
Dave
Always wear safety glasses while programming.
 Re: HSER baudrate
 Re: HSER baudrate
		or there's Dave's way . . .
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
 Re: HSER baudrate
 Re: HSER baudrate
		When changing baudrate on the fly, you want to turn off the USART before though.
RCSTA=0
SPBRG=xyz
TXSTA = whatever, assuming it's value change from baudrate to baudrate
RCSTA=$90
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
 Re: HSER baudrate
 Re: HSER baudrate
		Thanks, guys.
Both examples helped me. Just to see which registers should be set. Today I'll try ..
 Re: HSER baudrate
 Re: HSER baudrate
		Get the latest version of my PICMultiCalc on this forum, it will give you a good kick.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
 Re: HSER baudrate
 Re: HSER baudrate
		Everything works great. The calculator has really helped me.
Here's the code if someone needs it.
Code:IF HSerBaud=0 THEN RCSTA = 0 SPBRG = 207 ' 300 Baud @ 4MHz, 0.0% RCSTA = $90 ' Enable serial port & continuous receive TXSTA = $20 ' Enable transmit, BRGH = 0 endif IF HSerBaud=1 THEN RCSTA = 0 SPBRG = 25 ' 2400 Baud @ 4MHz, 0.17% RCSTA = $90 ' Enable serial port & continuous receive TXSTA = $20 ' Enable transmit, BRGH = 0 endif IF HSerBaud=$BD THEN RCSTA = 0 SPBRG = 25 ' 9600 Baud @ 4MHz, 0.16% RCSTA = $90 ' Enable serial port & continuous receive TXSTA = $24 ' Enable transmit, BRGH = 1 endif
 Re: HSER baudrate
 Re: HSER baudrate
		
For safety sake, I would set RCSTA at the end, just after TXSTA.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks