You are not allowed to use printf in an interrupt when using RTOS (see also the RTOS handbook page: http://mbed.org/handbook/RTOS).
Recently instead of Serial RawSerial library has been added, that should allow you to use putc and getc in an interrupt while using RTOS, but I don't think more than that.
What I believe is the 'proper' way to send stuff via Serial when a rising edge occurs: Add a thread which does what you want it to do (so send something via serial). Make sure it has while(1) { } around it. Now let this thread wait on a signal (explained in the handbook how to do it). Let the interrupt routine set the signal, which will print your message.
For the interrupt routine to set a signal it needs to know which thread he needs, so you need to store a pointer to the thread as a global variable. So something like:
Thread *pointer_to_thread;
void interruptFunction(void) {
pointer_to_thread->signal_set(0x1);
}
void yourPrintThread(void) {
while(1) {
Thread::signal_wait(0x1);
printf("w00t\n");
}
}
int main(void) {
Thread thread(yourPrintThread);
pointer_to_thread = &thread;
//rest of your stuff
}
That said, if you want using RawSerial you can probably also do it directly from the interrupt handler.
Hi,
I add the library RTos to my project and now I can't rise an interruption with the object InterruptIn. I put 3.3v in the pin 21 but nothing happens. I already see that other object like the Ticker doesn't work (I use RtosTimer instead of it).
Can you help me please ?
Thanks