[<<] [<] Page 1 of 1 [>] [>>] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
PIC16F877 & USART
From: Rick Mann ####@####.#### Date: 28 Dec 2002 21:21:39 -0000 Message-Id: <BA335426.105BD%rmann@latencyzero.com> Hi. I'm trying to get a PIC16F877 to work at 9600 baud. It works fine at 2400, with BRGH=0, but I can't seem to get reliable operation at 9600 with BRGH=1. I thought I read somewhere that one shouldn't even try to use BRGH=1, but all of the examples I've seen on the Microchip website and Piclist.com seem to do it. FWIW, it seemed to work better when the SPRG value was set to 26 instead of 25, the value everything says I should use. I have a MAX232 from TI between the PIC and the PC. The handshaking lines are all hard-wired. I try to send ascii '0' through '9' from my terminal program, and display those values on 8 LEDs. At 2400 baud, it works great. At 9600, I get incorrect (although consistently) values. Any ideas? Thanks! -- Rick | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
Re: PIC16F877 & USART
From: Edward Tiong ####@####.#### Date: 28 Dec 2002 21:37:33 -0000 Message-Id: <3E0E17A8.A7A152F0@shaw.ca> Take a look at this code at http://www.ee.ualberta.ca/~ee401/debug/debug877.asm Actually, here is the snipplet of code ... ; receives: nothing ; uses: W ; returns: nothing ;******************************************************************* initializeUART ; Set up for hardware flow control banksel BANK0 ; Set to bank0 bcf PORTC,Tx_PIN ; Initial condition for the Tx line bcf PORTC,Rx_PIN ; Initial condition for the Rx line bcf PORTB,RTS_PIN ; Initial condition for the RTS line bsf PORTB,CTS_PIN ; Initial condition for the CTS line banksel BANK1 ; Set to bank1 bsf TRISB,RTS_PIN ; set RTS Pin to input bcf TRISB,CTS_PIN ; set CTS Pin to output bsf TRISC,Tx_PIN ; set Rx and Tx Pins to default as bsf TRISC,Rx_PIN ; high impedance bcf PIE1,RCIE ; Disable uart interrupts bcf PIE1,TXIE ; Set baud Rate to one of the following ; movlw 0xCF ; 300 baud ; movlw 0x67 ; 2400 baud movlw 0x19 ; 9600 baud (see table in pic16f873.pdf) ; movlw 0xC ; 19200 baud movwf SPBRG movlw 0x24 ; Initialize Tx status and control register movwf TXSTA banksel BANK0 ; Set to bank0 movlw 0x90 ; Initialize Rx status and control register movwf RCSTA return Or take a closer look at what the University of Alberta - Electrical and Computer Engineering department is doing with the PIC16F873 and PIC16F877. (http://www.ee.ualberta.ca/~ee041) Please keep in mind that the PIC code written on this site was done by students for students. Hopefully this helps. Rick Mann wrote: > > Hi. I'm trying to get a PIC16F877 to work at 9600 baud. It works fine at > 2400, with BRGH=0, but I can't seem to get reliable operation at 9600 with > BRGH=1. > > I thought I read somewhere that one shouldn't even try to use BRGH=1, but > all of the examples I've seen on the Microchip website and Piclist.com seem > to do it. > > FWIW, it seemed to work better when the SPRG value was set to 26 instead of > 25, the value everything says I should use. > > I have a MAX232 from TI between the PIC and the PC. The handshaking lines > are all hard-wired. > > I try to send ascii '0' through '9' from my terminal program, and display > those values on 8 LEDs. At 2400 baud, it works great. At 9600, I get > incorrect (although consistently) values. > > Any ideas? Thanks! > > -- > Rick > > --------------------------------------------------------------------- > To unsubscribe, e-mail: ####@####.#### > For additional commands, e-mail: ####@####.#### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
RE: PIC16F877 & USART
From: "Andreas Junge - DSLX" ####@####.#### Date: 31 Dec 2002 21:33:46 -0000 Message-Id: <HPEPKMGBOBBNPFCOKLJGKEKCDCAA.andreas@tecthermo.com> What is your clock rate for the pic? There are multiple tables for different clock rates in the documentation. Here are my settings for a 20Mhz pic and 9600baud: SPBRG = 129; // 9600bps BRGH = 1; // High speed baud rate generation on RCSTA = 0; SYNC = 0; // Async TX9 = 0; // 8bits TX please RX9 = 0; // 8bits RX please SPEN = 1; // Enable serial port CREN = 1; // Enable receiver TXEN = 1; // Enable transmitter TXIE = 0; // Disable transmitter interrupts I hope this helps... Andreas, N6NU -----Original Message----- From: Rick Mann ####@####.#### Sent: Saturday, December 28, 2002 1:14 PM To: PICList; GNU PIC List Subject: PIC16F877 & USART Hi. I'm trying to get a PIC16F877 to work at 9600 baud. It works fine at 2400, with BRGH=0, but I can't seem to get reliable operation at 9600 with BRGH=1. I thought I read somewhere that one shouldn't even try to use BRGH=1, but all of the examples I've seen on the Microchip website and Piclist.com seem to do it. FWIW, it seemed to work better when the SPRG value was set to 26 instead of 25, the value everything says I should use. I have a MAX232 from TI between the PIC and the PC. The handshaking lines are all hard-wired. I try to send ascii '0' through '9' from my terminal program, and display those values on 8 LEDs. At 2400 baud, it works great. At 9600, I get incorrect (although consistently) values. Any ideas? Thanks! -- Rick --------------------------------------------------------------------- To unsubscribe, e-mail: ####@####.#### For additional commands, e-mail: ####@####.#### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
Re: [PIC]: PIC16F877 & USART
From: Rick Mann ####@####.#### Date: 1 Jan 2003 22:08:17 -0000 Message-Id: <BA38A2F9.106CF%rmann@latencyzero.com> on 12/31/02 1:27 PM, Andreas Junge - DSLX at ####@####.#### wrote: > What is your clock rate for the pic? There are multiple tables for different > clock rates in the documentation. Oh, I forgot to mention that, sorry. 4.000 MHz. > Here are my settings for a 20Mhz pic and 9600baud: > > SPBRG = 129; // 9600bps > BRGH = 1; // High speed baud rate generation on > RCSTA = 0; > SYNC = 0; // Async > TX9 = 0; // 8bits TX please > RX9 = 0; // 8bits RX please > SPEN = 1; // Enable serial port > CREN = 1; // Enable receiver > TXEN = 1; // Enable transmitter > TXIE = 0; // Disable transmitter interrupts So, here's the thing. I appreciate everyone giving me info about how to set up the values, but the problem I'm facing is that I *did* set up the values correctly, using both formulas (the one from Microchip and the one that accounts for rounding errors). The formulas work for 2400 baud, but don't seem to work for 9600 baud. I finally shipped a couple of units at 2400 baud. It's suitable for my application (simple control protocol), but I've run into more problems. Basically, someone sends something like "I3" to my device. My device then responds with "I3". It does this by executing synchronous code to send one byte, then the next. After a time, it will stop sending the second byte. However, if you command it again, it will send the first byte. I'll probably have to post the code at some point, but that's the new problem (still haven't solved the old ones). Happy New Year to all! -- Rick | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
Re: PIC16F877 & USART
From: Snail Instruments ####@####.#### Date: 2 Jan 2003 00:02:01 -0000 Message-Id: <3.0.6.16.20030101232417.476f589c@pop.iol.cz> At 13:14 28.12.02 -0800, you wrote: >Hi. I'm trying to get a PIC16F877 to work at 9600 baud. It works fine at >2400, with BRGH=0, but I can't seem to get reliable operation at 9600 with >BRGH=1. If possible check your signals with scope, maybe the problem lies somewhere else. >I thought I read somewhere that one shouldn't even try to use BRGH=1, but >all of the examples I've seen on the Microchip website and Piclist.com seem >to do it. This BRGH=1 bug applied to PIC16C77 (or 74?), not to the 16F877. >I try to send ascii '0' through '9' from my terminal program, and display >those values on 8 LEDs. At 2400 baud, it works great. At 9600, I get >incorrect (although consistently) values. Check your hardware this way - remove the PIC from its socket, connect the RC6 and RC7 contacts with a piece of wire. Now your terminal program should echo all the characters typed. If this works O.K., try following main loop, which should echo all the characters as well: ;setup serial port .... bcf _GIE ;(or don't set it) main:btfss _RCIF goto main movf rcreg,w movwf txreg goto main Regards, Josef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
Re: [PIC]: PIC16F877 & USART
From: Snail Instruments ####@####.#### Date: 2 Jan 2003 00:02:01 -0000 Message-Id: <3.0.6.16.20030101232424.476f9a44@pop.iol.cz> >Basically, someone sends something like "I3" to my device. My device then >responds with "I3". It does this by executing synchronous code to send one >byte, then the next. Just curious - what do you call 'synchronous code'? Josef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
Re: [PIC]: PIC16F877 & USART
From: Rick Mann ####@####.#### Date: 2 Jan 2003 08:19:08 -0000 Message-Id: <BA393428.106E9%rmann@latencyzero.com> on 1/1/03 11:24 PM, Snail Instruments at ####@####.#### wrote: > Just curious - what do you call 'synchronous code'? I guess you could say it polls. The code loads TXREG, then sits in a loop waiting for the txmt flag to be set, then loads TXREG with the second byte to send. By contrast, async code would load TXREG, then go off an do something else, waiting for the txmt interrupt to occur. -- Rick | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
Re: [PIC]: PIC16F877 & USART
From: Jeff Jackowski ####@####.#### Date: 4 Jan 2003 19:46:16 -0000 Message-Id: <Pine.OSF.4.44.0301041331390.358804-100000@fly.hiwaay.net> On Wed, 1 Jan 2003, Rick Mann wrote: >on 12/31/02 1:27 PM, Andreas Junge - DSLX at ####@####.#### wrote: > >> What is your clock rate for the pic? There are multiple tables for different >> clock rates in the documentation. > >Oh, I forgot to mention that, sorry. 4.000 MHz. > >So, here's the thing. I appreciate everyone giving me info about how to set >up the values, but the problem I'm facing is that I *did* set up the values >correctly, using both formulas (the one from Microchip and the one that >accounts for rounding errors). -- Jeff Jackowski http://ro.com/~jeffj/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
Re: [PIC]: PIC16F877 & USART
From: Jeff Jackowski ####@####.#### Date: 4 Jan 2003 19:56:05 -0000 Message-Id: <Pine.OSF.4.44.0301041342310.358804-100000@fly.hiwaay.net> On Wed, 1 Jan 2003, Rick Mann wrote: >on 12/31/02 1:27 PM, Andreas Junge - DSLX at ####@####.#### wrote: > >> What is your clock rate for the pic? There are multiple tables for different >> clock rates in the documentation. > >Oh, I forgot to mention that, sorry. 4.000 MHz. > >So, here's the thing. I appreciate everyone giving me info about how to set >up the values, but the problem I'm facing is that I *did* set up the values >correctly, using both formulas (the one from Microchip and the one that >accounts for rounding errors). > >The formulas work for 2400 baud, but don't seem to work for 9600 baud. Bother, I pressed the wrong button. Sorry for the extra post. I wrote some code in C to do exactly what you are trying to do, and it works fine with the published values. It isn't for a free compiler, but it does mess with the hardware registers directly. If you think it might help, you can get the code at http://home.hiwaay.net/~jeffj1/projects/index.html from the top link. The relavent stuff is in uart.c. The only major difference I could find between what your code does and what mine does is that I set the USART enable bit after setting all other values. I'm not sure if that is needed, but it seemed like a good idea at the time. -- Jeff Jackowski http://ro.com/~jeffj/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
Re: [PIC]: PIC16F877 & USART
From: Declan Moriarty ####@####.#### Date: 5 Jan 2003 10:26:16 -0000 Message-Id: <03010510181601.00278@genius.chateau.dec> On Saturday 04 January 2003 19:48, somebody wrote > On Wed, 1 Jan 2003, Rick Mann wrote: > >on 12/31/02 1:27 PM, Andreas Junge - DSLX at ####@####.#### wrote: > >> What is your clock rate for the pic? There are multiple tables for > >> different clock rates in the documentation. > > > >Oh, I forgot to mention that, sorry. 4.000 MHz. > > > >So, here's the thing. I appreciate everyone giving me info about how > > to set up the values, but the problem I'm facing is that I *did* > > set up the values correctly, using both formulas (the one from > > Microchip and the one that accounts for rounding errors). > > > >The formulas work for 2400 baud, but don't seem to work for 9600 > > baud. Can you write a test program using your code to output a continual stream of 0xCC (=1010 1010) and 'scope the frequency? A little bit of copy'n'paste would at least quantify your error (too FAST, or too SLOW). You need to divide your problem into fragments, and fix the one that's broken. If you are seriously stuck, Microchip do have help lines. I got the phone number for the English one. -- Regards, Declan Moriarty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[<<] [<] Page 1 of 1 [>] [>>] |