Interrupt In hangup

I have a problem when employing InterruptIn on NXP LPC1768, using OS 6.2. Apparently invoking the .rise() method the program is stuck till first activation of the interrupt. The code below has revealed the problem. The program does not reach “second checkpoint” unless the switch connected to P18 is pushed once. Subsequently the program runs as expected.

Is this problem known to anybody else?

#include "mbed.h"
#include <cstdio>
InterruptIn bryter(p18);
volatile int telle=0;
void bryterkontroll(){
    telle++;
}

int main(){
    int tellehusk=0;
    printf ("First checkpoint");
    bryter.mode(PullDown);   
    bryter.rise(&bryterkontroll);
    tellehusk=telle;
    printf ("\n\r second checkpoint"); //second checkpoint

    while (true) {               
        if(telle!=tellehusk) { // writes the number of clicks when changed
            printf( "\n\r Number of clicks %d ",telle);
            tellehusk=telle;
        }
    }
}

Ahoj,

yes, but… all your problems are caused by your using of the printf.
Place the \n at the end of all printf and your code will be ok.
This maybe help to understand it.

BR, Jan

Hi Jan and thanks for answering.

That does not help. Actually the printf-statements were added for debugging purpose only, after the problem was discovered.

BR
Geir Helge

Hello Geir Helge,

Replace

bryter.rise(&bryterkontroll);

with

bryter.rise(callback(bryterkontroll));

NOTE: It’s a common practice to have the carriage return character first followed by the new line one, like:

printf("Hello, World\r\n");

Best regards, Zoltan

Thanks a lot!

Regards GH