---
title: "[Re-curation]TMS320F28335 - W5300 MACRAW를 이용한 EtherCat Test"
url: "https://maker.wiznet.io/teddy/projects/re-curationtms320f28335-w5300-macraw--ethercat-test/"
markdown_url: "https://maker.wiznet.io/teddy/projects/re-curationtms320f28335-w5300-macraw--ethercat-test/md"
type: "UCC: User Created Content"
author: "nexp"
author_url: "https://oldmaker.wiznet.io/2022/07/27/tms320f28335-w5300-macraw%eb%a5%bc-%ec%9d%b4%ec%9a%a9%ed%95%9c-ethercat-test/"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "nexp"
original_url: "https://oldmaker.wiznet.io/2022/07/27/tms320f28335-w5300-macraw%eb%a5%bc-%ec%9d%b4%ec%9a%a9%ed%95%9c-ethercat-test/"
published: "2023-11-02"
language: "en"
hardware: ["WIZnet W5300"]
likes: 0
views: 756
comments: 1
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# [Re-curation]TMS320F28335 - W5300 MACRAW를 이용한 EtherCat Test

> TMS320F28335 - W5300 MACRAW를 이용한 EtherCat Test

Original author: nexp (source: https://oldmaker.wiznet.io/2022/07/27/tms320f28335-w5300-macraw%eb%a5%bc-%ec%9d%b4%ec%9a%a9%ed%95%9c-ethercat-test/)

## Components

- **WIZnet W5300** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5300))

## Article

**TMS320F28335 - W5300 MACRAW를 이용한 EtherCat Test**

![](https://t1.daumcdn.net/cfile/tistory/22627A49523ECBCD32)

W5300은 하드웨어적으로 TCP/IP를 구현한 Ethernet Controller이지만 Ethernet 데이터 부분을 사용자 임의 데이터를 보낼수 있는 MACRAW 모드로 구동할 수 있다. MACRAW 모드를 이용하면 임의이 데이터를 보낼수 있는데.. EtherCat 페킷을 보내면 EhterCat 통신을 할 수 있다. 특히 TMS320F28335와 같이 실시간 처리가 가능한 DSP를 이용하면 EtheCat구현이 쉬어진다.

![](https://t1.daumcdn.net/cfile/tistory/21754F49523ECBED28)

아래 표는 EtherCat Frame 데이터 구조이다.

간단히 구조를 살펴 보면 목적지, 출발지 MAC주소와 EtherType에 **0x88A4**를 사용하고 EtherCat Data를 전송하면 된다.

![](https://t1.daumcdn.net/cfile/tistory/2519A049523ECBEC14)

EhterCat Data 필더에는 2Byte의 총 데이터 길이와 Cmd, Idx, Address... 등등의 Data Headerd와 데이터로 채워진다.

데이터는 2+26 번째 버퍼 부터 시작된다.

![](https://t1.daumcdn.net/cfile/tistory/27331349523ECBEC03)

**W5300 MACRAW 모드 초기화**

Sn_MR_MACRAW 모드로 소켓을 생성하면 된다. 여기서 주의 사항은 MACRAW모드는 반드시 소켓 0번만 가능하다.

void Init_EtheCat(void)

{

socket(0, Sn_MR_MACRAW, 3000, Sn_MR_MF);

}

**EtherCat 데이터 전송함수**

데이터 송신시 첫 2Byte의 EtherHeader 와 마지막 2Byte CRC는 W5300에서 자동 생성된다. 다만 수신은 모든 페킷이 수신되므로 이부분을 적절히 처리해 주어야 한다.

uint32 EtherCatSend(SOCKET s, uint8 * buf, uint32 len)

{

uint8 status=0;

uint8 isr=0;

uint32 ret=0;

// check size not to exceed MAX size.

if (len > getIINCHIP_TxMAX(s)) ret = getIINCHIP_TxMAX(s);

else ret = len;

// copy data

wiz_write_buf(s, buf, ret);

// send

setSn_TX_WRSR(s,ret);

setSn_CR(s, Sn_CR_SEND);

// wait SEND command completion

while (!((isr = getSn_IR(s)) & Sn_IR_SENDOK))

{

status = getSn_SSR(s);

if ((status == SOCK_CLOSED) || (isr & Sn_IR_TIMEOUT))

{

setSn_IR(s,Sn_IR_TIMEOUT);

return 0;

}

}

// Clear Sn_IR_SENDOK

setSn_IR(s, Sn_IR_SENDOK);

return ret;

}

**TMS320F28335, W5300을 이용한 EtherCat 테스트**

테스트는 두세트의 이더넷 모듈을 이용해서 스위치를 누르면 EtherCat 페킷으로 데이터를 전송하고 수신된 데이터를 분석해서 LED를 On/Off 하도록 했다.

수신된 데이터는 WireShack를 이용하여 패킷을 캡쳐할 수 있고 EtherCat 데이터를 확인할수 있다.

26번 버퍼부터 데이터 필더 이다. 테스트에서는 스위치를 누를때 마다 1씩 증가해서 전송하도록 해서 테스트 했다.

![](https://t1.daumcdn.net/cfile/tistory/2502D749523ECBEC21)

그리고 시리얼포트를 이용하여 수신된 페킷을 확인할 수 있다.

![](https://t1.daumcdn.net/cfile/tistory/221CA349523ECBED11)

**TMS320F28335와 W5300 MACRAW모드를 이용한 EtherCat 테스트 동영상**

[Embedded media](https://www.youtube.com/embed/_9zXhRDQ8A4)

---

Source: https://maker.wiznet.io/teddy/projects/re-curationtms320f28335-w5300-macraw--ethercat-test/
