EasyCAT LAB - EtherCAT master simple example

Dependencies:   SOEM SPI_TFT_ILI9341 TFT_fonts

  • This repository contains a simple example for the EasyCAT LAB , a complete educational and experimental EtherCAT® system, composed of one master and two slaves.

Note

  • This example uses two LAB 2 slaves.

Note

  • In this example only two bytes of data are exchanged between the slaves and are also visualized on the TFT display.

Files at this revision

API Documentation at this revision

Comitter:
EasyCAT
Date:
Wed Oct 25 14:42:52 2023 +0000
Parent:
3:9c8c179d1f8a
Commit message:
Bug fix

Changed in this revision

config.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 9c8c179d1f8a -r cbef7fa67d5f config.h
--- a/config.h	Wed Oct 25 13:44:06 2023 +0000
+++ b/config.h	Wed Oct 25 14:42:52 2023 +0000
@@ -6,8 +6,8 @@
 
 //------------------------------------------------------------------------------
 
-#define LAB_2_1             1
-#define LAB_2_2             2
+#define LAB_1             1
+#define LAB_2             2
 
 #define SLAVE_NUM           2
 
@@ -22,13 +22,13 @@
 typedef struct __attribute__((__packed__))
 {
     uint8_t     Segments;
-}out_LAB_2_1t;
+}out_LAB_1t;
 
 typedef struct __attribute__((__packed__))
 {
     uint16_t    Potentiometer;              // in this example we don't use the    
     uint8_t     Buttons;                    // potentiometer but we have to 
-}in_LAB_2_1t;                               // declare it in the data structure
+}in_LAB_1t;                                 // declare it in the data structure
 
 
 //------------------------------------------------------------------------------
@@ -36,22 +36,22 @@
 typedef struct __attribute__((__packed__))
 {
     uint8_t     Segments;
-}out_LAB_2_2t;
+}out_LAB_2t;
 
 typedef struct __attribute__((__packed__))
 {
     uint16_t    Potentiometer;              // in this example we don't use the 
     uint8_t     Buttons;                    // potentiometer but we have to 
-}in_LAB_2_2t;                               // declare it in the data structure
+}in_LAB_2t;                                 // declare it in the data structure
 
 
 //------------------------------------------------------------------------------
 
-out_LAB_2_1t    *out_LAB_2_1;
-in_LAB_2_1t     *in_LAB_2_1;
+out_LAB_1t    *out_LAB_1;
+in_LAB_1t     *in_LAB_1;
 
-out_LAB_2_2t    *out_LAB_2_2;
-in_LAB_2_2t     *in_LAB_2_2;
+out_LAB_2t    *out_LAB_2;
+in_LAB_2t     *in_LAB_2;
 
 
 //------------------------------------------------------------------------------
@@ -62,11 +62,11 @@
 
 void MapLocalStructures (void)
 {
-    out_LAB_2_1 = (out_LAB_2_1t*)((char *)ec_slave[LAB_2_1].outputs - &IOmap[0] + &IOmapSafe[0]);
-    in_LAB_2_1 =  (in_LAB_2_1t*)((char *)ec_slave[LAB_2_1].inputs - &IOmap[0] + &IOmapSafe[0]);                
+    out_LAB_1 = (out_LAB_1t*)((char *)ec_slave[LAB_1].outputs - &IOmap[0] + &IOmapSafe[0]);
+    in_LAB_1 =  (in_LAB_1t*)((char *)ec_slave[LAB_1].inputs - &IOmap[0] + &IOmapSafe[0]);                
     
-    out_LAB_2_2 = (out_LAB_2_2t*)((char *)ec_slave[LAB_2_2].outputs - &IOmap[0] + &IOmapSafe[0]);
-    in_LAB_2_2 =  (in_LAB_2_2t*)((char *)ec_slave[LAB_2_2].inputs - &IOmap[0] + &IOmapSafe[0]);                
+    out_LAB_2 = (out_LAB_2t*)((char *)ec_slave[LAB_2].outputs - &IOmap[0] + &IOmapSafe[0]);
+    in_LAB_2 =  (in_LAB_2t*)((char *)ec_slave[LAB_2].inputs - &IOmap[0] + &IOmapSafe[0]);                
 }
 
 
@@ -79,10 +79,10 @@
    if (ec_slavecount != SLAVE_NUM)                          // check if the number of slaves matches what we expect
       return 0;                                             
                                                             
-   if (strcmp(ec_slave[LAB_2_1].name,"LAB_2"))              // verify slave by slave that the slave names are correct  
+   if (strcmp(ec_slave[LAB_1].name,"LAB_1"))              // verify slave by slave that the slave names are correct  
       return 0;
    
-   else if (strcmp(ec_slave[LAB_2_2].name,"LAB_2"))
+   else if (strcmp(ec_slave[LAB_2].name,"LAB_2"))
       return 0;
       
   return 1;
diff -r 9c8c179d1f8a -r cbef7fa67d5f main.cpp
--- a/main.cpp	Wed Oct 25 13:44:06 2023 +0000
+++ b/main.cpp	Wed Oct 25 14:42:52 2023 +0000
@@ -441,7 +441,7 @@
         
                                                                     //----- slave LAB_2_1 data management ------            
                                                                     //    
-        Buttons_1 = in_LAB_2_1->Buttons;                            // read the buttons status from the slave  
+        Buttons_1 = in_LAB_1->Buttons;                              // read the buttons status from the slave  
                                                                     //            
         if (Buttons_1 != PrevButtons_1)                             // check if the buttons value has changed
         {                                                           //
@@ -449,14 +449,14 @@
             DrawButtons_1_Value(Buttons_1);                         // draw the current buttons value on the TFT                                                                                              
         }                                                           //
                                                                     //
-        out_LAB_2_1->Segments = Buttons_2;                          // send to the slave the buttons status
+        out_LAB_1->Segments = Buttons_2;                            // send to the slave the buttons status
                                                                     // from the slave LAB_2_2                  
 
                                                                                                                     
                                                                     
                                                                     //----- slave 2_2 data management ----------                                                                      
                                                                     //
-        Buttons_2 = in_LAB_2_2->Buttons;                            // read the buttons status from the slave  
+        Buttons_2 = in_LAB_2->Buttons;                              // read the buttons status from the slave  
                                                                     //    
         if (Buttons_2 != PrevButtons_2)                             // check if the buttons value has changed
         {                                                           //
@@ -464,7 +464,7 @@
             DrawButtons_2_Value(Buttons_2);                         // draw the current buttons value on the TFT                                                                                             
         }                                                           //
                                                                     //               
-        out_LAB_2_2->Segments = Buttons_1;                          // send to the slave the buttons status                                                                       
+        out_LAB_2->Segments = Buttons_1;                            // send to the slave the buttons status                                                                       
                                                                     // from the slave LAB_2_1