Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Interrupt: Looping in ISR

Status
Not open for further replies.

flit07

New Member
Hi,

I'm using PIC16f877, writing a simple ISR, but it keeps on looping within ISR, if i set PEIE, though beforehand i've reset all interrupts flags.

Could anyone shed some light?

Code:
	INTE = 0;
	init_uart();  // set RCIE and TXIE
	reset_IF();  // reset all interrupt flags
	GIE = 1;
	PEIE = 1;     // keeps on looping if i set PEIE  <-- problem here
	__enable_interrupt();
	while(1)
	{       
		while( ReceivedCount < 50)  // guard condition for every ISR done
		{
			do_foreground_process();  
		}
        }
thanks!
 
Last edited:

Noggin

Member
Where is your interrupt code? Can you show your init_uart code? Is your UART input pins pulled up? Are you clearing the interrupt flag inside the interrupt?
 

flit07

New Member
Ok.,..
The ISR as follow

Code:
__interrupt void tutor_interrupt(void) 
{ 
		RB7 = 1;    // LED indicator, PORTB change Disabled
		ReceivedCount  += 1; // check condition to complete program
		c[0] = RCREG;   // read received Byte, Never mind on the data content, I just want to clear RCIF by reading RCREG
		flag = 1;  // Indicator for do_foreground_process
}

init_uart() as follow

Code:
void init_cntr(void)
{
  TRISC = TRISC | 0x80; //  set RC7 (RX) as input
  TRISC = TRISC & 0xBF; //  set RC6 (TX) as output
  BRGH=1;		//  high speed
  SPBRG=0x81;  	        //  baud rate 9600Bdps1
  SYNC=0;		//  synchronous mode disabled 
  SPEN=1;		//  Enable pin for transmission
  TXIE=1;		//  int  desired
  TXEN=1;		//  TX Enable
  TX9=0;                //  8 Bit transmission
  TRMT=1;               
  
  // Reception
  RCIE=1;               //  int desired
  RCIF=0;           // clear RC flag
  RX9=0;                //  8 bit reception
  TRMT=1;               //  TSR empty
  CREN=1;               //  Enables continuous receive
  TX9D=0;		//  8 bit transmission
  RX9D=0;               //  8 bit receive
}

And that's all the code. simple module to be integrated into a big one. I did clear off RC flag inside ISR. But it keeps looping inside ISR if i set PEIE. Why?
 
Last edited:

flit07

New Member
solved.....solved by me again..hahaha

TXIF is also set when tx register is not written.
so...pic will always get interrupted.
 
Status
Not open for further replies.

Latest threads

Top