Simply UART communication for STM32F0 Discovery using mbed. Received char is sent back to the computer.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 2:3f9a1eb39b79
- Parent:
- 1:2cae2115481a
- Child:
- 3:edbb83dae353
--- a/main.cpp Sun Mar 22 12:17:15 2015 +0000 +++ b/main.cpp Sat Apr 04 11:15:32 2015 +0000 @@ -38,7 +38,18 @@ // Hyperterminal configuration is default // 9600 bauds, 8-bit data, no parity //-------------------------------------- - +// Communication settings: +// pc.format(bits,parity,stop_bits) +// bits: 5-8 +// parity: SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0 +// stop_bits: 1 or 2 +// pc.baudrate(baud) +// baud: The desired baudrate (speed) +//-------------------------------------- +// Example for default settings: +// pc.format(8,SerialBase::None,1); +// pc.baud(9600); +//-------------------------------------- /* Functions----------------------------------------------------------------------*/ @@ -48,11 +59,11 @@ * Input : None * Output : None. * Return : None -*******************************************************************************/ +*******************************************************************************/ void serialRx() { - while(pc.readable()) { // while there is a character available to read. + while(pc.readable()) { // while there is a character available to read. char c=pc.getc(); // receive the charracter buffer[received++]=c; // save the charracter to the next place in buffer, increments number of received charracters } @@ -69,7 +80,7 @@ { int i = 1; // inkrements every second pc.printf("Program started !\r\n"); // text displayed on a computer - pc.attach(&serialRx,Serial::RxIrq); // Attach a function serialRx to call whenever a serial interrupt is generated + pc.attach(&serialRx,Serial::RxIrq); // Attach a function serialRx to call whenever a serial interrupt is generated while(1) { while(sent<received) { // while the number of received characters is greater than the number of sent characters pc.printf("Received char: %c (%d).\r\n", buffer[sent],(int)buffer[sent]); // send the character and the character number