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.

[SOLVED] UART data (in interrupt) reception not receive data ,after coming in the endless while(1); loop even interrupt occur

Status
Not open for further replies.

thannara123

Advanced Member level 5
Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,601
Helped
122
Reputation
244
Reaction score
116
Trophy points
1,353
Activity points
10,611
UART data (in interrupt) reception not receive data ,after coming in the endless while(1); loop even interrupt occur.

I am using Pic16f877a code work well without the while loop which is comment offed
what is the reason why dont go the code to ISR_UART after went into the while loop

C:
char Uart_RC_Data ;
void interrupt UART_Interrupt()
{
  if(RCIF )    // if interrupt occurred RCIF will be one
    {
     while(OERR)  // if there is error
        {
        // __delay_us(100);
          CREN=0;  // restart UART
            OERR=0;
        }
    CREN=1;
    Uart_RC_Data  = RCREG;  // global variables to read received data
  }
}


void main(void)
    {
         //OPTION_REG &= 0x7F;
       TRISB =0x00;
       TRISD = 0x00;
       LCD_init();
        TRISC6=0;   //Output (TX)
        TRISC7=1;   //Input (RX)
        ser_int();    
 
      while(1)
       {    
       LINE1;  
       string(" Uart Data Rcved");
       LINE2;
        LCD_data(Uart_RC_Data);
        __delay_ms(100);    
     
          while(1);  // whenever use this loop its not working
        }       
 
       }
 
Last edited:

its working if i remove the while(1)

Code:
void ser_int()
{   GIE=1;
    PEIE=1;
    RCIE=1;
    TXSTA=0x20; //BRGH=0, TXEN = 1, Asynchronous Mode, 8-bit mode
    RCSTA=0b10010000; //Serial Port enabled,8-bit reception
    SPBRG=17;           //9600 baudrate for 11.0592Mhz
    SPEN = 1; //Enables Serial Port
    TXIF=RCIF=0;
}
 

Hello!

You may consider first looking at existing (and working) sample code, tutorials.
What you are asking belongs to basics, and I'm sure there is a tutorial that you could
first try, verify, modify, try if it still works and then ask very specific questions if it
doesn't.
For instance, if you say: I tried this tutorial, and it works. I then change line ##
to <something else> and it doesn't work anymore. Why?
This way, somebody who wants to help you would check only what has changed in line##
and could reply at once, without having to download your code, crreate a project for you
and debug it.

Second thing: you should avoid hard coded values. For instance 0x20. Why not
#define TXEN 0x20 ?
Why not #define BAUD_115k 0x17
and then write TXSTA = TXEN; and SPBRG = BAUD_115k;
The advantage is that you don't even need to write comments.

By the way, I don't know if it's the case, but TXEN looks like TX enable. What about
RXEN? I mean: if the reception is not enabled, you will likely wait a while until the
interrupt comes. Just guessing, I have never used PIC.

Regards,

Dora.
 
Also note that your code can only receive at best 10 characters per second because you pass each character to the LCD and then delay 100mS before accepting any more. If you are trying to display text as it is received, you need to store it first and then display when it is all in the store.

Why do you use "while(OERR)" then follow it with "OERR = 0", there is no need to put it inside a loop if you reset it anyway.

Brian.
 
This last while loop. It'll never exit. Why is it there ?
Hi
if is it in the while loop ,whenever the intrreput occur ,is it jump to the ISR ? that is the doubt ?

Why is it there ? just for learning purpose

thanks
 

Hi
if is it in the while loop ,whenever the intrreput occur ,is it jump to the ISR ? that is the doubt ?

Why is it there ? just for learning purpose

thanks
That's true, it will jump to the ISR. But after completion of ISR it'll jump right back into this same loop and do nothing else.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top