![](/media/cache/profiles/433cd42837eb8bc231c8db5e4267cafc.jpg.50x50_q85.jpg)
EasyCAT LAB - EtherCAT master very simple example
- This repository contains a very basic example for the EasyCAT LAB , a complete educational and experimental EtherCAT® system, composed of one master and two slaves.
- The EasyCAT LAB is provided as a kit by AB&T Tecnologie Informatiche, to allow everybody to have an educational EtherCAT® system up and running in a matter of minutes.
- It uses the SOEM (Simple Open EtherCAT® Master) library by rt-labs, that has been ported in the
ecosystem by AB&T Tecnologie Informatiche.
- The slaves are based on the EasyCAT SHIELD and the Arduino UNO.
Note
- This example uses two LAB 2 slaves.
Note
- In this example, to keep things as simple as possible, only two bytes of data are exchanged between the slaves and the TFT display is not used .
config.h@2:368e7d4d8171, 10 months ago (annotated)
- Committer:
- EasyCAT
- Date:
- Wed Oct 25 15:38:52 2023 +0000
- Revision:
- 2:368e7d4d8171
- Parent:
- 0:bc829777f1ea
Bug fix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sulymarco | 0:bc829777f1ea | 1 | #ifndef config_H |
sulymarco | 0:bc829777f1ea | 2 | #define config_H |
sulymarco | 0:bc829777f1ea | 3 | |
sulymarco | 0:bc829777f1ea | 4 | #include "ethercat.h" |
sulymarco | 0:bc829777f1ea | 5 | |
sulymarco | 0:bc829777f1ea | 6 | |
sulymarco | 0:bc829777f1ea | 7 | //------------------------------------------------------------------------------ |
sulymarco | 0:bc829777f1ea | 8 | |
EasyCAT | 2:368e7d4d8171 | 9 | #define LAB_1 1 |
EasyCAT | 2:368e7d4d8171 | 10 | #define LAB_2 2 |
sulymarco | 0:bc829777f1ea | 11 | |
sulymarco | 0:bc829777f1ea | 12 | #define SLAVE_NUM 2 |
sulymarco | 0:bc829777f1ea | 13 | |
sulymarco | 0:bc829777f1ea | 14 | |
sulymarco | 0:bc829777f1ea | 15 | //------------------------------------------------------------------------------ |
sulymarco | 0:bc829777f1ea | 16 | |
sulymarco | 0:bc829777f1ea | 17 | #define IO_MAP_SIZE 256 |
sulymarco | 0:bc829777f1ea | 18 | |
sulymarco | 0:bc829777f1ea | 19 | |
sulymarco | 0:bc829777f1ea | 20 | //------------------------------------------------------------------------------ |
sulymarco | 0:bc829777f1ea | 21 | |
sulymarco | 0:bc829777f1ea | 22 | typedef struct __attribute__((__packed__)) |
sulymarco | 0:bc829777f1ea | 23 | { |
sulymarco | 0:bc829777f1ea | 24 | uint8_t Segments; |
EasyCAT | 2:368e7d4d8171 | 25 | }out_LAB_1t; |
sulymarco | 0:bc829777f1ea | 26 | |
sulymarco | 0:bc829777f1ea | 27 | typedef struct __attribute__((__packed__)) |
sulymarco | 0:bc829777f1ea | 28 | { |
sulymarco | 0:bc829777f1ea | 29 | uint16_t Potentiometer; // in this example we don't use the |
sulymarco | 0:bc829777f1ea | 30 | uint8_t Buttons; // potentiometer but we have to |
EasyCAT | 2:368e7d4d8171 | 31 | }in_LAB_1t; // declare it in the data structure |
sulymarco | 0:bc829777f1ea | 32 | |
sulymarco | 0:bc829777f1ea | 33 | |
sulymarco | 0:bc829777f1ea | 34 | //------------------------------------------------------------------------------ |
sulymarco | 0:bc829777f1ea | 35 | |
sulymarco | 0:bc829777f1ea | 36 | typedef struct __attribute__((__packed__)) |
sulymarco | 0:bc829777f1ea | 37 | { |
sulymarco | 0:bc829777f1ea | 38 | uint8_t Segments; |
EasyCAT | 2:368e7d4d8171 | 39 | }out_LAB_2t; |
sulymarco | 0:bc829777f1ea | 40 | |
sulymarco | 0:bc829777f1ea | 41 | typedef struct __attribute__((__packed__)) |
sulymarco | 0:bc829777f1ea | 42 | { |
sulymarco | 0:bc829777f1ea | 43 | uint16_t Potentiometer; // in this example we don't use the |
sulymarco | 0:bc829777f1ea | 44 | uint8_t Buttons; // potentiometer but we have to |
EasyCAT | 2:368e7d4d8171 | 45 | }in_LAB_2t; // declare it in the data structure |
sulymarco | 0:bc829777f1ea | 46 | |
sulymarco | 0:bc829777f1ea | 47 | |
sulymarco | 0:bc829777f1ea | 48 | //------------------------------------------------------------------------------ |
sulymarco | 0:bc829777f1ea | 49 | |
EasyCAT | 2:368e7d4d8171 | 50 | out_LAB_1t *out_LAB_1; |
EasyCAT | 2:368e7d4d8171 | 51 | in_LAB_1t *in_LAB_1; |
sulymarco | 0:bc829777f1ea | 52 | |
EasyCAT | 2:368e7d4d8171 | 53 | out_LAB_2t *out_LAB_2; |
EasyCAT | 2:368e7d4d8171 | 54 | in_LAB_2t *in_LAB_2; |
sulymarco | 0:bc829777f1ea | 55 | |
sulymarco | 0:bc829777f1ea | 56 | |
sulymarco | 0:bc829777f1ea | 57 | //------------------------------------------------------------------------------ |
sulymarco | 0:bc829777f1ea | 58 | |
sulymarco | 0:bc829777f1ea | 59 | char IOmap[IO_MAP_SIZE]; |
sulymarco | 0:bc829777f1ea | 60 | char IOmapSafe[IO_MAP_SIZE]; |
sulymarco | 0:bc829777f1ea | 61 | |
sulymarco | 0:bc829777f1ea | 62 | |
sulymarco | 0:bc829777f1ea | 63 | void MapLocalStructures (void) |
sulymarco | 0:bc829777f1ea | 64 | { |
EasyCAT | 2:368e7d4d8171 | 65 | out_LAB_1 = (out_LAB_1t*)((char *)ec_slave[LAB_1].outputs - &IOmap[0] + &IOmapSafe[0]); |
EasyCAT | 2:368e7d4d8171 | 66 | in_LAB_1 = (in_LAB_1t*)((char *)ec_slave[LAB_1].inputs - &IOmap[0] + &IOmapSafe[0]); |
sulymarco | 0:bc829777f1ea | 67 | |
EasyCAT | 2:368e7d4d8171 | 68 | out_LAB_2 = (out_LAB_2t*)((char *)ec_slave[LAB_2].outputs - &IOmap[0] + &IOmapSafe[0]); |
EasyCAT | 2:368e7d4d8171 | 69 | in_LAB_2 = (in_LAB_2t*)((char *)ec_slave[LAB_2].inputs - &IOmap[0] + &IOmapSafe[0]); |
sulymarco | 0:bc829777f1ea | 70 | } |
sulymarco | 0:bc829777f1ea | 71 | |
sulymarco | 0:bc829777f1ea | 72 | |
sulymarco | 0:bc829777f1ea | 73 | |
sulymarco | 0:bc829777f1ea | 74 | //------------------------------------------------------------------------------ |
sulymarco | 0:bc829777f1ea | 75 | |
sulymarco | 0:bc829777f1ea | 76 | uint32_t network_configuration(void) |
sulymarco | 0:bc829777f1ea | 77 | { |
sulymarco | 0:bc829777f1ea | 78 | |
sulymarco | 0:bc829777f1ea | 79 | if (ec_slavecount != SLAVE_NUM) // check if the number of slaves matches what we expect |
sulymarco | 0:bc829777f1ea | 80 | return 0; |
sulymarco | 0:bc829777f1ea | 81 | |
EasyCAT | 2:368e7d4d8171 | 82 | if (strcmp(ec_slave[LAB_1].name,"LAB_1")) // verify slave by slave that the slave names are correct |
sulymarco | 0:bc829777f1ea | 83 | return 0; |
sulymarco | 0:bc829777f1ea | 84 | |
EasyCAT | 2:368e7d4d8171 | 85 | else if (strcmp(ec_slave[LAB_2].name,"LAB_2")) |
sulymarco | 0:bc829777f1ea | 86 | return 0; |
sulymarco | 0:bc829777f1ea | 87 | |
sulymarco | 0:bc829777f1ea | 88 | return 1; |
sulymarco | 0:bc829777f1ea | 89 | } |
sulymarco | 0:bc829777f1ea | 90 | |
sulymarco | 0:bc829777f1ea | 91 | |
sulymarco | 0:bc829777f1ea | 92 | #endif |