9 years, 9 months ago.

Interruption and serial class !!

Hi, this is really a classic question, and I don't find previous response.

Using an interrupt from a serial link, why do I need to check the receive buffer (getc) inside the interrupt function (see listing below) and not outside (into the main program) using my ZAP booelan ? And why "attach" member don't need "Serial::RxIrq" to enable the interrupt origin ?

thanks

  1. include "mbed.h" Serial pc(USBTX, USBRX);

DigitalOut Led1(LED1); DigitalOut Led2(LED2);

bool ZAP=false; char TT;

void Change() { Led1=!Led1; ZAP=true; TT=pc.getc(); <- interrupt works with that ! }

int main() { pc.baud(115200); pc.attach(&Change);,Serial::RxIrq); <- don't need the RxIrq member ??

while(1) { if(ZAP) {TT=pc.getc(); ZAP=false; Led2=!Led2;} <- interrupt not works with that (without the previous code TT=pc.getc(); ) } }

Be the first to answer this question.