An Mbed library for an EtherCAT Arduino Shield developed by Esmacat to connect the larger Arduino ecosystem and other MCU boards capable of connecting a shield with an Arduino Uno form factor. EASE can easily turn an MCU board, including the Arduino ecosystem, into a cost-efficient EtherCAT slave subsystem in the larger EtherCAT system. Using EtherCAT communication, EASE can reliably communicate with other base boards through an EtherCAT master.

Information about Esmacat and EASE is provided in the link below. https://os.mbed.com/users/esmacat/code/EASE_Example/wiki/Homepage

Committer:
pratima_hb
Date:
Wed Jan 29 19:27:19 2020 +0000
Revision:
0:4a9e3331b131
Child:
1:b66c3e4ce9f5
EsmacatShield Library for EASE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pratima_hb 0:4a9e3331b131 1 /**
pratima_hb 0:4a9e3331b131 2 EsmacatShield.h - Library for using EtherCAT Arduino Shield by Esmacat(EASE).
pratima_hb 0:4a9e3331b131 3 Created by Esmacat, 01/22/2020
pratima_hb 0:4a9e3331b131 4
pratima_hb 0:4a9e3331b131 5 *******************************************************************************
pratima_hb 0:4a9e3331b131 6 * @file EsmacatShield.h
pratima_hb 0:4a9e3331b131 7 *******************************************************************************
pratima_hb 0:4a9e3331b131 8 */
pratima_hb 0:4a9e3331b131 9
pratima_hb 0:4a9e3331b131 10
pratima_hb 0:4a9e3331b131 11 #ifndef EsmacatShield_h
pratima_hb 0:4a9e3331b131 12 #define EsmacatShield_h
pratima_hb 0:4a9e3331b131 13
pratima_hb 0:4a9e3331b131 14 #include "mbed.h"
pratima_hb 0:4a9e3331b131 15
pratima_hb 0:4a9e3331b131 16 #define EASE_READ_REG 0B00000000
pratima_hb 0:4a9e3331b131 17 #define EASE_WRITE_REG 0B10000000
pratima_hb 0:4a9e3331b131 18 #define EASE_SINGLE_SHOT 0B10111111
pratima_hb 0:4a9e3331b131 19 #define EASE_LED_ON 0B00000100
pratima_hb 0:4a9e3331b131 20 #define EASE_LED_OFF 0B11111011
pratima_hb 0:4a9e3331b131 21
pratima_hb 0:4a9e3331b131 22
pratima_hb 0:4a9e3331b131 23 /**
pratima_hb 0:4a9e3331b131 24 * @brief This is a driver code for EASE with form factor of Arduino
pratima_hb 0:4a9e3331b131 25 * UNO shields. This shield communicates with the base board via SPI.
pratima_hb 0:4a9e3331b131 26 *
pratima_hb 0:4a9e3331b131 27 * @version 1.0
pratima_hb 0:4a9e3331b131 28 *
pratima_hb 0:4a9e3331b131 29 * @details EASE stacks onto Arduino-like boards (a.k.a Base board).
pratima_hb 0:4a9e3331b131 30 * The Base board can read and write registers on EASE via SPI.
pratima_hb 0:4a9e3331b131 31 * The same registers can also be written and read by an EtherCAT master via a
pratima_hb 0:4a9e3331b131 32 * standard EtherCAT protocol. Multiple EASE boards can be connected with
pratima_hb 0:4a9e3331b131 33 * Ethernet cables with a daisy-chain topology and powered via Ethernet cables
pratima_hb 0:4a9e3331b131 34 * with Power-over-EtherCAT (POE) technology. EASE, thus bridges the data
pratima_hb 0:4a9e3331b131 35 * packets between an EtherCAT master and multiple Base boards.
pratima_hb 0:4a9e3331b131 36 *
pratima_hb 0:4a9e3331b131 37 * @code
pratima_hb 0:4a9e3331b131 38 *#include "mbed.h"
pratima_hb 0:4a9e3331b131 39 *#include <EsmacatShield.h> //Include Esmacat Arduino Library
pratima_hb 0:4a9e3331b131 40 *
pratima_hb 0:4a9e3331b131 41 *int counter;
pratima_hb 0:4a9e3331b131 42 *int v[8]; //EASE 8 registers
pratima_hb 0:4a9e3331b131 43 *Serial pc(USBTX, USBRX);
pratima_hb 0:4a9e3331b131 44 *
pratima_hb 0:4a9e3331b131 45 *DigitalOut selectPin(D10); // D10 is used to drive chip enable low
pratima_hb 0:4a9e3331b131 46 *SPI spi(D11, D12, D13); // mosi, miso, sclk
pratima_hb 0:4a9e3331b131 47 *
pratima_hb 0:4a9e3331b131 48 *
pratima_hb 0:4a9e3331b131 49 *int main()
pratima_hb 0:4a9e3331b131 50 *{
pratima_hb 0:4a9e3331b131 51 *
pratima_hb 0:4a9e3331b131 52 * EsmacatShield slave(spi, selectPin); //Define Chip Selector Pin
pratima_hb 0:4a9e3331b131 53 *
pratima_hb 0:4a9e3331b131 54 * slave.setup_spi(); //Setup SPI for EASE, 8 bit Data, Mode 1, 3MHz freq
pratima_hb 0:4a9e3331b131 55 *
pratima_hb 0:4a9e3331b131 56 * while(1)
pratima_hb 0:4a9e3331b131 57 * {
pratima_hb 0:4a9e3331b131 58 * slave.get_ecat_registers(v); //read all registers
pratima_hb 0:4a9e3331b131 59 * slave.write_reg_value(0,counter++, true); //Write register data (register,value, led_on)
pratima_hb 0:4a9e3331b131 60 * wait_us(1000000); //sleep for 1000 ms
pratima_hb 0:4a9e3331b131 61 * slave.write_reg_value(0,counter++, false); //Write register data (register,value, led_on)
pratima_hb 0:4a9e3331b131 62 * wait_us(1000000); //sleep for 1000 ms
pratima_hb 0:4a9e3331b131 63 * pc.printf("Next Iteration \n");
pratima_hb 0:4a9e3331b131 64 * for (int i=0;i<8;i++) //print the registers read on pc
pratima_hb 0:4a9e3331b131 65 * {
pratima_hb 0:4a9e3331b131 66 * pc.printf("%d",i);
pratima_hb 0:4a9e3331b131 67 * pc.printf("\t");
pratima_hb 0:4a9e3331b131 68 * pc.printf("%d",v[i]);
pratima_hb 0:4a9e3331b131 69 * pc.printf("\n");
pratima_hb 0:4a9e3331b131 70 * }
pratima_hb 0:4a9e3331b131 71 * }
pratima_hb 0:4a9e3331b131 72 *
pratima_hb 0:4a9e3331b131 73 *}
pratima_hb 0:4a9e3331b131 74 * @endcode
pratima_hb 0:4a9e3331b131 75 */
pratima_hb 0:4a9e3331b131 76
pratima_hb 0:4a9e3331b131 77
pratima_hb 0:4a9e3331b131 78 class EsmacatShield
pratima_hb 0:4a9e3331b131 79 {
pratima_hb 0:4a9e3331b131 80 public:
pratima_hb 0:4a9e3331b131 81 /**********************************************************//**
pratima_hb 0:4a9e3331b131 82 * @brief Constructor for EsmacatShield Class.
pratima_hb 0:4a9e3331b131 83 *
pratima_hb 0:4a9e3331b131 84 * @details Requires an existing SPI object as well as a DigitalOut object.
pratima_hb 0:4a9e3331b131 85 * The DigitalOut object is used for a chip enable signal
pratima_hb 0:4a9e3331b131 86 *
pratima_hb 0:4a9e3331b131 87 * On Entry:
pratima_hb 0:4a9e3331b131 88 * @param[in] spi - pointer to existing SPI object
pratima_hb 0:4a9e3331b131 89 * @param[in] pin - pointer to a DigitalOut pin object
pratima_hb 0:4a9e3331b131 90 *
pratima_hb 0:4a9e3331b131 91 * On Exit:
pratima_hb 0:4a9e3331b131 92 *
pratima_hb 0:4a9e3331b131 93 * @return None
pratima_hb 0:4a9e3331b131 94 **************************************************************/
pratima_hb 0:4a9e3331b131 95 EsmacatShield(SPI &spi, DigitalOut &pin);
pratima_hb 0:4a9e3331b131 96 /**********************************************************//**
pratima_hb 0:4a9e3331b131 97 * @brief Set up spi communication.
pratima_hb 0:4a9e3331b131 98 *
pratima_hb 0:4a9e3331b131 99 * @details Sets up SPI communication by using the member.
pratima_hb 0:4a9e3331b131 100 * functions format and frequency. 8 bit data, Mode 1,
pratima_hb 0:4a9e3331b131 101 * frequency of communication set to 3000000Hz
pratima_hb 0:4a9e3331b131 102 *
pratima_hb 0:4a9e3331b131 103 * On Entry:
pratima_hb 0:4a9e3331b131 104 *
pratima_hb 0:4a9e3331b131 105 * On Exit:
pratima_hb 0:4a9e3331b131 106 *
pratima_hb 0:4a9e3331b131 107 * @return None
pratima_hb 0:4a9e3331b131 108 **************************************************************/
pratima_hb 0:4a9e3331b131 109 void setup_spi();
pratima_hb 0:4a9e3331b131 110 /**********************************************************//**
pratima_hb 0:4a9e3331b131 111 * @brief Write given Register with the given value.
pratima_hb 0:4a9e3331b131 112 *
pratima_hb 0:4a9e3331b131 113 * @details Using this function 8 different 16 bit integers can be
pratima_hb 0:4a9e3331b131 114 * written into EASE.
pratima_hb 0:4a9e3331b131 115 *
pratima_hb 0:4a9e3331b131 116 * On Entry:
pratima_hb 0:4a9e3331b131 117 * @param[in] write_addr - The Register number to be written into.
pratima_hb 0:4a9e3331b131 118 * Can take values from 0 to 7
pratima_hb 0:4a9e3331b131 119 * @param[in] value - The value to be written into the register
pratima_hb 0:4a9e3331b131 120 * @param[in] led_on - True to turn LED ON
pratima_hb 0:4a9e3331b131 121 * - False to turn LED OFF
pratima_hb 0:4a9e3331b131 122 *
pratima_hb 0:4a9e3331b131 123 * On Exit:
pratima_hb 0:4a9e3331b131 124 *
pratima_hb 0:4a9e3331b131 125 * @return None
pratima_hb 0:4a9e3331b131 126 **************************************************************/
pratima_hb 0:4a9e3331b131 127 void write_reg_value(int write_addr,int value, bool led_on=1);
pratima_hb 0:4a9e3331b131 128
pratima_hb 0:4a9e3331b131 129 /**********************************************************//**
pratima_hb 0:4a9e3331b131 130 * @brief Read EASE Register.
pratima_hb 0:4a9e3331b131 131 *
pratima_hb 0:4a9e3331b131 132 * @details Using this function 8 different 16 bit integers on EASE can be
pratima_hb 0:4a9e3331b131 133 * read.
pratima_hb 0:4a9e3331b131 134 *
pratima_hb 0:4a9e3331b131 135 * On Entry:
pratima_hb 0:4a9e3331b131 136 * @param[in] Pointer to integer - Eight consecutive memory locations
pratima_hb 0:4a9e3331b131 137 from this pointer will be stored with the integer values read
pratima_hb 0:4a9e3331b131 138 * from EASE.
pratima_hb 0:4a9e3331b131 139 *
pratima_hb 0:4a9e3331b131 140 * On Exit:
pratima_hb 0:4a9e3331b131 141 * @param[out] pointer to the integer where the data is stored.
pratima_hb 0:4a9e3331b131 142
pratima_hb 0:4a9e3331b131 143 *
pratima_hb 0:4a9e3331b131 144 * @return None
pratima_hb 0:4a9e3331b131 145 **************************************************************/
pratima_hb 0:4a9e3331b131 146 int* get_ecat_registers(int regs[8]);
pratima_hb 0:4a9e3331b131 147
pratima_hb 0:4a9e3331b131 148 /************************************************************
pratima_hb 0:4a9e3331b131 149 * @brief Default destructor for EsmacatShield Class.
pratima_hb 0:4a9e3331b131 150 *
pratima_hb 0:4a9e3331b131 151 * @details Destroys SPI object if owner
pratima_hb 0:4a9e3331b131 152 *
pratima_hb 0:4a9e3331b131 153 * On Entry:
pratima_hb 0:4a9e3331b131 154 *
pratima_hb 0:4a9e3331b131 155 * On Exit:
pratima_hb 0:4a9e3331b131 156 *
pratima_hb 0:4a9e3331b131 157 * @return None
pratima_hb 0:4a9e3331b131 158 **************************************************************/
pratima_hb 0:4a9e3331b131 159
pratima_hb 0:4a9e3331b131 160 ~EsmacatShield();
pratima_hb 0:4a9e3331b131 161 private:
pratima_hb 0:4a9e3331b131 162
pratima_hb 0:4a9e3331b131 163 SPI &ecat_spi;
pratima_hb 0:4a9e3331b131 164 DigitalOut &ecat_cs;
pratima_hb 0:4a9e3331b131 165 int read_reg_value(int read_addr);
pratima_hb 0:4a9e3331b131 166 };
pratima_hb 0:4a9e3331b131 167
pratima_hb 0:4a9e3331b131 168
pratima_hb 0:4a9e3331b131 169 #endif
pratima_hb 0:4a9e3331b131 170