ok, now we can see the program in full context. So this code has real meaning:-
int main() {
pbone.rise(&execute);
pbtwo.rise(&selectChoice);
menu();
while(1){
}
}
Your entire program is driven by interrupts! This really isn't the way to go about doing this. As said before, while one InterruptIn callback is executing, any other InterruptIns that activate will NOT execute until the first one returns. Your stuck in interrupt deadlock. All InterruptIns use the same IRQ so they all get the same priority. You cannot raise one above another.
You really need to redesign this keeping your program running in "user context" and do as little as possible in "Interrupt context". For example:-
#include "mbed.h"
InterruptIn pbone(p7);
InterruptIn pbtwo(p8);
bool pbonePressed = false;
bool pbtwoPressed = false;
void pboneCallback(void) { pbonePressed = true; }
void pbtwoCallback(void) { pbtwoPressed = true; }
int main() {
pbone.rise(&pboneCallback);
pbtwo.rise(&pbtwoCallback);
while(1) {
if (pbonePressed) {
pbonePressed = false;
// Do actions required when button one is pressed.
}
if (pbtwoPressed) {
pbtwoPressed = false;
// Do actions required when button two is pressed.
}
}
}
As you can see from the above, the callbacks just set a flag. In the main() while(1) loop you detect these presses and act accordingly. If you are in a function that needs to break when button two is pressed for example, break the loop on pbtwoPressed going true. But so long as that function is called from main loop and NOT by another interrupt, it'll break the loop. But if you invoked a function that loops from a callback you will never see pbtwoPressed going true.
Try to stay in "user context" and use the interrupts sparingly. Don't execute your entire program from callbacks or you'll never get it to work (and if you did, slight minor changes or mods later will bring down the house of cards).
Hi
I'm using a push-button to control when to enter a function.The function as shown below depends on the value of the index variable.I have set the attached interrupt function so that the index is set to 0 whenever the push-button is pressed.
Unless I am completely mistaken I thought that interrupts operated asynchronously in relation to the main program flow, so I was expecting that when pressed the function would return, but this is not what I'm seeing. The variable keeps incrementing and everything is blocked.
What I want is to update the index variable asynchronously when I push the button. Is there a way to do this using interrupts? (I don't want to use a ticker in this case)