InterruptIn across multiple program files

12 May 2010

I've written a program with a number of different graphical functions nested within different component files. My 'main' code directs the program to a menu system, which by using 2 seperate interrupts (defined as but1 and but2 in the header file), scrolls through the menu options and allows selection of one of the functions. This works fine.

The problem emerges when I attempt to link back to the menu from one of the graphical functions using one of the same interrupts, I'll write something like:

but1.fall(&menuscreen);

But the interrupt will not respond. I've tried a huge amount of different combinations of functions and rising & falling edge triggers, defining new interrupts on new pins, but after the first function with interrupts present, they will not work in any other function!

Can someone shed any light on this?

TIA,

Auberon

12 May 2010

Where do you define but1 and but2? Where is "menuscreen"? If you can publish your project, it will be easier to find the issue.

12 May 2010

Auberon Tatum wrote:
defined as but1 and but2 in the header file
'menuscreen' is in the 'menu' file, there is no problem in linking to this as it occurs normally in the program at the beginning:
Auberon Tatum wrote:
My 'main' code directs the program to a menu system

Auberon Tatum wrote:
This works fine.
I will publish the full code shortly

12 May 2010

The full code can be found here:

http://mbed.org/users/Aubs/programs/Accel_test_LCD1Modular

12 May 2010

 

Auberon Tatum wrote:

 

Auberon Tatum wrote:
defined as but1 and but2 in the header file

And this is the problem. You "worked around" the link errors by declaring the variables static, but this just gave you a separate copy in each of the files that includes the header. What you should do instead is the following. In header.h:

extern LIS302 acc;
extern MobileLCD lcd;
extern Serial pc;
extern InterruptIn but1;
extern InterruptIn but2;
extern InterruptIn but3;

In main.cpp (after including header.h):

LIS302 acc(p11,p12,p13,p14);        //define pinouts for accelerometer
MobileLCD lcd(p5,p6,p7,p8,p9);      //define pinouts for LCD
Serial pc(USBTX,USBRX);             //define pinouts for USB comms if needed
InterruptIn but1 (p21);
InterruptIn but2 (p22);
InterruptIn but3 (p23);
This way you declare the variables in the header, so that everyone can access them, but define them in one file, so you get a single instance of each variable in the program.

12 May 2010

Thanks Igor, I've implemented this but unfortunately the problem still remains...

12 May 2010

I think the problem is that Graphic() and other functions are called from the interrupt handler but they never return, so the new interrupts never get a chance to be handled.

13 May 2010

Can you reset the interupt withn the Graphic() and other functions using (NULL) or am i missing something else???

13 May 2010

I see, is there any way of re-setting the handler so I can use the next set of interrupts from another function?

Surely the header file defines the handler, so can be accessed by all?

13 May 2010

Does anybody have any other ideas about what might be causing this? Please?

13 May 2010 . Edited: 13 May 2010

Tried using a NULL command at the beginning of each function Danny, but I think all that is achieving is linking that particular interrupt to nothing at all. I would guess that there is a different syntax for clearing the register.

13 May 2010

You need to restructure your program so that interrupt handlers return.