Junaid Ahmed
/
hw2
uart communication
Revision 0:46e2bf06ec86, committed 2014-03-07
- Comitter:
- mja054
- Date:
- Fri Mar 07 23:14:41 2014 +0000
- Commit message:
- homework 2
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 46e2bf06ec86 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Mar 07 23:14:41 2014 +0000 @@ -0,0 +1,56 @@ +#include "mbed.h" +#define BAUD_RATE 921600 +#define INITIATER 0 + +// http://mbed.org/platforms/FRDM-KL46Z/ + +DigitalOut myled(LED_GREEN); +Serial pc(USBTX, USBRX); +Serial uart(PTE0, PTE1); + +char num = 0; + +void receiver_send() +{ + while(1) { + wait(1); + uart.putc(num); + num += 2; + myled = !myled; + } +} + +void send(char c) +{ + uart.putc(c); +} + +void read() +{ + myled = !myled; + char c = uart.getc(); + num += 2; +// send(num); + if (INITIATER) + pc.printf("%d\n", c); +} + +int main() { + pc.baud(BAUD_RATE); + uart.baud(BAUD_RATE); + + if (INITIATER) { + uart.attach(read); + num = 1; + uart.putc(num); + } else { + num = 0; + receiver_send(); + } + + pc.printf("Hello World\n"); + + while (true) { + wait(0.5); + } +} \ No newline at end of file
diff -r 000000000000 -r 46e2bf06ec86 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Mar 07 23:14:41 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/8e73be2a2ac1 \ No newline at end of file