CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

INT_RDA2 and INT_RDA

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








INT_RDA2 and INT_RDA
PostPosted: Fri Feb 15, 2008 10:19 am     Reply with quote

Hi there i'm using a 18f8722 with an internal oscilator at 32MHz.
For my project i need to communicate with a master and i need to send the status of my slave. I'm using the two uarts one to communicate and the other one to receive data from a rfid reader. the code is:
Code:

#include <18F8722.h>
#fuses INTRC,WDT1024,NOPROTECT,NOLVP
#priority RDA2//,RDA,RB
#use delay(clock=32000000)
#use rs232(baud=19200, xmit=PIN_C6,rcv=PIN_C7,ERRORS,UART1,STREAM=COMM)
#use rs232(baud=9600, xmit=PIN_G1,rcv=PIN_G2,ERRORS,UART2,STREAM=CARD)



/////////////////////////////////////////////////////////////


void communications();
/////////////////////////////////////////////////////////////
#define WR PIN_B0
/////////////////////////////////////////////////////////////
#include "settings.h"
#include "stdlib.h"
#include "keyboard.h"
#include "flexy_lcd.h"
#include "card_reader.h"
#include "piccomm.h"
/////////////////////////////////////////////////////////////
#INT_RDA2
   void card_reading(){
      char c;
      c=fgetc(CARD);
      //fputc(c,COMM);
      le_cartao(c);
   }

/////////////////////////////////////////////////////////////
#INT_RDA
   void serial_interrupt(){
      //char c;
      //c=fgetc(COMM);
         //fputc(c,COMM);
      //fputc('A',COMM);
      restart_wdt();
      communications();
      
      
      
   }
/////////////////////////////////////////////////////////////

#INT_RB
void teclado(){
   
   //fprintf(DEBUG,"Keypad!!!\n\r");
      //keypad();
}

/////////////////////////////////////////////////////////////


void main() {

   init_cartao();
   setup_oscillator(OSC_32MHZ);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_RDA2);
   setup_wdt(WDT_ON);
   while(true){
     
         output_high(PIN_B1);
         delay_ms(100);
         output_low(PIN_B1);
         delay_ms(100);

         

  }

}

void communications(){
   descodifica(ReceiveMsg(COM1));
}


Now the problem is that if i use the communications() in the INT_RDA interrupts i only get garbage in the rfid reading if i remove the communications routine it works fine. Is there any relation between the INT_RDA and the INT_RDA2 beside being two communication interrupts? (By the way the communications works fine with or without the INT_RDA2) . Can anyone explain why this happens?? Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 15, 2008 3:25 pm     Reply with quote

1. We don't know what's in the communications() routine.

2. In your #INT_RDA routine, you call the communications() routine.
Does it actually do a call to fgetc() ?

3. In your main while() loop, you don't restart the WDT. You depend
upon an interrupt occuring, to call restart_wdt(). What if there is no interrupt ?

4. In your description, you refer to "rfid", but in your program, you
have labeled that stream as "CARD". You have two different names for
the same thing. This makes it more difficult to understand your problem.

5. What's your compiler version ?
Audi80



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

PostPosted: Mon Feb 18, 2008 11:58 am     Reply with quote

Sorry about my late response...
The communications routine is where i´ve got my communication protocol implemented but it doesn't interfere with the card reader, the only problem that it might be is that the routine has 200 line code. that routine does several fgetc but it is to the COMM buffer. like:

Code:

fgetc(COMM);

My question is that even it the int_rda interrupt occurs why does it mess up with the INT_RDA2 interrupt?? Confused

The restart_wdt(); in the INT_RDA is to insure that if the pic gets stuck it restarts and i dont lose any communications. at least for a while. and the communications are on RS-485 with a pooling for 100ms so while i can communicate i restart the WDT.

In the label CARD i refered it because i´m using rfid cards and tags.

My compiler version is 4.013

I dont know were it was but i reader somewhere in the forum that the PIC18F8722 has a problem when using the two interrupts at the same time so i´ve requested a PIC18F8723 that i think it might work but i´m just guessing.

Laughing
I´ve got to deliver this project by the end of the month so if anyone as the solution for this problem i´d be very pleased.

I think that this friend has the same problem i do.

http://www.ccsinfo.com/forum/viewtopic.php?t=31313&highlight=
Ken Johnson



Joined: 23 Mar 2006
Posts: 197
Location: Lewisburg, WV

View user's profile Send private message

PostPosted: Mon Feb 18, 2008 3:17 pm     Reply with quote

Rule # 1: Get in and out of any isr as quickly as possible.

Your interrupts shoud not be calling other functions (cartao, communications); just read the byte (getc) from the hardware register, stick it in a buffer, set a flag and exit.

In the main loop, check for this flag, copy bytes from your buffer and process them there.

Hope this helps Smile

Ken
Audi80



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 5:19 am     Reply with quote

I´ve found out the problem. My RFID reader was consuming at least 100mA and my source was weak... By the way i didnt changed anything in the code and my project is working for 1 day with no problems so its possible to use functions inside a interruption. Thanks everyone that helped me...
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 6:19 am     Reply with quote

Yes you can call functions from an interrupt routine but you should only do this if you don't have another option.

Each call to a function adds overhead (more instructions) to your interrupt routine.
The more your interrupt routine does the less chance of another interrupt (if there was one) being processed.
If your interrupt code is slower than your interrupt frequency your PIC will do nothing but service the interrupts. Won't run main.

Looking at your isr this calls 1 function which calls another function with the result of another function! 3 function calls ! that is an extra call and ret for each one.
And with no idea what those other functions do it would be impossible for anyone to know if you have problems with your timing etc.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group