
A trivial example of a UART comm. Works on all Nucleos.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:389db7a2ed7f
- Child:
- 1:a149bb0c3d05
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 05 15:31:52 2015 +0000 @@ -0,0 +1,40 @@ +#include "mbed.h" + +//------------------------------------ +// Hyperterminal configuration +// 9600 bauds, 8-bit data, no parity +//------------------------------------ +void flushSerialPort(Serial* port); + +Serial pc(SERIAL_TX, SERIAL_RX); + +DigitalOut myled(LED1); + +int main() +{ + + pc.baud(115200); + int i = 1; + int q; + pc.printf("Hello World !\n"); + while(1) { + + wait(5); + pc.printf("This program runs since %d seconds.\n", i++); + myled = !myled; + flushSerialPort(&pc); + + if (pc.scanf("%d", &q)) + pc.printf("%d\n", q); + } +} + +void flushSerialPort(Serial* port) +{ + + while((*port).readable()) { + (*port).getc(); + } + + return; +}