---
title: "Ethernet-to-serial/RS485 configured with W5500 and KL27"
url: "https://maker.wiznet.io/louis_m/resellers/ethernet-to-serial-rs485-configured-with-w5500-and-kl27/"
markdown_url: "https://maker.wiznet.io/louis_m/resellers/ethernet-to-serial-rs485-configured-with-w5500-and-kl27/md"
type: "VAR: Value-Added Reseller Products"
author: "eefocus"
author_url: "https://www.eefocus.com/circuit/1073630.html"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "eefocus"
original_url: "https://www.eefocus.com/circuit/1073630.html"
published: "2023-05-02"
language: "en"
hardware: ["WIZnet W5500"]
likes: 0
views: 614
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Ethernet-to-serial/RS485 configured with W5500 and KL27

> Ethernet-to-serial/RS485 configured with W5500 and KL27

Original author: eefocus (source: https://www.eefocus.com/circuit/1073630.html)

## Components

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

WIZnet parts: W5500 ([Datasheet](https://docs.wiznet.io/Product/Chip/Ethernet/W5500/datasheet?utm_source=maker&utm_medium=project&utm_campaign=w5500), [product hub](https://maker.wiznet.io/products/w5500/))

## Article

使用W5500+KL27实现[以太网](https://www.eefocus.com/baike/481744.html)转串口RS232、RS485透传功能：

![](https://file.eefcdn.com/circuit/FkzCyTccsSuPHI6G_Ef2Et4PNrtI)![](https://www.cirmall.com/upload/images/FgXBW9BzZVPaD3OkF-Co_31pZur4/02.jpg)

将W5500的库移植到工程中，然后就是初始化KL27的[SPI](https://www.eefocus.com/baike/496252.html)：
void w5500_spi_init()
{
PORT_Init(PORTB, PORT_MODULE_ALT1_MODE, PIN_0|PIN_1, 0, NULL); //PTB0 - SPI1_RST -> W5500 RST
GPIO_Init(GPIOB, GPIO_PIN_OUTPUT, PIN_0);
GPIO_Clr (GPIOB, PIN_0);
delay(0xfff);
GPIO_Set (GPIOB, PIN_0);
delay(0xffff);

GPIO_Init (GPIOB, GPIO_PIN_INPUT,PIN_1);

PORT_Init(PORTD, PORT_MODULE_ALT1_MODE, PIN_4, 0, NULL); //PTB0 - SPI1_RST -> W5500 RST
GPIO_Init(GPIOD, GPIO_PIN_OUTPUT, PIN_4);
GPIO_Set (GPIOD, PIN_4);

//SPI1 PTD4/5/6/7 CS/SCK/MOSI/MISO
PORT_Init(PORTD, PORT_MODULE_ALT2_MODE, PIN_5|PIN_6|PIN_7, 0, NULL);
SPI1_Init(SPI_MODULE_DIV2_8B_POLL_CONFIG,NULL,0,NULL);
}

然后程序中循环处理就可以，将收到的数据，再发回去。

![](https://file.eefcdn.com/circuit/FkCHiOo1jnHmUUHTObSBoVd_TIyt)

测试单包1956字节收发：

![](https://file.eefcdn.com/circuit/FtMhOjrDXsMOmCXlo2kiajrfB-MB)

连续3ms，自动收发，不丢包。（测试：一包1956字节，连续2ms发送，有丢包）

![](https://file.eefcdn.com/circuit/FqPJm_5-B7LQjW_kPSlxCfaxLXPy)

测试连续3ms自动收发网速：![](https://file.eefcdn.com/circuit/FmOR7P-upWc3I4QVmZr-Rjy9IZed)

---

Source: https://maker.wiznet.io/louis_m/resellers/ethernet-to-serial-rs485-configured-with-w5500-and-kl27/
