interrupts with FX2

Hello,

do you know where I can find information about setting up an interrupt with the FX2?

To my knowledge an ISR looks like:

static void MyIsr(void) __interrupt 0 { // Clear global USB IRQ EXIF &= ~0x10; .. }

But how do I tell the FX2 to run the ISR when the IRQ0 (INT0 pin) occurs?

Best regards Jan

--------------------------------------- Posted through

formatting link

Reply to
jan0385
Loading thread data ...

Have you tried Google?

Reply to
daven

with

occurs?

Yes Ok,

With "information snippets" I found with google (yes I tried google) I wrote the folowing code:

.... // PORTACFG: FLAGD SLCS(*) 0 0 0 0 INT1 INT0 // INT0 on PortA PORTACFG = 0x01; IP = 0x01; // INT0 to high priority IE = 0x81; // global interupt enable an enable interupts from INT0

..

static void MyIsr(void) __interrupt 0 { // My Interrupt handler for INT0 }

....

Does the 0 after the __interrupt stand for the first row in the interupt vector table or?

--------------------------------------- Posted through

formatting link

Reply to
jan0385

The exact syntax for the interrupt handler will depend on the compiler. Check the data sheet/user manual for your part and this will give you information on the interrupt vector table and whether you need to use 0 or some other, although your code comments suggest that 0 is the correct one.

Does it compile?

Reply to
daven

There isn't a universal convention for tagging interrupts. You'll need to refer to the documentation for the particular assembler you're using.

--
Rich Webb     Norfolk, VA
Reply to
Rich Webb

There occur no errors during compilation. The syntax for defining an ISR using the sdcc compiler is (I looked in th manual of sdcc): void timer_isr (void) __interrupt (1) __using (1)

the keyword using is optional. For the number after __interrupt I take for INT0

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, th firmware is not running. It seems the error is depending of the IS definition...

--------------------------------------- Posted through

formatting link

Reply to
jan0385

How do you know it's not running? How will you know when it is running correctly? Also you appear to be contradicting yourself, above you say the firmware *is* running without errors!

Reply to
daven

When I don't define this ISR, the firmware is running because..

With my Computer I send bulk requests to the FX2. Ok, and when I define the ISR the the FX2 don't respond to this requests. When I don't define this ISR, the FX2 sends an USB message after receiving the bulk request.

--------------------------------------- Posted through

formatting link

Reply to
jan0385

In order to make the conversation easier to follow, please quote the last message as I am doing.

So I am assuming therefore that the USB part is in some code elsewhere?

Are you clearing the interrupt flag? If you don't the interrupt will keep firing and the rest of the program will never be able to run.

Reply to
daven

the

this

The FX2 is configured, that he should answer to a bulk request by send an usb message to the bus.

The source I got from

formatting link
void main(void) { Initialize(); for(;;) { // Wait for the EP6 buffer to become non-full. if(!(EP6CS & (1Are you clearing the interrupt flag? If you don't the interrupt will

No the flag should be cleared automaticaly(register TCON). Or is this not

8051 like? This is my interrupt initialization:

// PORTACFG: FLAGD SLCS(*) 0 0 0 0 INT1 INT0 // INT0 am PortA PORTACFG = 0x01; SYNCDELAY; // (delay maybe not needed) IP = 0x01; SYNCDELAY; //xxxxxxx1 // | // INT0 auf high priority IE = 0x81; SYNCDELAY; //1xxxxxx1 //| | //| Enable interrupts for INT0 //Global interrupt enable TCON |= 0x01; //xxxxxxx1 // || // |1=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. (TRM of FX2)

--------------------------------------- Posted through

formatting link

Reply to
jan0385

formatting link

If it's cleared automatically then that should be fine.

What is the ISR code?

Reply to
daven

define

elsewhere?

an

formatting link

not

Ok, I overlooked the fact, that using ISRs with the FX2 you have to add the line to the main()-file:

#pragma NOIV

This setting is required to set up EZUSB-specific interrupt vector table.

Then you have to put the ISR in another file than the file, where this statement is.

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 an extra header file. The two files (file with main() and the file with the ISR) now can see the varibale.

static volatile char value=0;

By the way, there is no compilation error. Can you see a failure defining the variable or another faliure?

--------------------------------------- Posted through

formatting link

Reply to
jan0385

The variable should be declared in one of your c files and then extern'd in the header file. It sounds like the way you have done it will create two separate variables with the same name.

Even better is to only declare the variable in one of the c files and then create a function to access it from another c file. That way you can protect the variable from erroneous writes, or make it so that it is only readable for example.

Reply to
daven

the

table.

problem.

PC

with

could I make it as follows: _______________________ 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 to variables internaly too?

defining

--------------------------------------- Posted through

formatting link

Reply to
jan0385

You can't put functions in header files, they go in .c files. So put the above in a .c file and then in a header file put:

extern static char getVar(); extern static incVar();

then include this header file in the whichever other .c files need to call the functions.

Reply to
daven

Of course you can! Whether it is good practise is a different matter....

Meindert

Reply to
Meindert Sprang

It's not good practice but it is permitted and might be useful in special circumstances. This is a "should not" rather than a "can not."

The storage class specifier "static" declares that the functions have internal linkage. This can't be paired with the specifier "extern." From

6.9.1 Function Definitions "The storage-class specifier, if any, in the declaration specifiers shall be either extern or static."

It is permitted (and common practice) to have the functions declared in the header files as extern and then in exactly one .c file (which includes the header) to write the function definitions.

Also: the function prototypes above really ought to have parameter lists.

--
Rich Webb     Norfolk, VA
Reply to
Rich Webb

Well yes you can but if you then include that header file in more than one .c file things are still not going to work.

At risk of starting another "goto" discussion, you can of course use goto but if I saw someone using it I'd tell them they can't! :-)

Reply to
daven

Yes I can.

Ok I made the variable static in an extra file. In the file I have function to access this variable by the ISR and the main-file.

problem solved. Thank you!

--------------------------------------- Posted through

formatting link

Reply to
jan0385

My bad, I copy and pasted without deleting static!

To be clear, the functions must be declared in the .c file without the static specifier as well.

Well I'd normally put a void in there but I don't know his compiler and whether it's considerd acceptable/normal to have an empty list.

Reply to
daven

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.