SPI communication with nRF9160 (using Ethernet Sheild, W5500 & SDCard) with Zephyr’s library

A memorandum on how to use Ethernet Sheild (SPI module of W5500 & SD card) with nRF9160DK, nRF9160 feather, etc. in ncs v1.6.1 environment.
ORIGINAL POST
By KiKUiCHi_R1R
components
Hardware Components
nRF9160 feather
X 1
w5500
X 1
Software Apps and online services
ncs v1.6.1
details

nrf.PNG

Introduction

A memorandum on how to use Ethernet Sheild (SPI module of W5500 & SD card) with nRF9160DK, nRF9160 feather, etc. in ncs v1.6.1 environment.

Zephyr’s library is hard to get along with, so I’m quite addicted to it.

The implementation method in this article seems to work but not the correct answer.

I want to know the correct answer, but there is little information.

About wiring

If possible, I had to make a direct connection or keep the wiring as simple as possible to
get a decent waveform.

Library etc.

W5500 forcibly ported the library provided by wiznet without using the Zephyr driver.
https://github.com/Wiznet/ioLibrary_Driver

The SD card came to work for the time being by using Zephyr’s library
.

The biggest problem is the operation of SPI.

Even if I implemented it in the usual (?) Way, it didn’t work at all.
I tried using the NRFX_SPIM library and it worked for some reason.

prj.conf (excerpt)
CONFIG_SPI=n
CONFIG_NRFX_SPIM=y
CONFIG_NRFX_SPIM2=y
CONFIG_NRFX_SPIM3=y

CONFIG_DISK_ACCESS=y
CONFIG_DISK_DRIVER_SDMMC=y
CONFIG_SDMMC_OVER_SPI=y
CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y

Use SPI2 for SD card and SPI3 for W5500.

Interrupts conflict with UART and I2C and need to be disabled.

Addendum: After changing spim3
compatible = "nordic,nrf-spim";
to
compatible = "wiznet,w5500";
in the overlay file, the following symptoms disappeared, and
there is no need to use irq_connect_dynamic or modify the nrfx_spim library.

I use CONFIG_DYNAMIC_INTERRUPTS because the SD card library initializes both SPI2 and SPI3. (Compilation fails when IRQ_CONNECT is defined for SPI3) It worked when it was clearly initialized with irq_connect_dynamic at runtime. ↓ ↓ ↓ ↓ ↓ Addendum: This correction is also necessary

As of 2021.11.15 → Use Ethernet Sheild (W5500 and SDCard) with nRF9160 feather …

https://qiita.com

↑↑↑↑↑ Addendum: This correction is also necessary

circuitdojo_feather_nrf9160ns.overlay
// SEGGER Embedded Studio auto generated
&uart1 {
        status = "disabled";
 };
&gpio0 {
    status = "okay";
};
&gpiote {
    status = "okay";
};
&i2c2 {
    status = "disabled";
};
&spi1 {
    status = "disabled";
};
&spi2 {
    compatible = "nordic,nrf-spim";
    status = "okay";
    mosi-pin = <21>;
    miso-pin = <22>;
    sck-pin = <19>;
    cs-gpios = <&gpio0 3 GPIO_ACTIVE_LOW>; /* SDHC */
    sdhc0: sdhc@0 {
        compatible = "zephyr,mmc-spi-slot";
        reg = <0>;
        status = "okay";
        label = "SDHC0";
        //spi-max-frequency = <24000000>;
        spi-max-frequency = <8000000>;
    };
};
&spi3 {
//  compatible = "nordic,nrf-spim";
    compatible = "wiznet,w5500";
    interrupts = < 0xb 0x1 >;
    status = "okay";
    mosi-pin = <21>;
    miso-pin = <22>;
    sck-pin = <19>;
    cs-gpios = <&gpio0 4 GPIO_ACTIVE_LOW>; /* W5500 */
};

The pin layout of feather is set as follows:
COPI (MOSI) pin is 21 pin
CIPO (MISO) pin is 22 pin
SCK pin is 19 pin
W5500 CS pin is 4 pin (8 pin on board)
SDCard CS 3 pins (7 pins on the board)

Ethernet Sheild’s W5500 and SDCard’s MOSI, MISO, SCK are common, so I tried it like this.

Other notes

When switching between W5500 (SPI3) and SD (SPI2)

NRF_SPIM3-> ENABLE = 0; // or NRF_SPIM2-> ENABLE = 0;

It was necessary to disable the SPI of the person who does not use it.
To enable it, substitute 7 instead of 0.

I don’t know the correct method, so I’m talking about the level that worked for the time being.

NORDIC nRF9160DK

The nRF9160DK worked with the Ethernet Sheild plugged in directly.

Note that it will not work properly unless you write a program to switch the pin wiring to nRF52840 on the nRF9160DK in advance.

The control of the board wiring of nRF9160DK must be set on the nRF52840 side.
By default, it is connected to LEDs and switches.
Since the UART is also connected to VCOM (virtual port on USB), nothing is output or input even if it is wired to a pin.

lastly

The advantage of nRF9160 is that LTE communication can be used easily.
However, it is regrettable that the development environment is difficult and the library specifications change.

However, since it is a chip that I have to deal with for the time being, I have no choice but to do my best.

nrf.PNG

Introduction

A memorandum on how to use Ethernet Sheild (SPI module of W5500 & SD card) with nRF9160DK, nRF9160 feather, etc. in ncs v1.6.1 environment.

Zephyr’s library is hard to get along with, so I’m quite addicted to it.

The implementation method in this article seems to work but not the correct answer.

I want to know the correct answer, but there is little information.

About wiring

If possible, I had to make a direct connection or keep the wiring as simple as possible to
get a decent waveform.

Library etc.

W5500 forcibly ported the library provided by wiznet without using the Zephyr driver.
https://github.com/Wiznet/ioLibrary_Driver

The SD card came to work for the time being by using Zephyr’s library
.

The biggest problem is the operation of SPI.

Even if I implemented it in the usual (?) Way, it didn’t work at all.
I tried using the NRFX_SPIM library and it worked for some reason.

prj.conf (excerpt)
CONFIG_SPI=n
CONFIG_NRFX_SPIM=y
CONFIG_NRFX_SPIM2=y
CONFIG_NRFX_SPIM3=y

CONFIG_DISK_ACCESS=y
CONFIG_DISK_DRIVER_SDMMC=y
CONFIG_SDMMC_OVER_SPI=y
CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y

Use SPI2 for SD card and SPI3 for W5500.

Interrupts conflict with UART and I2C and need to be disabled.

Addendum: After changing spim3
compatible = "nordic,nrf-spim";
to
compatible = "wiznet,w5500";
in the overlay file, the following symptoms disappeared, and
there is no need to use irq_connect_dynamic or modify the nrfx_spim library.

I use CONFIG_DYNAMIC_INTERRUPTS because the SD card library initializes both SPI2 and SPI3. (Compilation fails when IRQ_CONNECT is defined for SPI3) It worked when it was clearly initialized with irq_connect_dynamic at runtime. ↓ ↓ ↓ ↓ ↓ Addendum: This correction is also necessary

As of 2021.11.15 → Use Ethernet Sheild (W5500 and SDCard) with nRF9160 feather …

https://qiita.com

↑↑↑↑↑ Addendum: This correction is also necessary

circuitdojo_feather_nrf9160ns.overlay
// SEGGER Embedded Studio auto generated
&uart1 {
        status = "disabled";
 };
&gpio0 {
    status = "okay";
};
&gpiote {
    status = "okay";
};
&i2c2 {
    status = "disabled";
};
&spi1 {
    status = "disabled";
};
&spi2 {
    compatible = "nordic,nrf-spim";
    status = "okay";
    mosi-pin = <21>;
    miso-pin = <22>;
    sck-pin = <19>;
    cs-gpios = <&gpio0 3 GPIO_ACTIVE_LOW>; /* SDHC */
    sdhc0: sdhc@0 {
        compatible = "zephyr,mmc-spi-slot";
        reg = <0>;
        status = "okay";
        label = "SDHC0";
        //spi-max-frequency = <24000000>;
        spi-max-frequency = <8000000>;
    };
};
&spi3 {
//  compatible = "nordic,nrf-spim";
    compatible = "wiznet,w5500";
    interrupts = < 0xb 0x1 >;
    status = "okay";
    mosi-pin = <21>;
    miso-pin = <22>;
    sck-pin = <19>;
    cs-gpios = <&gpio0 4 GPIO_ACTIVE_LOW>; /* W5500 */
};

The pin layout of feather is set as follows:
COPI (MOSI) pin is 21 pin
CIPO (MISO) pin is 22 pin
SCK pin is 19 pin
W5500 CS pin is 4 pin (8 pin on board)
SDCard CS 3 pins (7 pins on the board)

Ethernet Sheild’s W5500 and SDCard’s MOSI, MISO, SCK are common, so I tried it like this.

Other notes

When switching between W5500 (SPI3) and SD (SPI2)

NRF_SPIM3-> ENABLE = 0; // or NRF_SPIM2-> ENABLE = 0;

It was necessary to disable the SPI of the person who does not use it.
To enable it, substitute 7 instead of 0.

I don’t know the correct method, so I’m talking about the level that worked for the time being.

NORDIC nRF9160DK

The nRF9160DK worked with the Ethernet Sheild plugged in directly.

Note that it will not work properly unless you write a program to switch the pin wiring to nRF52840 on the nRF9160DK in advance.

The control of the board wiring of nRF9160DK must be set on the nRF52840 side.
By default, it is connected to LEDs and switches.
Since the UART is also connected to VCOM (virtual port on USB), nothing is output or input even if it is wired to a pin.

lastly

The advantage of nRF9160 is that LTE communication can be used easily.
However, it is regrettable that the development environment is difficult and the library specifications change.

However, since it is a chip that I have to deal with for the time being, I have no choice but to do my best.

COMMENTS

Please Login to comment
  Subscribe  
Notify of
POSTED BY
Reusable S/W