---
title: "SPRESENSEでArduino Ethernetライブラリを動かしてみた"
url: "https://maker.wiznet.io/scarlet/projects/spresensearduino-ethernet/"
markdown_url: "https://maker.wiznet.io/scarlet/projects/spresensearduino-ethernet/md"
type: "UCC: User Created Content"
author: "baggio"
author_url: "https://qiita.com/baggio/items/650eeb2a80875afed07e"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "baggio"
original_url: "https://qiita.com/baggio/items/650eeb2a80875afed07e"
published: "2023-10-20"
language: "ja"
likes: 0
views: 172
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# SPRESENSEでArduino Ethernetライブラリを動かしてみた

> SPRESENSEでArduino Ethernetライブラリを動かしてみた

Original author: baggio (source: https://qiita.com/baggio/items/650eeb2a80875afed07e)

## Article

**Spresense Ethernet Tutorial**

*Introduction:*
Recently, I covered the use of the LTE-M extension board, but this tutorial focuses on wired networks. Specifically, we will look at implementing the Arduino Ethernet library on Spresense. Although I started this before acquiring the LTE extension board, I’ve now made the library and the process public. Spresense is impressively compatible with Arduino, offering a smooth experience.

**1. Purchasing the Ethernet Module:**
Although the Spresense extension board is pin-compatible with the Arduino UNO, making the Arduino Ethernet Shield a potential fit, I chose a different, cost-effective module. This was mainly because the shield's ICSP connector interfered with the Spresense. The module cost 1494 yen, but there might be cheaper options available.

- Recommended Module: W5500 Ethernet Network Module

- [Purchase Link](https://www.amazon.co.jp/gp/product/B07H3Z4FNX)

**2. Connecting SPRESENSE Expansion Board to W5500 Module:**
The operating voltage of the W5500 module is 3.3V, but it's 5V-tolerant. Here's an example connection at 3.3V with the Spresense expansion board: ![SPRESENSE-W5500](https://markdownlivepreview.com/SPRESENSE-W5500.png)
*Note:* Ensure the jumper (JP1) on the Spresense expansion board is set to 3.3V.

**3. Porting the Ethernet Library:**
The Ethernet library comes bundled with the ArduinoIDE, but the original source can be found [here](https://github.com/arduino-libraries/Ethernet). To make it compatible with Spresense, some changes are required. I have uploaded the modified version [here](https://github.com/baggio63446333/Ethernet).
As of May 1, 2020, the modifications are aimed at making the library more suitable for Spresense. Install it under the libraries folder of the Arduino environment. Compatibility with other boards is ensured, so you can use this library seamlessly with other setups.

**Key Points for Spresense Porting:**

- Use `SPI_MODE3` instead of `SPI_MODE0`.

- SS (Slave Select) is automatically controlled by hardware.

- Reads/writes to W5500 are buffered, and executed in one `SPI.transfer()` call.

- Interrupts are disabled during `SPI.transfer()` (added May 7, 2020).

For advanced users looking to build an IP camera using the Spresense Camera, consider assigning network processing to a sub-core for optimized real-time performance.

**Spresense SPI Information:**
Spresense uses the ARM PrimeCell PL022 for SPI. This is a familiar hardware component for many. Other components like UART (PL011) and DMAC (PL080) might also be onboard. Given its architecture, platforms like mbed could potentially run on Spresense.

For those familiar with PL022, you'll know its quirks, like the automatic LOW/HIGH control of the SSPFSSOUT signal (SS signal) by hardware. When transferring data in continuous bursts, the behavior changes based on the SPI_MODE. For W5500 communication, use `SPI_MODE3` instead of `SPI_MODE0`.

For more details, refer to the ARM PrimeCell Synchronous Serial Port (PL022) technical reference manual.

**4. Ethernet Sample Code:**
Explanations for the sample code can be found [here](https://www.arduino.cc/en/Reference/Ethernet).

*Happy Building!*

---

Source: https://maker.wiznet.io/scarlet/projects/spresensearduino-ethernet/
