My GPIO tests

Fork of Nucleo_toggle_ios by Nathan Yonkee

Files at this revision

API Documentation at this revision

Comitter:
ElenaTosetti
Date:
Thu Feb 22 15:38:20 2018 +0000
Parent:
1:54c670dd698f
Commit message:
Added loop

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Apr 21 19:57:11 2017 +0000
+++ b/main.cpp	Thu Feb 22 15:38:20 2018 +0000
@@ -1,13 +1,106 @@
 #include "mbed.h"
- 
-#define IOS (0xA0) // PA_5 + PA_7
- 
-PortOut myIOs(PortA, IOS);
+
+
+#include <string.h>
+
+#define BAUD_RATE 115200
+
+
+
+DigitalOut PA9IOs(PA_9);
+DigitalOut PA10IOs(PA_10);
+DigitalOut PA11IOs(PA_11);
+DigitalOut PA12IOs(PA_12);
+
+DigitalOut PB4IOs(PB_4);
+DigitalOut PB5IOs(PB_5);
+DigitalOut PB6IOs(PB_6);
+DigitalOut PB7IOs(PB_7);
+
+DigitalOut PB12IOs(PB_12);
+DigitalOut PB13IOs(PB_13);
+DigitalOut PB14IOs(PB_14);
+DigitalOut PB15IOs(PB_15);
+
+DigitalOut PC6IOs(PC_6);
+DigitalOut PC7IOs(PC_7);
+DigitalOut PC8IOs(PC_8);
+DigitalOut PC9IOs(PC_9);
+
+Serial s(USBTX, USBRX); //default for nrf51 is p0.09 p0.11
+
+
+// Command string
+char action[256];
+char command[12];
+unsigned short val;
+
+#define N_ITERATIONS 1120
+void gpio_action(){
+//    for(i = 0; i <= 1119; i++)
+//               {
+    PA9IOs = 0; // SET PA9
+    PB4IOs = 0; // SET PB4
+    PC6IOs = 0; // SET PC6
+    PB12IOs = 0; // SET PB12
+    wait(10); // wait 440 seconds
+    PA10IOs = 0; // SET PA10
+    PB5IOs = 0; // SET PB5
+    PC7IOs = 0; // SET PC7
+    PB13IOs = 0; // SET PB13
+    wait(2.5); // wait 2.5 seconds
+    PA10IOs = 1; // RESET PA10
+    PB5IOs = 1; // RESET PB5
+    PC7IOs = 1; // RESET PC7
+    PB13IOs = 1; // RESET PB13
+//}
+}
+
+int i;
+int run  = 1;
  
-int main() {
-    while(1) {   
-        myIOs = myIOs ^ IOS; // Toggle IOs level
-        wait(0.5); // 500 ms
-    }
+int main() { 
+  
+    s.baud(BAUD_RATE);
+
+    //Reset EN_1_1 and EN_1_2
+    PA9IOs = 1; // RESET PA9
+    PA10IOs = 1; // RESET PA10  
+    //Reset EN_2_1 and EN_2_2
+    PB4IOs = 1; // RESET PB4
+    PB5IOs = 1; // RESET PB5
+    //Reset EN_3_1 and EN_3_2
+    PB12IOs = 1; // RESET PB12
+    PB13IOs = 1; // RESET PB13
+    //Reset EN_4_1 and EN_4_2
+    PC6IOs = 1; // RESET PC6
+    PC7IOs = 1; // RESET PC7
+    run:
+        s.printf("Action:\r\n");
+        int count;
+        s.scanf( "%s %d" , action, &count);  
+        if (strstr(action, "START") != NULL){
+                i = 0;
+                s.printf("START command\r\n");
+                while(i<count && run){
+                    s.printf("Start iteration %d\r\n", i);
+                    gpio_action();
+                    s.printf("Done iteration %d\r\n", i);
+                    i++;
+                }
+                
+                goto run;
+        
+        } else {
+
+           s.printf("ERROR: %s unhandled action\r\n",action);
+           }
+           
+
+
+    
+
+     
+
 }
  
\ No newline at end of file