Simon Ford / Mbed 2 deprecated SerialInterruptFix

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // using 2 serial instances to workaround hand bug while using printf both inside and outside interrupt
00002 
00003 #include "mbed.h"
00004 
00005 Serial pc(USBTX, USBRX); // tx, rx
00006 Serial pc2(USBTX, USBRX); // tx, rx
00007 
00008 // debugging LEDs
00009 DigitalOut interrupt(LED1);
00010 DigitalOut tx(LED4);
00011 
00012 void handle() {
00013     char rx_byte = pc2.getc();
00014     interrupt = !interrupt;
00015 }
00016 
00017 int main() {
00018     pc2.attach(handle);
00019 
00020     while (1) {
00021         // send a long string of bytes
00022         tx = 1;
00023         for (int i=0;i<20;i++) {
00024             printf("If I receive while transmitting this I will crash...\r\n");
00025         }
00026         tx = 0;
00027         wait(1.0);
00028     }
00029 }