Searching \ for '[PIC]: changing baud rate' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'changing baud rate'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: changing baud rate'
2001\03\11@125409 by Sandy Phelps

flavicon
face
Hello PIC people,
I don't seem to be having much success with changing the baud rate in a
16F877 using the
built-in USART. From all the info I could gleam the following code should do
it.
I tried starting with 1200 baud and it works. The code starts out at 9600
baud and when I send
a command to change to 1200 (and change my program on the PC to use 1200) it
just doesn't
respond.
Using the simulator, I can see that SPBRG does change to the new value.
Anyone who has made this work please assist.
Regards,
S. Phelps

baud_1200
   ; ----------------------------------------------------
   ; Reset the baud rate to 1200.
   ; SPBRG = 207d.
   ; ----------------------------------------------------
   bsf STATUS, RP0 ; select bank 1
   movlw b'11000000' ; set portc direction
   movwf TRISC & 0x07f

   movlw d'207' ;spbrg value for 1200 baud
   movwf SPBRG & 0x07f

   movlw 0x22
   movwf TXSTA & 0x07f

   bcf STATUS, RP0 ;select bank 0
   movlw 0x90
   movwf RCSTA & 0x07f

   return

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2001\03\11@170712 by Tony Nixon

flavicon
picon face
Sandy Phelps wrote:
>
> Hello PIC people,
> I don't seem to be having much success with changing the baud rate in a
> 16F877 using the
> built-in USART. From all the info I could gleam the following code should do
> it.
>
> baud_1200
>     ; ----------------------------------------------------
>     ; Reset the baud rate to 1200.
>     ; SPBRG = 207d.
>     ; ----------------------------------------------------
>     bsf STATUS, RP0 ; select bank 1
>     movlw b'11000000' ; set portc direction
>     movwf TRISC & 0x07f



RC6 is supposed to be an output during UART enable (Tx).

    movlw b'10000000' ; set portc direction

Not sure whether this will fix the problem because I think the TRIS bits
are overridden when the UART is enabled.

Do you need to change the BRGH bit?

--
Best regards

Tony

mICro's
http://www.picnpoke.com
.....salesKILLspamspam@spam@picnpoke.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2001\03\11@200546 by Sandy Phelps

flavicon
face
Seems odd, but port c bit 6 must be programmed as an input to set up baud
rate.
I am using the same conditions as the begining of the program uses to set
up the baud rate, same RCSTA, TXSTA, port c conditions.
I must be missing something but it evades me.
Regards,
Sandy Phelps

{Original Message removed}

2001\03\11@204739 by Tony Nixon

flavicon
picon face
Sandy Phelps wrote:
>
> Seems odd, but port c bit 6 must be programmed as an input to set up baud
> rate.

To me that seems odd, because I've never heard of it.

> I am using the same conditions as the begining of the program uses to set
> up the baud rate, same RCSTA, TXSTA, port c conditions.
> I must be missing something but it evades me.


Why don't you just change the SPBRG register only, and if necessary the
BRGH bit.

Writing to the SPBRG register resets the baud counters ready for new
RX/TX.


--
Best regards

Tony

mICro's
http://www.picnpoke.com
.....salesKILLspamspam.....picnpoke.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body


2001\03\12@051137 by o-8859-1?Q?K=FCbek_Tony?=

flavicon
face
Hi,
I'm probably going this route in a week or so
( dynamically changing buad rate ), but just by
glancing through your code it seems 'dangerous' to me.
Why not the more 'careful' route there you :

a) disable global irq
b) diable uart irq's
c) disable uart module
d) reconfigure the uart module ( speed )
e) enable uart module
f) enable uart irq's
g) enable global irq

That should work, changing speed or other configuration
while running seems to have to many unknowns to me.

/Tony


Tony Kübek, Flintab AB            
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²
E-mail: tony.kubekspamspam_OUTflintab.com
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²

--
http://www.piclist.com hint: To leave the PICList
@spam@piclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2001\03\12@234509 by Jeethu Rao

flavicon
face
Hi Sandy,
               I too was quite frustrated in the beginning with the Baud
Rate Settings of the USART on a 16F877. Rather than manually working out the
SPBRG values, I used a formula provided by Fr. Thomas McGahee (also a member
of PICList),  And I never ever had problems with the BaudRate generator
after that.

The formulas are:-

;   For brgh=0       baudrate=Fosc/(64(spbrg+1))
;   So when brgh=0   spbrg_value = (xtal_freq/(baudrate*d'64'))-1

;   For brgh=1       baudrate=Fosc/(16(spbrg+1))
;   So when brgh=1   spbrg_value = (xtal_freq/(baudrate*d'16'))-1

You Can use em in a situation like:

<SNIP>

xtal_freq =       d'16000000' ;crystal frequency in Hertz.
   ;!!! set for YOUR crystal.
baudrate = d'4800' ;desired baudrate.
   ;now calculate spbrg_value...
spbrg_value = (xtal_freq/(baudrate*d'64'))-1
   ;this is based on txsta,brgh=0.
   ;if you have set txsta,brgh to 1, then you
   ;will have to use the alternate formula
   ;for when brgh=1. See formulas above...

movlw spbrg_value ;set baud rate generator value
movwf spbrg

</SNIP>

P.S I got this info from a file named picuart.zip from Fr. Tom McGahee's
site (http://redrival.com/mcgahee)
This file is a wonderful guide to solving all sorts of problems on a PIC
UART !

Regards,

Jeethu Rao
KILLspamjeethuKILLspamspamjeethurao.com

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2001\03\13@145827 by Jacob M Hartman

flavicon
face
part 1 597 bytes content-type:text/plain; charset=us-asciiHere is a short program that perhaps does the ultimate in dynamically
changing the baud rate:  It sets the divisor to the ADC input on AN0.  That
way, if nothing else works, you can set your terminal to the desired baud
rate and tweak a potentiometer until the terminal receives the data
properly.  I hope you find it helpful.

As for why on earth would anyone write such a useless thing?  I had a
mislabeled oscillator, so I couldn't figure out what divisor to use.  In
retrospect, a blinking led and a stopwatch might have been a simpler
solution....  :-)

Jake

(See attached file: seradj.asm)

part 2 3919 bytes content-type:application/octet-stream; (decode)

part 3 154 bytes
--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\03\16@003957 by Sandy Phelps

flavicon
face
Hi Folks,
Thanks to everyone who offered suggestions about changing the baud rate.
Unfortunately, my problem was in the Visual Basic program used to control the PIC.
I changed the comm settings with first disabling the port. So the PIC program may have been working on one of the many variations I tried.
The following is apparently the minimum needed to change baud rate on the fly.
I have multiple routines for 1200, 9600 and 19.2k baud. It switches rates and communicates
both ways.
One precaution: Make sure your controlling program knows what baud rate is current.

I have and do use Fr. McGahee's picuart.asm code. It has been invaluable in my project.


baud_9600
; ----------------------------------------------------
; for 9600 baud, spbrg_value = 25
; ----------------------------------------------------
clrf status  bsf STATUS, RP0      ; select bank 1
movlw d'25'                  ;spbrg value for 9600 baud
movwf SPBRG & 0x07f
movlw 0x22
movwf TXSTA & 0x07f
bcf STATUS, RP0         ;select bank 0
movlw 0x90
movwf RCSTA & 0x07f
return
Regards,
Sandy Phelps

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservspamBeGonespammitvma.mit.edu with SET PICList DIGEST in the body


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...