7 years, 1 month ago.

Why does the mbed hang when I don't duplicate an interrupt function in main()?

I have an odd error I can't get my head around...

I have an interrupt, and SD card interfaced use the SDBlockDevice (sd-driver) library in an official mbed Git repo (but not part of mbed-os).

I have a function 'TRIG' which opens a file, writes to it and closes it. The TRIG function is called by an interrupt.

If I call it, the mbed hangs with a flashing LED (4 slow pulses, 4 fast pulses)...

HOWEVER!

If I have the same function statements in the main() AND the TRIG (as shown below), the interrupt works and writes to the SD card!!!

I am completely confused about what is happening here?

CODE THAT WORKS:

void TRIG() {
    wait(1);
    FILE* fy = fopen("/sd/number.txt", "a");
    wait(1);
    fprintf(fy, "test4343\n");
    fclose(fy);
}


int main() {

    wait(1);
    FILE* fd = fopen("/sd/number.txt", "a");
    wait(1);
    fprintf(fd, "test\n");
    fclose(fd);

    switch_a.rise(&TRIG);

CODE THAT DOESN'T WORK:

void TRIG() {
    wait(1);
    FILE* fy = fopen("/sd/number.txt", "a");
    wait(1);
    fprintf(fy, "test4343\n");
    fclose(fy);
}


int main() {


    switch_a.rise(&TRIG);
Be the first to answer this question.