Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interrupt problem in serial communication

Status
Not open for further replies.

coolvasanth07

Member level 1
Joined
Sep 25, 2012
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,506
Hi, i have problem in serial interrupt,,when i initialize "gie=1" , it not take isr....then how can i write the code for interrupt...it's urgent plz help me....

>>thanks in advance....
 

Hi, i have problem in serial interrupt,,when i initialize "gie=1" , it not take isr....then how can i write the code for interrupt...it's urgent plz help me....

>>thanks in advance....


which microcontroller ur using...give detailed information
 

Am using pic16f877a and hi-tech c compiler...
 

before making gie =1 reset the external interrupt flag (INTF = 0) and enable the external interrupt(INTE = 1) and then set gie =1

did u do this

- - - Updated - - -

in your isr function check for this

if (INTF) // If the external flag is 1, do .....
{
INTF=0; // Reset the external interrupt flag
 

ya sir, but not take ISR...my uart initialization shown below, in this program when i enable "GIE", it not TAke ISR...
Code:
void uart_init()
{
	TXSTA=0x20;
	RCSTA=0x90;
	SPBRG=15;
	RCIE=1;
	TXIE=1;
	INTF=0;
	INTE=1;
//	GIE=1;
	PEIE=1;
void interrupt isr(void)
{
	if(INTF)
	{
		INTF=0;	
		if(RCIF)
		{
                }
       }
 
Last edited:

ya sir, but not take ISR...my uart initialization shown below, in this program when i enable "GIE", it not TAke ISR...
Code:
void uart_init()
{
	TXSTA=0x20;
	RCSTA=0x90;
	SPBRG=15;
	RCIE=1;
	TXIE=1;
	INTF=0;
	INTE=1;
//	GIE=1;
	PEIE=1;
void interrupt isr(void)
{
	if(INTF)
	{
		INTF=0;	
		if(RCIF)
		{
                }
       }


did you Enable external interrupts INTE from RB0 did you make portb as output...once post your main function so that i can found out error in your code..

- - - Updated - - -

once check your while loop in main function
 

my main function shown below
Code:
void main()
{
	TRISD=0x00;
	PORTD=0x00;
	TRISB=0x00;
	PORTB=0x00;
	TRISE=0x01;
	PORTE=0x01;
	lcd_init();
	uart_init();
	value=200; 
	lcd_string(data);
	lcd_cmd(0x88);
	__delay_ms(30);
	while(1)
	{
		lcd_cmd(0x88);
		__delay_ms(30);
		if(sw==1)
		{	
			if(value!=0)
			----;
			__delay_ms(30);
		}
		lcd_string(arr);
	}
}
 

which is the compiler u are using and post the full code with ISR..
 

IN ISR TRY TO DO THIS AT END OF YOUR CODE...I HOPE YOU ARE YOU USING UART INTERRUPT IN ISR FUNCTION

RXIF=0; // Clear UART RX Interrupt Flag.
RXIE=0; // Disable UART RX Interrupt



CHECK THIS CODE This code will read in the UART data and store the result
in an array.

unsigned cnt, cnt1;
char rxchar, i = 0, flag = 0; // Variable for storing the data from UART and array counter
unsigned char rxarray[80]; // array to store the received charaters
unsigned short j;

void interrupt() {
if (PIR1.RCIF) { // test the interrupt for uart rx
rxchar = Uart1_Read(); //
rxarray = rxchar;
i++;
// ******************************************************
// Only select one of the following statements
if (rxchar == 36) { // select this if looking for a terminating character
flag = 1;
} // end if (rxchar == "$")
PIR1.RCIF = 0; // clear RCIF
} // end if (PIR1.RCIF)

}


void main() {
ANSEL = 0; // Configure AN pins as digital
ANSELH = 0;
UART1_Init(9600);
Delay_ms(500); // Wait for UART module to stabilize
PIE1.RCIE = 1; //enable USART receiver interrupt bit
INTCON.PEIE = 1; //enable peripheral interrupt bit
INTCON.GIE = 1; //enable global interrupt bit

while (1) {
if (flag ==1) {
j = 0;
while(j < i) {
Uart1_Write(rxarray[j]);
j++;
} // end while(rxarray)
i = 0;
flag = 0;
} // end if (flag)


}
}



In this example there is no check agianst buffer overflow and framing errors.
 

this is my full code,,,am using Hi-Tech C compiler...
Code:
void main()
{
	TRISD=0x00;
	PORTD=0x00;
	TRISB=0x00;
	PORTB=0x00;
	TRISE=0x01;
	PORTE=0x01;
	lcd_init();
	uart_init();
	value=200; 
	lcd_string(data);
	lcd_cmd(0x88);
	__delay_ms(30);
	while(1)
	{
		lcd_cmd(0x88);
		__delay_ms(30);
		if(sw==1)
		{
			__delay_ms(30);
			while(sw==1);
			__delay_ms(30);
			if(value!=0)
			value=value-1;
			__delay_ms(30);
		}
		
		lcd_string(arr);
	}
}

void uart_init()
{
	TXSTA=0x20;
	RCSTA=0x90;
	SPBRG=15;
	RCIE=1;
	TXIE=1;
	INTF=0;
	INTE=1;
//	GIE=1;
	PEIE=1;
}

void interrupt isr(void)
{	
	unsigned char temp;
	GIE=1;
	int i=0;
	if(INTF)
	{
		INTF=0;	
		if(RCIF)
		{
			RCIF=0;
			temp=RCREG;
			if(temp=='a')
			{
				value=value+5;
			}
		}
	}
}
 
Last edited:

Try this. Don't forget to change the value of SPBRG

Code:
void interrupt ISR(void)
{
	
	if(RCIF)  //If UART Rx Interrupt
	{			
		if(OERR) //if over run error, then reset the receiver
		{
			CREN = 0;
			CREN = 1;
		}
		RCIF = 0;
							
	}
}


SPBRG=129;             //set baud rate as 9600 baud
BRGH=1;                //baud rate high speed option
TXEN=0;                //disable transmission
TX9 =0;                //8-bit transmission
RX9 =0;                //8-bit reception   
CREN=1;                //enable reception
SPEN=1;                //enable serial port
SYNC = 0;
SPEN = 1;
RX9 = 0;
CREN = 1;
FERR = 0;
OERR = 0;
TXIE = 0;
RCIE = 1;
			
//Include these settings
GIE  = 1;  		//Enable global interrupts
PEIE = 1;  		//Enable Peripheral Interrupts
 
this is my full code,,,am using Hi-Tech C compiler...
Code:
void main()
{
	TRISD=0x00;
	PORTD=0x00;
	TRISB=0x00;
	PORTB=0x00;
	TRISE=0x01;
	PORTE=0x01;
	lcd_init();
	uart_init();
	value=200; 
	lcd_string(data);
	lcd_cmd(0x88);
	__delay_ms(30);
	while(1)
	{
		lcd_cmd(0x88);
		__delay_ms(30);
		if(sw==1)
		{
			__delay_ms(30);
			while(sw==1);
			__delay_ms(30);
			if(value!=0)
			value=value-1;
			__delay_ms(30);
		}
		
		lcd_string(arr);
	}
}

void uart_init()
{
	TXSTA=0x20;
	RCSTA=0x90;
	SPBRG=15;
	RCIE=1;
	TXIE=1;
	INTF=0;
	INTE=1;
//	GIE=1;
	PEIE=1;
}

void interrupt isr(void)
{	
	unsigned char temp;
	GIE=1;
	int i=0;
	if(INTF)
	{
		INTF=0;	
		if(RCIF)
		{
			RCIF=0;
			temp=RCREG;
			if(temp=='a')
			{
				value=value+5;
			}
		}
	}
}

in this case you are not enabling the global interrupt flag i,e. GIE=1

why are u checking the external interrupt bit first i,e. INTF==1 in ISR

what u mean by sw and arr i told to post the full code and which is the crystal u are using........
 

thank u sir(jayanth.devarayanadurga) thank u very much....i got it.........thanks a lot....Thanks to all...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top