Serial interrupt

24 Jun 2011

Hello, I have the next code that I would expect to flip the led every time I send a character from the PC to the mbed. However, the led keeps on blinking after the first character. Any idea of what can be wrong ? Regards, Juan

#include "mbed.h"

DigitalOut clk(LED1);
DigitalOut dat(LED2);
DigitalOut enable(LED3);
DigitalOut bit(LED4);

void flip() {
    clk = !clk;
}



Timeout flipper;
Serial pc(USBTX, USBRX);

int main() {
    clk = 1;
    pc.attach(&flip,Serial::RxIrq);
    while(1) {
    }
}
24 Jun 2011

Not sure how the Mbed library actually clears the condition that triggered the interrupt, but as a first step, try actually reading the character to ensure any input buffer is cleared:-

See if this makes any difference. Also, try adding echo to make sure what goes in comes out (for debugging purposes).

#include "mbed.h"

DigitalOut clk(LED1);
DigitalOut dat(LED2);
DigitalOut enable(LED3);
DigitalOut bit(LED4);

Serial pc(USBTX, USBRX);
Timeout flipper;

void flip(void) {
    pc.putc( pc.getc() );
    clk = !clk;
}

int main() {
    clk = 1;
    pc.attach(&flip,Serial::RxIrq);
    while(1) {
    }
}

24 Jun 2011

That works perfectly, thanks Andy

05 Sep 2019

the same code not working on STM32F429VIT. What is problem may be?