Simply UART communication for STM32F0 Discovery using mbed. Received char is sent back to the computer.
Dependencies: mbed
Revision 4:61f0ff55c75d, committed 2015-05-12
- Comitter:
- Foxnec
- Date:
- Tue May 12 09:11:43 2015 +0000
- Parent:
- 3:edbb83dae353
- Commit message:
- Changes to comments
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Apr 04 14:32:38 2015 +0000 +++ b/main.cpp Tue May 12 09:11:43 2015 +0000 @@ -25,20 +25,20 @@ /* Function prototypes -----------------------------------------------------------*/ /* Variables ---------------------------------------------------------------------*/ -char buffer[255]; // for receive more characters from the computer -int received=0; // how many characters was received from computer -int sent=0; // how many characters was sent to computer +char buffer[255]; // for receiving more characters from the computer +int received=0; // how many characters were received from computer +int sent=0; // how many characters were sent to computer // mbed - initialization of peripherals -Serial pc(PA_9, PA_10); // inicialize SERIAL_TX=PA_9, SERIAL_RX=PA_10 -DigitalOut blue(PC_8); // inicialize blue LED on STM32F0 discovery -DigitalOut green(PC_9); // inicialize green LED on STM32F0 discovery +Serial pc(PA_9, PA_10); // initialize SERIAL_TX=PA_9, SERIAL_RX=PA_10 +DigitalOut blue(PC_8); // initialize blue LED on STM32F0 discovery +DigitalOut green(PC_9); // initialize green LED on STM32F0 discovery /* Functions----------------------------------------------------------------------*/ /******************************************************************************* * Function Name : serialRx. -* Description : Saves all received charracters to the buffer. +* Description : Saves all received characters to the buffer. * Input : None * Output : None. * Return : None @@ -46,9 +46,9 @@ void serialRx() { - while(pc.readable()) { // while there is a character available to read. + while(pc.readable()) { // while there is a character to read from the serial port. char c=pc.getc(); // receive the charracter - buffer[received++]=c; // save the charracter to the next place in buffer, increments number of received charracters + buffer[received++]=c; // save the charracter to the next place in buffer, increments number of received charactbers } } @@ -78,9 +78,9 @@ // pc.baud(9600); //-------------------------------------- - int i = 1; // inkrements every second + int i = 1; // increments 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 be called 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