usart test

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
nameless129
Date:
Mon Jun 30 02:05:10 2014 +0000
Commit message:
rasPiUsatTest

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
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
diff -r 000000000000 -r 8848a3fcb99c mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Jun 30 02:05:10 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721
\ No newline at end of file