View previous topic :: View next topic |
Author |
Message |
ebarnes
Joined: 16 Apr 2007 Posts: 11
|
Global variables. |
Posted: Thu Apr 19, 2007 8:55 am |
|
|
I am using "Static" to define variable "RfidReq", but I still get this error message.
"Undefined identifier
The specified identifier is being used but has never been defined. Check the spelling."
I am declaring it in the Interupt, because when i declared it inthe main, i got the error in the interupt. *Sigh*
-----------------------------------------------------------
#int_RDA
void RDA_isr()
{
static char RfidReq[8];
static int CharCnt;
RfidReq[CharCnt]=getc();
putc(RfidReq[CharCnt]);
CharCnt++;
if(CharCnt>=8)
{
CharCnt=0;
}
}
---------------------------------------------------------
and using it here in Main.
---------------------------------------------------------
void main()
{
static int CharComp;
static char master[8];// this is the master key in decimal
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
enable_interrupts(INT_RDA);
enable_interrupts(INT_SSP);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
setup_oscillator(OSC_4MHZ);
master[0]='0';///lsb
master[1]='6';
master[2]='9';
master[3]='1';
master[4]='2';
master[5]='7';
master[6]='1';
master[7]='5';///msb
while (CharComp >=-1)
{
if (RfidReq[CharComp] == master[CharComp])// this is the line the error occures on
CharComp++;
else
CharComp = -10;
}
}
----------------------------------------------------
when i compile, i get the error only on the specific variable.
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Apr 19, 2007 9:23 am |
|
|
Your poll is useless, by it's asynchronous nature an interrupt can never return a variable.
Explanation: As you can never know when the interrupt will occur, how and when were you going to test for the result?
Quote: | I am declaring it in the Interupt, because when i declared it inthe main, i got the error in the interupt. *Sigh*
| Make it a global variable.
Code: | while (CharComp >=-1)
{
if (RfidReq[CharComp] == master[CharComp])// this is the line the error occures on
CharComp++;
else
CharComp = -10;
} | Bug 1: By default the variables in the CCS compiler are unsigned, if you want to use signed variables you have to declare them as such.
Bug 2: change the test '>=' to '>'
Dangerous: You are doing a call to putc() in the interrupt handler. For interrupts there is the requirement that they should be executed as quick as possible, at least faster than the time required to handle a single interrupt. Here you might be in error when the putc() is outputting data at the same or a slower baudrate than you are receiving with. |
|
|
ebarnes
Joined: 16 Apr 2007 Posts: 11
|
|
Posted: Thu Apr 19, 2007 9:36 am |
|
|
Thank-you for your Critique, but You didn't address why I am getting the error. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Apr 19, 2007 10:13 am |
|
|
Your static variable is defined inside of your ISR and can only be used inside the ISR. When you try to use a variable inside of main(), even though it has the same name, it is considered to be a completely different variable. You will need to declare a variable inside of main() to use it inside of main(). If you want to access the same variable inside of the ISR and inside of main() then you will need to declare it at the top of the code and make it a Global variable.
Also, It would not be a good idea to declare different variables with the same name inside of different functions. Even though the compiler will handle them properly, it may cause confusion for the programmer on which variable he is manipulating. Mistakes can creep into your code if you practice this type of programming.
Ronald |
|
|
ebarnes
Joined: 16 Apr 2007 Posts: 11
|
|
Posted: Thu Apr 19, 2007 10:16 am |
|
|
what is the syntax for defining a global variable? I cannot find it in the help sections. |
|
|
rberek
Joined: 10 Jan 2005 Posts: 207 Location: Ottawa, Canada
|
|
Posted: Thu Apr 19, 2007 10:36 am |
|
|
Global variables have the same syntax as local variables, they are just declared outside of main or any other code block.
This is standard C syntax and is not specific to the CCS compiler, so it may not be discussed in the help files. |
|
|
iw2nzm
Joined: 23 Feb 2007 Posts: 55
|
|
Posted: Thu Apr 19, 2007 11:22 am |
|
|
ckielstra wrote: |
Dangerous: You are doing a call to putc() in the interrupt handler. For interrupts there is the requirement that they should be executed as quick as possible, at least faster than the time required to handle a single interrupt. Here you might be in error when the putc() is outputting data at the same or a slower baudrate than you are receiving with. |
When one need to receive & forward chars between two serials how should one do?
I know this:
http://www.ccsinfo.com/faq.php?page=interrupts_disabled
But I don't find a more efficient method than:
Code: | fputc(fgetc(STREAM1), STREAM2); |
coded into the RDA isr.
Bye
Marco / iw2nzm |
|
|
|