Disable interrupt within interrupt

I am having issues with this interrupt, when it is called it keeps recalling and getting stuck in itself
therefor i think disabling from within would be the only solution i can think of. any ideas of how to do this?

Hello Jack,

Try to disable it by detaching the callback:

void callback() {
    device.attach(NULL);  // detach the callback
   ...
}

Then re-attach it as follows:

while (1) {
    if (global) {
        ...
        device.attach(&callback);
    }
....

Try to publish your code here as formatted text by prepending and appending it with three back-tick characters ``` on a separate line. It will enable people to copy & paste and modify it. A picture does not allow that.

Best regards, Zoltan

Hi Zoltan thanks for the advice however it throws the same error so am unsure how to solve this is the interrupt cannot be solved within itself.

#include "mbed.h"

Serial device(PC_12, PD_2);

bool global = 0;
int holding;

void callback() {
    global = 1;
    device.attach(NULL);
}

int main() {

    device.attach(&callback);

    while(1){
        if(global){
            char read[4];
            uint32_t hold = 0;
            device.gets(read,4);
            hold = (read[3]<<24)+(read[2]<<16)+(read[1]<<8)+read[0];
            printf("%X",hold);
            global = 0;
            device.attach(&callback);
        }
        wait(0.5);
        printf("waiting\r\n");
    }
}

Hi there,

look at this, maybe it will help.

BR, Jan

Hello Jack,

Because Mbed OS 6 doesn’t allow to use the device in ISR context one option is to use EventQueue rather than ISR. To save RAM you can try to use application’s shared event queue:

#include "mbed.h"

BufferedSerial  device(PC_12, PD_2);
EventQueue*     eventQueue;
volatile bool   global = 0;
int             holding;

void callback()
{
    device.attach(NULL);
    global = 1;
}

int main()
{
    eventQueue = mbed_event_queue();
    device.attach(eventQueue->event(callback), BufferedSerial::RxIrq);

    while (1) {
        if (global) {
            char        read[4];
            uint32_t    hold = 0;
            device.gets(read, 4);
            hold = (read[3] << 24) + (read[2] << 16) + (read[1] << 8) + read[0];
            printf("%X", hold);
            global = 0;
            device.attach(eventQueue->event(callback), BufferedSerial::RxIrq);
        }

        //ThisThread::sleep_for(500);
        //printf("waiting\r\n");
    }
}

Best regards, Zoltan