test USART1 + USART6 on nucleo boards. Tested on a F401RE.

Dependencies:   mbed

Revision:
0:bc3ae66c3a9e
diff -r 000000000000 -r bc3ae66c3a9e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Apr 05 22:07:26 2020 +0000
@@ -0,0 +1,193 @@
+/*
+ * Investigate possible pins for USART1 and USART6 on a F401RE 
+ *
+ * Greg Blair, DSP Analytics, Toronto, Canada, April 2020
+ * 
+ * This Nucleo_usart126 code was hacked from Nucleo_U2andU1_Interrupt
+ * From: www.emcu.it
+ * Date: 29-06-2014
+ * Tested on NUCLEO_L152RE
+ * for more info see here: http://www.emcu.it/NUCLEOevaBoards/NUCLEOevaBoards.html#Tutorial
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ 
+ ++++++++++++++++++++++ CONFIGURATIONS +++++++++++++++++++++++++++++++
+ 
+ USART2 reads commands from the USB serial port
+ 
+ All 3 USART parameters are:
+   Baud Rate: 115200 
+   Data: 8
+   Parity: NONE
+   Stop: 1
+   Flow Control: NONE
+  
+ ++++++++++++++++++++++++++++++++ Pin setup ++++++++++++++++++++++++++
+ MCube F401RE pins
+   TX1 PA9  D8 CN10-21       alt PB6 D10 CN10-17
+   RX1 PA10 D2 CN10-33       alt PB7     CN7-21
+ 
+   TX2 PA2  D1 CN10-35       no alt
+   RX2 PA3  D0 CN10-37       no alt
+
+   TX6 PC6     CN10-4        alt PA11 CN10-14
+   RX6 PC7  D9 CN10-19       alt PA12 CN10-12
+   
+ These Nucleo boards should work with default pins, alt pins tested on F401RE
+   F030R8 F070RB F072RB F091RC 
+   F302R8 F303RE F334R8
+   F401RE F411RE F446RE
+   G070RB G071RB
+   L053R8 L073RZ L152RE
+   L476RG F410RB
+   WB55 <- in mbed board list error: Target "NUCLEO_WB55RG" is not recognized
+     board=P-NUCLEO-WB55
+
+ ++++++++++++++++++++++ How to use this example ++++++++++++++++++++++
+ Press the Blue Button 
+ Press the 1 keyboard key
+ Press the 6 keyboard key
+ 
+ A green led blink acknowledges a 1 or 6 character was received on USART 1 or 6
+*/
+
+#include "mbed.h"
+
+DigitalOut myled(LED1);              // LED: nucleo LD2
+DigitalIn  BlueButton(USER_BUTTON);  // Blue-Button
+#define RX1n PA_10
+#define TX1n PA_9 
+#define RX1a PB_7
+#define TX1a PB_6
+   
+#define RX6n PC_7
+#define TX6n PC_6
+#define RX6a PA_12
+#define TX6a PA_11
+
+///////////////////////////////////////////////////
+
+// jumper PA9 D8 CN10-21 - PB7 CN7-21          (ARDUINO HEADER D8 CONFLICTS) 
+#define TX1 TX1n
+#define RX1 RX1a
+
+// jumper PB6 D10 CN10-17 - PA10 D2 CN10-33    (ARDUINO HEADER D2,D10 CONFLICTS)  
+// #define TX1 TX1a
+// #define RX1 RX1n
+Serial Serial1(TX1, RX1);            // USART1
+
+Serial pc(SERIAL_TX, SERIAL_RX);     // USART2, USB virtual serial port
+
+// jumper PC6 CN10-4 - PC7 D9 CN10-19          (ARDUINO HEADER D9 CONFLICTS)  
+// #define TX6 TX6n
+// #define RX6 RX6n
+
+// jumper PA12 CN10-12 - PA11 CN10-14          (NO ARDUINO HEADER CONFLICT)
+#define TX6 TX6a 
+#define RX6 RX6a
+Serial Serial6(TX6, RX6);            // USART6
+
+enum { Pressed, NotPressed } BUTTON_STATE_t;
+enum { LED_OFF, LED_ON }     11LED_STATE_t;
+
+int Cmd=0;
+int rx1=0;
+int rx6=0;
+
+///////////////////////////////////////////////////
+
+// Serial receive character interrupt handlers, minimal processing
+void USART1_INT()
+{
+    rx1 = Serial1.getc();  // read from serial1 to clear the interrupt
+}
+
+void USART2_INT()
+{
+    Cmd = pc.getc();       // read from serial2 to clear the interrupt
+}
+
+void USART6_INT()
+{
+    rx6 = Serial6.getc();  // read from serial6 to clear the interrupt
+}
+
+int main() 
+{
+    myled = LED_OFF;
+    
+    // SetUp the interrupt handlers
+    Serial1.attach(&USART1_INT);
+    pc     .attach(&USART2_INT);
+    Serial6.attach(&USART6_INT);
+
+    // SetUp the baud rate
+    Serial1.baud(115200);
+    pc     .baud(115200);
+    Serial6.baud(115200);
+    
+    pc.puts("\033[2J");                           // clear screen
+    pc.puts("Compiled " __DATE__ " at " __TIME__ " GMT by g++ " __VERSION__ "\r\n");
+    pc.puts("press 1 to test USART1\r\n");
+    pc.puts("press 6 to test USART6\r\n");
+    pc.puts("press the blue button\r\n");
+    pc.puts("led flashes if USART1 receives a 1 or USART6 6 receives a 6\r\n");
+        
+    while(1) {
+        // Blue Button
+        if (BlueButton == Pressed) {
+            pc.puts("Please release the BLUE Button\n\r");
+            while(BlueButton == Pressed);  // spin. wait for release
+            
+            Serial1.putc('1');
+            Serial6.putc('6');
+            pc.puts("Blue button --- sent 1+6 to USART 1+6\n\r");
+        }
+
+        // process commands
+        switch(Cmd) {
+            case '1':
+                Serial1.putc('1');
+                pc.puts("Sent 1 to USART1\n\r");
+                Cmd = '\0';
+                break;
+            case '6': 
+                Serial6.putc('6');
+                pc.puts("Sent 6 to USART6\n\r");
+                Cmd = '\0';
+                break;
+        }
+
+        // process received characters
+        if (rx1 == '1') {
+            pc.puts("USART1 received 1\n\r");
+            myled = LED_ON;
+            wait(.1);
+            myled = LED_OFF;
+            rx1 = '\0';
+        }
+        if (rx6 == '6') {
+            pc.puts("USART6 received 6\n\r");
+            myled = LED_ON;
+            wait(.1);
+            myled = LED_OFF;
+            rx6 = '\0';
+        }
+    } // while(1)
+}
\ No newline at end of file