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:
Thu Feb 06 17:35:14 2020 +0000
Revision:
2:77c2a6061e77
Parent:
1:b66c3e4ce9f5
Updated the data types(to int16_t) of the read and write function to be able to send and receive negative numbers

Who changed what in which revision?

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