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.

[PIC] Issue in USART receive isr with Hi tech C compiler and PIC16F877A

Status
Not open for further replies.

Nikunj Tanna

Advanced Member level 4
Joined
Dec 8, 2009
Messages
115
Helped
23
Reputation
46
Reaction score
15
Trophy points
1,298
Location
Ahmedabad, Gujarat, India
Activity points
1,985
Hi,

I am working for sending and receiving SMS from SIM900A to PIC16F877A. I have usd isr to receive the response from SIM900A. It seems that the firmware goes into isr when the character is received but I am not able to fully store the received message in an array. I am pasting the ISR and initialization part. Any help or suggestions is appreciated.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void interrupt isr(void)            // Here be interrupt function - the name is
{
   unsigned char data,temp;
    while(!RCIF) continue;
 if(RCIF = 1)
    {
     RCIE = 0;
     data = RCREG;    
    Rxdata[index] = data;       
     index++;
     if(index == 80)
     index = 0;
        }
RCIE = 1;
}



I have tried with if(RCIF == 1) and also with if(RCIF==1 && RCIE ==1) but no luck. It seems that RCREG is not storing the data.

I have also tried to check OERR and FERR bits but when I put them in code they goes in to the loop and restarts the USART almost every time. What should be the right procedure to avoid Overrun errors?


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
if(OERR)
   {
         CREN = 0;
          CREN = 1;
   }
 
if(FERR)
 {
   TXEN = 0;
   TXEN = 1;
 }
}



- - - Updated - - -

Thanks andre_teprom for editing. I will take care of these things in future.
 
Last edited by a moderator:

Don't put in the 'while(!RCIF) continue;' line. Instead change the following if statement to be 'if(RCIE && RCIF)'.
The reason is that these processors use a single ISR that must handle all interrupts. Therefore it will only be called when there is an interrupt flag set. Blocking until the RCIF is bad in the situation where some other interrupt source has triggered the ISR - you will stop everything on the device until the RCIF is set which may me anytime in the future.
However, there can be situations where the IF flags can be set but the corresponding IE bit is not set. Therefore the recommended practice for these devices is to test both the IE and IF bits and perform the required code if BOTH are set.
Don't play with the RCIE bit in the ISR. The RCIF bit will clear when you read the RCREG and there is no need to clear the RCIE bit. Anyway, you set it again later in the ISR but outside of any conditional in which case ANYTHING which calls the ISR will cause the RCIE to be set - again this is bad practice.
Make sure that the 'Rxdata' array and the 'index' variable are declared as volatile - any variable that is updated in an ISR needs to be declared as volatile so the non-ISR code will check it properly.
We can't see how you declare these, nor can we see your other code so it is hard to tell how these variables are being used. Perhaps you need to show us a small but complete example that shows the probelm you are having.
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top