Reception of multiple characters over UART without interrupting the program. Uses 2 input buffers.
Dependencies: mbed
Fork of Nucleo-getc by
Revision 4:472805b710a0, committed 2015-08-05
- Comitter:
- mfwic
- Date:
- Wed Aug 05 23:03:52 2015 +0000
- Parent:
- 3:e316c5e314e1
- Commit message:
- Test publish for imported code
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r e316c5e314e1 -r 472805b710a0 main.cpp --- a/main.cpp Tue May 12 09:31:21 2015 +0000 +++ b/main.cpp Wed Aug 05 23:03:52 2015 +0000 @@ -1,10 +1,12 @@ +//RK: User enters mulitple characters from keyboard terminated with Enter/Return. +//Only recognizes numbers. Limit of 10. Overrun caused negative results. /********************************************************************************** * @file main.cpp * @author Petr Dousa * @version V1.00 * @date 22-March-2015 * @brief Every single second push to serial message and read from serial -* Serial speed is set to 115200. +* Serial speed is set to 9600. ***********************************************************************************/ /* Includes ----------------------------------------------------------------------*/ @@ -127,21 +129,22 @@ //array for data that are coming to user char * prijata_data; - pc.baud(115200); // set serial speed to 115200 + pc.baud(9600); // set serial speed to 9600 pc.attach(&serialRx,Serial::RxIrq); // attach serialRx to reception interrupt - pc.printf("Hello World !\n"); + //pc.attach(&serialRx); + pc.printf("Hello World !\r\n"); while(1) { - wait_ms(10); // wait 1 second + wait_ms(10); // wait 10 milliseconds if(serialGetBuffer(prijata_data)) { // get char array from serial sscanf (prijata_data,"%d",&j); // sscanf for searching integer - pc.printf("From PC:%d.\n" ,j); // write to serial incoming integer + pc.printf("From PC:%d.\r\n" ,j); // write to serial incoming integer } k++; - if (k>=100) { - pc.printf("This program runs since %d seconds.\n", i++); // write some string to serial + if (k>=6000) { //print once per second + pc.printf("This program running for %d minutess.\r\n", i++); // write some string to serial myled = !myled; // blink LED