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 #include "EsmacatShield.h"
pratima_hb 0:4a9e3331b131 2
pratima_hb 0:4a9e3331b131 3 EsmacatShield::EsmacatShield(SPI &spi, DigitalOut &pin):ecat_spi(spi),ecat_cs(pin)
pratima_hb 0:4a9e3331b131 4 {
pratima_hb 0:4a9e3331b131 5
pratima_hb 0:4a9e3331b131 6 }
pratima_hb 0:4a9e3331b131 7
pratima_hb 0:4a9e3331b131 8 void EsmacatShield::setup_spi()
pratima_hb 0:4a9e3331b131 9 {
pratima_hb 0:4a9e3331b131 10 /*Chip must be deselected*/
pratima_hb 0:4a9e3331b131 11 ecat_cs = 1;
pratima_hb 0:4a9e3331b131 12
pratima_hb 0:4a9e3331b131 13 /*Setup the spi for 8 bit data, Mode 1,
pratima_hb 0:4a9e3331b131 14 with a 3MHz clock rate*/
pratima_hb 0:4a9e3331b131 15 ecat_spi.format(8,1);
pratima_hb 0:4a9e3331b131 16 ecat_spi.frequency(3000000);
pratima_hb 0:4a9e3331b131 17
pratima_hb 0:4a9e3331b131 18 /* Chip must be selected*/
pratima_hb 0:4a9e3331b131 19 ecat_cs = 0;
pratima_hb 0:4a9e3331b131 20
pratima_hb 0:4a9e3331b131 21 }
pratima_hb 0:4a9e3331b131 22
pratima_hb 0:4a9e3331b131 23
pratima_hb 0:4a9e3331b131 24 void EsmacatShield::write_reg_value(int write_addr,int value, bool led_on)
pratima_hb 0:4a9e3331b131 25 {
pratima_hb 0:4a9e3331b131 26 uint8_t v1,v2;
pratima_hb 0:4a9e3331b131 27 // Chip must be selected
pratima_hb 0:4a9e3331b131 28 ecat_cs = 0;
pratima_hb 0:4a9e3331b131 29 wait_us(2000); //sleep for 2 ms;
pratima_hb 0:4a9e3331b131 30 write_addr = write_addr <<3;
pratima_hb 0:4a9e3331b131 31 if (led_on)
pratima_hb 0:4a9e3331b131 32 {
pratima_hb 0:4a9e3331b131 33 ecat_spi.write(((EASE_WRITE_REG|write_addr)| EASE_LED_ON)& EASE_SINGLE_SHOT);
pratima_hb 0:4a9e3331b131 34 }
pratima_hb 0:4a9e3331b131 35 else
pratima_hb 0:4a9e3331b131 36 {
pratima_hb 0:4a9e3331b131 37 ecat_spi.write((EASE_WRITE_REG|write_addr)& EASE_LED_OFF & EASE_SINGLE_SHOT);
pratima_hb 0:4a9e3331b131 38 }
pratima_hb 0:4a9e3331b131 39 v1 = (value&0xFF00) >> 8;
pratima_hb 0:4a9e3331b131 40 v2 = (value&0x00FF);
pratima_hb 0:4a9e3331b131 41 ecat_spi.write(v1);
pratima_hb 0:4a9e3331b131 42 ecat_spi.write(v2);
pratima_hb 0:4a9e3331b131 43 // Chip must be deselected
pratima_hb 0:4a9e3331b131 44 ecat_cs = 1;
pratima_hb 0:4a9e3331b131 45 wait_us(2000); //sleep for 2 ms;
pratima_hb 0:4a9e3331b131 46 }
pratima_hb 0:4a9e3331b131 47
pratima_hb 0:4a9e3331b131 48 int* EsmacatShield::get_ecat_registers(int regs[8]) {
pratima_hb 0:4a9e3331b131 49 regs[0] = read_reg_value(1);
pratima_hb 0:4a9e3331b131 50 regs[1] = read_reg_value(2);
pratima_hb 0:4a9e3331b131 51 regs[2] = read_reg_value(3);
pratima_hb 0:4a9e3331b131 52 regs[3] = read_reg_value(4);
pratima_hb 0:4a9e3331b131 53 regs[4] = read_reg_value(5);
pratima_hb 0:4a9e3331b131 54 regs[5] = read_reg_value(6);
pratima_hb 0:4a9e3331b131 55 regs[6] = read_reg_value(7);
pratima_hb 0:4a9e3331b131 56 regs[7] = read_reg_value(0);
pratima_hb 0:4a9e3331b131 57 return(regs);
pratima_hb 0:4a9e3331b131 58 }
pratima_hb 0:4a9e3331b131 59
pratima_hb 0:4a9e3331b131 60 int EsmacatShield::read_reg_value(int read_addr)
pratima_hb 0:4a9e3331b131 61 {
pratima_hb 0:4a9e3331b131 62 uint16_t v2,v3;
pratima_hb 0:4a9e3331b131 63 // Chip must be selected
pratima_hb 0:4a9e3331b131 64 ecat_cs = 0;
pratima_hb 0:4a9e3331b131 65 wait_us(2000); //sleep for 2 ms;
pratima_hb 0:4a9e3331b131 66 read_addr = read_addr <<3;
pratima_hb 0:4a9e3331b131 67 ecat_spi.write( EASE_READ_REG|read_addr);
pratima_hb 0:4a9e3331b131 68 v2 = ecat_spi.write(0x00);
pratima_hb 0:4a9e3331b131 69 v3 = ecat_spi.write(0x00);
pratima_hb 0:4a9e3331b131 70 // Chip must be deselected
pratima_hb 0:4a9e3331b131 71 ecat_cs = 1;
pratima_hb 0:4a9e3331b131 72 wait_us(2000); //sleep for 2 ms;
pratima_hb 0:4a9e3331b131 73
pratima_hb 0:4a9e3331b131 74 return (v2<<8)+v3;
pratima_hb 0:4a9e3331b131 75 }
pratima_hb 0:4a9e3331b131 76
pratima_hb 0:4a9e3331b131 77 EsmacatShield::~EsmacatShield(void)
pratima_hb 0:4a9e3331b131 78 {
pratima_hb 0:4a9e3331b131 79 //empty block
pratima_hb 0:4a9e3331b131 80 }
pratima_hb 0:4a9e3331b131 81