>-----Original Message----- >From: Darren Gibbs [mailto:tsquank@YAHOO.COM] >Sent: 14 March 2004 19:36 >To: PICLIST@MITVMA.MIT.EDU >Subject: [PIC:] USART RX interrupts > > >I have two 16F628s, one sending commands to the other over the >USART with the baud rate at 31250. It's working almost >flawlessly and I'm trying to finetune the receiving code to >eliminate a couple of annoying behaviors. The main loop of >the receiving program is doing PWM on 5 pins, each connected >to LEDs. I'm collecting bytes from the serial port at >interrupt time and thought it would be fruitful to experiment >with disabling interrupts during some iterations of the main >loop to see if the interrupt handler is interacting badly with >the main loop at certain points. I can't seem to get this to >work properly. > >I've tried to disable/enable just the RX interrupt with: > > bcf PIE1,RCIE > > (some code) > > bsf PIE1,RCIE > >and I've tried to disable/reenable all interrupts with: > > clrf INTCON > > (some code) > > movelw B'11000000' > movwf INTCON > >In one case, it works very briefly 3-10 seconds and then the >receiving PIC goes into a coma and stops responding >completely, in the other case I appear to be getting serial >port errors and it never works at all.. > >Is there some specific incantation for disabling/enabling rx >interrupts while the port is continuously getting data? I >don't care if I lose a few commands, I just want to ignore the >incoming data briefly and then start paying attention again. > >thanks for any ideas! > >darren I suspect your problem is that you are overflowing the RX buffer. If this happens the PIC sets the OERR flag and stops receiving data. If you don't care about losing data, then before you re-enable interrupts ensure the OERR flag is clear. If not then clear it by clearing and setting the CREN bit. e.g. bcf PIE1, RCIE ; disable RX interrupts ; do stuff here btfss PIR1, OERR ; buffer over run? goto enable_int ; no, proceed to enable interrupts bcf PIR1, CREN ; yes, toggle CREN to clear error bsf PIR1, CREN enable_int bsf PIE1, RCIE ; enable RX interrupts Regards Mike ======================================================================= This e-mail is intended for the person it is addressed to only. The information contained in it may be confidential and/or protected by law. If you are not the intended recipient of this message, you must not make any use of this information, or copy or show it to any person. Please contact us immediately to tell us that you have received this e-mail, and return the original to us. Any use, forwarding, printing or copying of this message is strictly prohibited. No part of this message can be considered a request for goods or services. ======================================================================= Any questions about Bookham's E-Mail service should be directed to postmaster@bookham.com. -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body