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.
Committer:
sulymarco
Date:
Mon Jul 08 17:44:47 2019 +0000
Revision:
0:13be39911caf
Child:
4:cbef7fa67d5f
first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sulymarco 0:13be39911caf 1 #ifndef config_H
sulymarco 0:13be39911caf 2 #define config_H
sulymarco 0:13be39911caf 3
sulymarco 0:13be39911caf 4 #include "ethercat.h"
sulymarco 0:13be39911caf 5
sulymarco 0:13be39911caf 6
sulymarco 0:13be39911caf 7 //------------------------------------------------------------------------------
sulymarco 0:13be39911caf 8
sulymarco 0:13be39911caf 9 #define LAB_2_1 1
sulymarco 0:13be39911caf 10 #define LAB_2_2 2
sulymarco 0:13be39911caf 11
sulymarco 0:13be39911caf 12 #define SLAVE_NUM 2
sulymarco 0:13be39911caf 13
sulymarco 0:13be39911caf 14
sulymarco 0:13be39911caf 15 //------------------------------------------------------------------------------
sulymarco 0:13be39911caf 16
sulymarco 0:13be39911caf 17 #define IO_MAP_SIZE 256
sulymarco 0:13be39911caf 18
sulymarco 0:13be39911caf 19
sulymarco 0:13be39911caf 20 //------------------------------------------------------------------------------
sulymarco 0:13be39911caf 21
sulymarco 0:13be39911caf 22 typedef struct __attribute__((__packed__))
sulymarco 0:13be39911caf 23 {
sulymarco 0:13be39911caf 24 uint8_t Segments;
sulymarco 0:13be39911caf 25 }out_LAB_2_1t;
sulymarco 0:13be39911caf 26
sulymarco 0:13be39911caf 27 typedef struct __attribute__((__packed__))
sulymarco 0:13be39911caf 28 {
sulymarco 0:13be39911caf 29 uint16_t Potentiometer; // in this example we don't use the
sulymarco 0:13be39911caf 30 uint8_t Buttons; // potentiometer but we have to
sulymarco 0:13be39911caf 31 }in_LAB_2_1t; // declare it in the data structure
sulymarco 0:13be39911caf 32
sulymarco 0:13be39911caf 33
sulymarco 0:13be39911caf 34 //------------------------------------------------------------------------------
sulymarco 0:13be39911caf 35
sulymarco 0:13be39911caf 36 typedef struct __attribute__((__packed__))
sulymarco 0:13be39911caf 37 {
sulymarco 0:13be39911caf 38 uint8_t Segments;
sulymarco 0:13be39911caf 39 }out_LAB_2_2t;
sulymarco 0:13be39911caf 40
sulymarco 0:13be39911caf 41 typedef struct __attribute__((__packed__))
sulymarco 0:13be39911caf 42 {
sulymarco 0:13be39911caf 43 uint16_t Potentiometer; // in this example we don't use the
sulymarco 0:13be39911caf 44 uint8_t Buttons; // potentiometer but we have to
sulymarco 0:13be39911caf 45 }in_LAB_2_2t; // declare it in the data structure
sulymarco 0:13be39911caf 46
sulymarco 0:13be39911caf 47
sulymarco 0:13be39911caf 48 //------------------------------------------------------------------------------
sulymarco 0:13be39911caf 49
sulymarco 0:13be39911caf 50 out_LAB_2_1t *out_LAB_2_1;
sulymarco 0:13be39911caf 51 in_LAB_2_1t *in_LAB_2_1;
sulymarco 0:13be39911caf 52
sulymarco 0:13be39911caf 53 out_LAB_2_2t *out_LAB_2_2;
sulymarco 0:13be39911caf 54 in_LAB_2_2t *in_LAB_2_2;
sulymarco 0:13be39911caf 55
sulymarco 0:13be39911caf 56
sulymarco 0:13be39911caf 57 //------------------------------------------------------------------------------
sulymarco 0:13be39911caf 58
sulymarco 0:13be39911caf 59 char IOmap[IO_MAP_SIZE];
sulymarco 0:13be39911caf 60 char IOmapSafe[IO_MAP_SIZE];
sulymarco 0:13be39911caf 61
sulymarco 0:13be39911caf 62
sulymarco 0:13be39911caf 63 void MapLocalStructures (void)
sulymarco 0:13be39911caf 64 {
sulymarco 0:13be39911caf 65 out_LAB_2_1 = (out_LAB_2_1t*)((char *)ec_slave[LAB_2_1].outputs - &IOmap[0] + &IOmapSafe[0]);
sulymarco 0:13be39911caf 66 in_LAB_2_1 = (in_LAB_2_1t*)((char *)ec_slave[LAB_2_1].inputs - &IOmap[0] + &IOmapSafe[0]);
sulymarco 0:13be39911caf 67
sulymarco 0:13be39911caf 68 out_LAB_2_2 = (out_LAB_2_2t*)((char *)ec_slave[LAB_2_2].outputs - &IOmap[0] + &IOmapSafe[0]);
sulymarco 0:13be39911caf 69 in_LAB_2_2 = (in_LAB_2_2t*)((char *)ec_slave[LAB_2_2].inputs - &IOmap[0] + &IOmapSafe[0]);
sulymarco 0:13be39911caf 70 }
sulymarco 0:13be39911caf 71
sulymarco 0:13be39911caf 72
sulymarco 0:13be39911caf 73
sulymarco 0:13be39911caf 74 //------------------------------------------------------------------------------
sulymarco 0:13be39911caf 75
sulymarco 0:13be39911caf 76 uint32_t network_configuration(void)
sulymarco 0:13be39911caf 77 {
sulymarco 0:13be39911caf 78
sulymarco 0:13be39911caf 79 if (ec_slavecount != SLAVE_NUM) // check if the number of slaves matches what we expect
sulymarco 0:13be39911caf 80 return 0;
sulymarco 0:13be39911caf 81
sulymarco 0:13be39911caf 82 if (strcmp(ec_slave[LAB_2_1].name,"LAB_2")) // verify slave by slave that the slave names are correct
sulymarco 0:13be39911caf 83 return 0;
sulymarco 0:13be39911caf 84
sulymarco 0:13be39911caf 85 else if (strcmp(ec_slave[LAB_2_2].name,"LAB_2"))
sulymarco 0:13be39911caf 86 return 0;
sulymarco 0:13be39911caf 87
sulymarco 0:13be39911caf 88 return 1;
sulymarco 0:13be39911caf 89 }
sulymarco 0:13be39911caf 90
sulymarco 0:13be39911caf 91
sulymarco 0:13be39911caf 92 #endif