fxz

Dependencies:   mbed

Fork of RS232_3 by ABELI

Files at this revision

API Documentation at this revision

Comitter:
AndreasSchoegler
Date:
Tue Jun 09 17:41:05 2015 +0000
Commit message:
sd

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 66682d3a234e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jun 09 17:41:05 2015 +0000
@@ -0,0 +1,86 @@
+#include "mbed.h"
+
+
+InterruptIn iiUp(p15);
+Timer timer1;
+int los=0;
+
+// global vars and objects
+DigitalOut led2(LED2);
+Serial pc(USBTX, USBRX); // tx, rx    ; is default !!! (9600, 8N1)
+char recChar=0;
+bool recFlag=false;
+char recArr[20];
+int index=0;
+
+// functions
+void flushSerialBuffer() { 
+    while (pc.readable()) { 
+        pc.getc(); 
+    } 
+}
+    
+void readData() {
+    
+    if(los>=1)
+    {
+    recChar = pc.getc();
+    recArr[index] = recChar;
+    index++;
+    if ((recChar == '\r') || (index>=19)) {
+        recFlag = true;
+        recArr[index] = 0;
+        
+        float t = timer1.read_ms();
+        pc.printf(" - That's the input: %f L= %d %s\r\n", t,index,recArr); 
+        if(index<5)
+        {
+           pc.printf("Eingabe zu kurz ");  
+        }
+        if(index>10)
+        {
+           pc.printf("Eingabe zu lang ");  
+        }
+        index = 0; 
+        timer1.stop();
+        timer1.reset();
+        flushSerialBuffer();
+        los=0;
+        
+    }
+ }
+}
+ 
+ void SendText()
+ {
+    
+   pc.printf("Geben Sie ein Wort mit mindestens 5 und maximal 10 ein:"); 
+   timer1.start(); 
+   los=1;   
+    
+ }
+    
+int main() {
+//    pc.baud(115200);
+    pc.baud(38400);
+    pc.format(8, SerialBase::Odd, 2);
+    led2 = 1;
+
+    flushSerialBuffer();
+    pc.printf("Hello RS232-USB Virtual Serial Port -World!\r\n");
+    
+    
+    pc.attach(&readData);
+    
+    
+    iiUp.rise(&SendText);
+    
+    while(1) {
+        if (recFlag) {
+            flushSerialBuffer();
+//            pc.printf(" - That's the input: %s\r\n", recArr);  // non reantrant function
+            recFlag = false;
+            led2 = !led2;
+        }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 66682d3a234e mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Jun 09 17:41:05 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/cbbeb26dbd92
\ No newline at end of file