We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello,
I want to work with the interrupt int0 of the FX2.
The regsiters I have to use are written down in the TRM of the FX2. But where are informations about enabling the interrupt or name of the ISR for example?
Where I can search? I only find information snippets.
Best regards Jan
Ok,
With "information snippets" I found with google and the trm I wrote the folowing code:
.... IP = 0x01; SYNCDELAY; // INT0 auf high priority
IE = 0x81; SYNCDELAY; //Global interrupt enable and INT0 enable
TCON |= 0x01; //edge sensitive //Is set when a negaitve cklock edge is detected on the INT0 pin and is automaticaly cleared when the FX2 vectors to the corresponding ISR.
..
static void MyIsr(void) __interrupt 0 { // My Interrupt handler for INT0 }
....
Does the 0 after the __interrupt stand for the first row in the interrupt vector table or?
static void MyIsr(void) __interrupt 0 { // My Interrupt handler for INT0 } 1) static not needed 2) have never seen '__' in front of 'interrupt', to the best of my knowledge it is wrong
the number is (vector_address - 3)/8 aka "interrupt number" BUT BEWARE some datasheets will have "interrupt numbers" that do not match this formula ALWAYS use (vector_address - 3)/8
Erik
By the way I don't have an syntax errors when I use the __ in front of interrupt.
these changes don't solve my problem.
When I uncomment my ISR, the firmware is running without errors.
And the 0 for INT0 should be right too.
Even if I disable all interrupts and I have my ISR uncommented, the firmware is not running.
There should be an error defining this function.
If you have an interrupt enabled and no ISR you will most likely crash
The examples for EZUSB FX2LP are included in the Dev kit CD image on the Cypress site,
SETUP_FX2LP_DVK_1004.exe (26.4 MBytes) www.cypress.com/
After installation, this folder holds an example for INT0 and other interrupts.
C:\Cypress\USB\Examples\FX2LP\extr_intr The point for ISR coding is,
The main file, extr_intr.c, starts with this line
#pragma NOIV // Do not generate interrupt vectors
This setting is required to set up EZUSB-specific interrupt vector table. But it disturbs usual interrupt vector for '51, which is required for INT0 handling.
Then, you have to place your INT0 ISR in an other file, which doesn't have above #pragma. The example places it in isr.c
Tsuneo
Ok, I'm sorry I mixed uncomment and comment. I didn't enabled the interrupts but defined my ISR and there where errors in the firmware.
I'll look in the example Tsuneo showed me.
Thank you for this information. I made it as you described.
In the main() where I initialize the Interrupt I added the line #pragma NOIV
In another file I put the ISR.
The USB tranfer is not disturbed now. Thats an improvement for the problem. But there's a further problem.
In the ISR I increment a variable. This variable I send over USB to my PC to see if the ISR ran. But it is not incremented. Incrementing it in a "normal" function is going well.
I declared the variable in ane xtra header file. The two files (file with main() and the file with the ISR) now see the varibale.
static volatile char value=0;
By the way, there is no compilation error. Can you see a failure?
Why did you make it 'static' ... ?
Think about what effect that might have...?
You might want to take a look at this thread on the subject of 'static':
http://www.keil.com/forum/16651/
When I make it static and I have included this file in both files I'll have a copy of this variable? The variable exists now two times in the stack?
But how can realize it having two files and both know this variable?
When I make it static and I have included this file in both files I'll have a copy of this variable? The variable exists now two times in the stack? 1) NO variables "exist on the stack"in C51 2) either you get an error or you have two SEPARATE variables, it is an issue of 'scope'
you need to read up on global variables and 'extern' (and header files??). Please do not respond with the usual BS about global variables.
the only way you can communicate between a function and an ISR is having them in the same module or using a global variable
And 'static' variables don't (generally?) exist on the stack anyhow!
"the only (sic) way you can communicate between a function and an ISR is having them in the same module..."
Strictly, in the same Translation Unit - in which case you'd need a variable at File Scope.
"...or using a global variable"
I guess you could also do something really horrible with absolute memory locations...
This is 'C' textbook stuff!
See: c-faq.com/.../decldef.html
Yes, but how can I realize it making it global when I use two files which have to access this variable?
could I make it as follows: creating a new file _______________________ globalVars.h:
static volatile char var;
static char getVar() { return var; }
static incVar() { var++; }
________________________
Whenn accessing the variable from the ISR or main file I call the getVar() fucntion. Does this realization create two variables internaly too?
But was it too simple to remove the "static" keyword, thereby allowing access to the variable from other translation modules?
Then a line with "extern" to tell the compiler that someone else has a variable of this type and name that it wants to share with the world.
Surely, you must realise every 'C' program with more than 1 source file must manage to do this? It really is basic, textbook stuff!
Did you actually follow the link that I provided?
Have you actually thought about the meaning of the 'static' keyword?