Matt, You are right, I must disable TX interrupts (I did) AND check TXIF flag last because it will be almost always set. Joan > -----Mensaje original----- > De: pic microcontroller discussion list > [mailto:PICLIST@MITVMA.MIT.EDU]En nombre de Matt Pobursky > Enviado el: viernes, 03 de mayo de 2002 2:02 > Para: PICLIST@MITVMA.MIT.EDU > Asunto: Re: [PIC]: Weird 16F877 USART behaviour > > > On Thu, 2 May 2002 23:37:28 +0200, Joan Ilari wrote: > >Hi, Piclisters ! > > > >1- Introduction : > > > >I am developing a project where a 16F877 has to communicate with > >an external processor through a serial line by means of its > >USART. The TX and Rx routines are interrupt-driven. > > > >2- The (checked) fact : > > > >If in the interrupt routine I check TXIF flag before RCIF, when > >a byte is received, I find that : TXIF is set => TX routine is > >called instead of RX one => RCREG register is not read => RX > >interrupt is not reset => interrupt program is continuously > >called => watchdog fires, etc ... etc... > > > > The TXIF flag is a transmitter empty flag. It's set any time the > transmitter register is empty, so it will be set most of the > time. You need to disable TX interrupts until you load the first > character to be sent into the TXREG. Once you write the TXREG, > the TXIF flag will be cleared automatically. Then enable your TX > interrupt, when the character is sent the TXIF flag will be set > again and your TX interrupt will occur. After your last character > to be sent is loaded into the TXREG, disable TX interrupts so you > won't be interrupted after the last character is sent. > > This one bites a lot of people. > > Matt Pobursky > Maximum Performance Systems > > -- > http://www.piclist.com hint: PICList Posts must start with ONE topic: > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > > -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics