usart test

Dependencies:   mbed

Revision:
0:8848a3fcb99c
diff -r 000000000000 -r 8848a3fcb99c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jun 30 02:05:10 2014 +0000
@@ -0,0 +1,50 @@
+#pragma import __use_all_ctype
+
+#include "mbed.h"
+#include <stdlib.h>
+
+Serial pc(USBTX, USBRX);
+Serial pi(p9, p10);  // tx, rx
+
+bool f_rcev = 0;
+unsigned int c_rcev = 0;
+char uartBuff[1000];
+char uartRcev[1000];
+
+void callback() {
+    char buf = 0;
+
+    buf = pi.getc();
+    uartBuff[c_rcev] = buf;
+    if(uartBuff[c_rcev] == '\r' )
+    {
+        uartBuff[c_rcev+1] = 0;
+        memcpy(uartRcev,uartBuff,sizeof(uartRcev) );
+        memset(uartBuff,0,sizeof(uartBuff));
+        c_rcev = 0;
+        f_rcev = 1;
+    }
+    else
+    {
+        c_rcev++;
+    }
+}
+
+int main(void) {
+
+    pi.baud(115200);
+    pc.baud(115200);
+    pi.attach(&callback);
+
+    while (1) 
+    {
+        if(f_rcev == 1)
+        {
+//            printf("\033[2J");
+//            printf("\033[1;1H");
+//            printf("%s\r\n",uartRcev);
+            puts(uartRcev);
+            f_rcev = 0;
+        }
+    }   
+}
\ No newline at end of file