Ram Bambo / Mbed 2 deprecated LPCXpresso11U68_USBSerial

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
rambambo
Date:
Wed Jul 24 12:12:14 2019 +0000
Parent:
0:1ec32b38f724
Commit message:
Quick and dirty program to receive keystrokes and send text via virtual serial port, it also flashes the green led with 1 millisecond pulses as life indicator. Unfortunally the mbed lib sends an error via serial when PwmOut is used

Changed in this revision

USBDevice.lib Show diff for this revision Revisions of this file
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
--- a/USBDevice.lib	Wed Jun 25 02:25:16 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/USBDevice/#0c6524151939
--- a/main.cpp	Wed Jun 25 02:25:16 2014 +0000
+++ b/main.cpp	Wed Jul 24 12:12:14 2019 +0000
@@ -1,38 +1,71 @@
+/* Quick and dirty program to receive keystrokes and send text via virtual
+ * serial port, it also flashes the green led with 1 millisecond pulses as
+ * life indicator
+ *
+ * Unfortunally the mbed lib sends an error via serial when PwmOut is used
+ *
+ * This program has been derived from
+ * https://os.mbed.com/users/Bongjun/code/LPC11U68_USBSerial/
+ *
+ */
+
 #include "mbed.h"
-#include "USBSerial.h"
 
-DigitalOut myled1(LED1);
-DigitalOut myled2(LED2);
-DigitalOut myled3(LED3);
+DigitalOut LED_rd(LED1);
+DigitalOut LED_gn(LED2);
+DigitalOut LED_bl(LED3);
+/*
+// PwmOut: mbed lib raises an error: no available SCT, even LED pins provide PWM
+    PwmOut LED_rd(LED1);
+    PwmOut LED_gn(LED2);
+    PwmOut LED_bl(LED3);
+    float brightness_LED_rd = 0.8;
+    float brightness_LED_gn = 0.4;
+    float brightness_LED_bl = 0.2;
+*/
 
 //Virtual serial port over USB
-USBSerial serial;
 Serial pc(USBTX, USBRX);
 
+volatile uint8_t    buf[] = {'\0', '\0'};   // buf[1]: string null terminator
+
+void onCharReceived()   // fills character buffer using rx interrupt
+{
+    buf[0] = pc.getc();
+}
+
 int main()
 {
-    uint8_t buf[1];
-    while(1) {
-//        pc.printf("I am a PC serial port\r\n");
-        serial.printf("I am a virtual serial port\r\n");
+    LED_rd = LED_gn = LED_bl = 1;           // LEDs off
+    pc.baud(115200);                        // from default = 9600
+    pc.attach(&onCharReceived);
+    pc.printf("\r\n\n\n#####  LPCXpresso11U68_USBSerial  #####\r\n\r\nPress any key at the PC keyboard!\r\n\r\n");
 
-        //if data is exist
-        if (serial.available()) {
-            buf[0] = serial._getc();
-            serial.printf("recv char is 0x%.2x\r\n", buf[0]);
-        }
+    while(1) {
+//uint32_t            counter = 0;            // Debug only
+//        pc.printf("%8d\r\n", counter++);    // Debug only
 
-        myled1 = 1;
-        wait(0.2);
-        myled1 = 0;
-        wait(0.2);
-        myled2 = 1;
-        wait(0.2);
-        myled2 = 0;
-        wait(0.2);
-        myled3 = 1;
-        wait(0.2);
-        myled3 = 0;
-        wait(0.2);
+        switch(buf[0])
+        {
+            case '\0':
+                break;
+            case 'a':
+                pc.printf("recv char IS THE EXPECTED 'a' = 0x%.2x\r\n", buf[0]);
+                break;
+            case 'b':
+                pc.printf("recv char IS THE EXPECTED 'b' = 0x%.2x\r\n", buf[0]);
+                break;
+            default:
+                pc.printf("recv char is not expected: ");
+                if (buf[0]<33)
+                    pc.printf("0x%.2x\r\n", buf[0]); // hex code, when non-printable char
+                else
+                    pc.printf("%s\r\n", buf);
+                break;
+        }
+        buf[0] = '\0';      // reset character buffer
+
+        LED_gn = 0; wait_ms(1);     // just one millisecond due to high brightness of green
+        LED_gn = 1; wait_ms(299);
     }
 }
--- a/mbed.bld	Wed Jun 25 02:25:16 2014 +0000
+++ b/mbed.bld	Wed Jul 24 12:12:14 2019 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file