
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 // Test app to cause program to suddently terminate when using serial interrupt... 00004 // Line 24 seems to be the important bit, but I don't really understand why? 00005 // Is it perhaps the putc is peroperly clearing the interrupt flag instead of the getc? 00006 00007 00008 // usb serial device defaults to 9600 baud, 8N1 on /dev/ttyACM0 (in Linux!) 00009 Serial pc(USBTX, USBRX); // tx, rx 00010 00011 // debugging LEDs 00012 DigitalOut interrupt(LED1); 00013 DigitalOut tx(LED4); 00014 00015 // one byte receive buffer 00016 char rx_byte; 00017 00018 void handle() 00019 { 00020 interrupt = 1; 00021 //if(pc.readable()) // <--- this line doesn't matter either way... 00022 { 00023 rx_byte = pc.getc(); 00024 //pc.putc(rx_byte); // <--- WITHOUT THIS LINE, THE APPLICATION WILL HANG IF IT RECEIVES WHILE SENDING! 00025 } 00026 interrupt = 0; 00027 return; 00028 } 00029 00030 int main() 00031 { 00032 interrupt = 0; 00033 tx = 0; 00034 pc.attach(handle); 00035 00036 while(1) 00037 { 00038 // send a long string of bytes 00039 tx = 1; 00040 for(int i=0;i<20;i++) 00041 { 00042 NVIC_DisableIRQ(UART0_IRQn); 00043 pc.printf("If I receive while transmitting this I *won't* crash...\r\n"); 00044 NVIC_EnableIRQ(UART0_IRQn); 00045 } 00046 tx = 0; 00047 00048 wait(1.0); 00049 } 00050 }
Generated on Wed Jul 13 2022 20:53:42 by
