w5500 not working on SPI1?

Hi, striving to get the w5500 working on Particle Electron using NCD_Ethernet_Overlay.h/.cpp;
The lib supports Particle and the code seems to jive …

So I dove into SPI bus after verifying the obvious (pinMode / SS assignment, setSS(), resetSS() in EthernetClient.cpp, etc.), and here’s an example trace I got;
Are these Voltage swings unstable or should we expect a little slew / bounce?

w5500-volts-on-spi

EDIT - should now be full cycle.
And then is this about right for a SPI exchange?
Coz I’m getting nothing out of the RJ45 (Wireshark) despite verifying a PC can connect to the TCP server (@ 192.168.0.39), unlike this post which seemed to at least get something.

name	type	start_time	duration	mosi	miso
CAN	can_error	3.07339159	1.00E-05		
SPI	enable	3.07345541	4.00E-09		
SPI	result	3.07345682	1.00E-06	0x00	0x00
SPI	result	3.07345922	1.00E-06	0x00	0xFA
SPI	result	3.07346158	1.00E-06	0x00	0xFA
SPI	result	3.07346395	1.00E-06	0x00	0x05
SPI	disable	3.07346668	4.00E-09		
SPI	enable	3.07349923	4.00E-09		
SPI	result	3.07350062	1.00E-06	0x00	0x00
SPI	result	3.07350302	1.00E-06	0x00	0xFA
SPI	result	3.07350538	1.00E-06	0x04	0xFA
SPI	result	3.07350775	1.00E-06	0x85	0x05
SPI	disable	3.07351047	4.00E-09		
SPI	enable	3.07354303	4.00E-09		
SPI	result	3.07354441	1.00E-06	0x00	0x00
SPI	result	3.07354681	1.00E-06	0x1E	0xFA
SPI	result	3.07354918	1.00E-06	0x0C	0xFA
SPI	result	3.07355155	1.00E-06	0x02	0x05
SPI	disable	3.07355426	4.00E-09		
SPI	enable	3.07358683	4.00E-09		
SPI	result	3.07358821	1.00E-06	0x00	0x00
SPI	result	3.07359061	1.00E-06	0x1F	0xFA
SPI	result	3.07359298	1.00E-06	0x0C	0xFA
SPI	result	3.07359534	1.00E-06	0x02	0x05
SPI	disable	3.07359806	4.00E-09		
SPI	enable	3.07363069	4.00E-09		
SPI	result	3.07363208	1.00E-06	0x00	0x00
SPI	result	3.07363448	1.00E-06	0x1E	0xFA
SPI	result	3.07364028	1.00E-06	0x2C	0xFA
SPI	result	3.07364274	1.00E-06	0x02	0x05
SPI	disable	3.07364546	4.00E-09		
SPI	enable	3.07367809	4.00E-09		
SPI	result	3.07367947	1.00E-06	0x00	0x00
SPI	result	3.07368187	1.00E-06	0x1F	0xFA
SPI	result	3.07368424	1.00E-06	0x2C	0xFA
SPI	result	3.0736866	1.00E-06	0x02	0x05
SPI	disable	3.07368932	4.00E-09		
SPI	enable	3.07372195	4.00E-09		
SPI	result	3.07372334	1.00E-06	0x00	0x00
SPI	result	3.07372574	1.00E-06	0x1E	0xFA
SPI	result	3.0737281	1.00E-06	0x4C	0xFA
SPI	result	3.07373047	1.00E-06	0x02	0x05
SPI	disable	3.07373318	4.00E-09		
SPI	enable	3.07376575	4.00E-09		
SPI	result	3.07376713	1.00E-06	0x00	0x00
SPI	result	3.07376953	1.00E-06	0x1F	0xFA
SPI	result	3.0737719	1.00E-06	0x4C	0xFA
SPI	result	3.07377427	1.00E-06	0x02	0x05
SPI	disable	3.07377698	4.00E-09		
SPI	enable	3.07380961	4.00E-09		
SPI	result	3.073811	1.00E-06	0x00	0x00
SPI	result	3.0738134	1.00E-06	0x1E	0xFA
SPI	result	3.07381576	1.00E-06	0x6C	0xFA
SPI	result	3.07381813	1.00E-06	0x02	0x05
SPI	disable	3.07382085	4.00E-09		
SPI	enable	3.07385341	4.00E-09		
SPI	result	3.07385479	1.00E-06	0x00	0x00
SPI	result	3.07385719	1.00E-06	0x1F	0xFA
SPI	result	3.07385956	1.00E-06	0x6C	0xFA
SPI	result	3.07386193	1.00E-06	0x02	0x05
SPI	disable	3.07386464	4.00E-09		
SPI	enable	3.07389728	4.00E-09		
SPI	result	3.07389866	1.00E-06	0x00	0x00
SPI	result	3.07390106	1.00E-06	0x1E	0xFA
SPI	result	3.07390342	1.00E-06	0x8C	0xFA
SPI	result	3.07390579	1.00E-06	0x02	0x05
SPI	disable	3.0739085	4.00E-09		
SPI	enable	3.07394107	4.00E-09		
SPI	result	3.07394246	1.00E-06	0x00	0x00
SPI	result	3.07394485	1.00E-06	0x1F	0xFA
SPI	result	3.07394722	1.00E-06	0x8C	0xFA
SPI	result	3.07394958	1.00E-06	0x02	0x05
SPI	disable	3.0739523	4.00E-09		
SPI	enable	3.07398494	4.00E-09		
SPI	result	3.07398632	1.00E-06	0x00	0x00
SPI	result	3.07398872	1.00E-06	0x1E	0xFA
SPI	result	3.07399108	1.00E-06	0xAC	0xFA
SPI	result	3.07399345	1.00E-06	0x02	0x05
SPI	disable	3.07399617	4.00E-09		
SPI	enable	3.07402873	4.00E-09		
SPI	result	3.07403012	1.00E-06	0x00	0x00
SPI	result	3.07403252	1.00E-06	0x1F	0xFA
SPI	result	3.07403488	1.00E-06	0xAC	0xFA
SPI	result	3.07403725	1.00E-06	0x02	0x05
SPI	disable	3.07403997	4.00E-09		
SPI	enable	3.0740726	4.00E-09		
SPI	result	3.07407398	1.00E-06	0x00	0x00
SPI	result	3.07407638	1.00E-06	0x1E	0xFA
SPI	result	3.07407875	1.00E-06	0xCC	0xFA
SPI	result	3.07408111	1.00E-06	0x02	0x05
SPI	disable	3.07408383	4.00E-09		
SPI	enable	3.07411639	4.00E-09		
SPI	result	3.07411778	1.00E-06	0x00	0x00
SPI	result	3.07412018	1.00E-06	0x1F	0xFA
SPI	result	3.07412254	1.00E-06	0xCC	0xFA
SPI	result	3.07412491	1.00E-06	0x02	0x05
SPI	disable	3.07412763	4.00E-09		
SPI	enable	3.07416366	4.00E-09		
SPI	result	3.07416504	1.00E-06	0x00	0x00
SPI	result	3.07416744	1.00E-06	0x1E	0xFA
SPI	result	3.07416981	1.00E-06	0xEC	0xFA
SPI	result	3.07417217	1.00E-06	0x02	0x05
SPI	disable	3.07417489	4.00E-09		
SPI	enable	3.07420745	4.00E-09		
SPI	result	3.07420884	1.00E-06	0x00	0x00
SPI	result	3.07421124	1.00E-06	0x1F	0xFA
SPI	result	3.0742136	1.00E-06	0xEC	0xFA
SPI	result	3.07421597	1.00E-06	0x02	0x05
SPI	disable	3.07421868	4.00E-09		
SPI	enable	3.07425148	4.00E-09		
SPI	result	3.07425287	1.00E-06	0x00	0x00
SPI	result	3.07425527	1.00E-06	0x09	0xFA
SPI	result	3.07425763	1.00E-06	0x04	0xFA
SPI	result	3.07426004	1.00E-06	0xDE	0x05
SPI	result	3.07426247	1.00E-06	0xAD	0x00
SPI	result	3.07426487	1.00E-06	0xBE	0x00
SPI	result	3.07426727	1.00E-06	0xEF	0x00
SPI	result	3.07426966	1.00E-06	0xFE	0x00
SPI	result	3.07427206	1.00E-06	0xED	0x00
SPI	disable	3.07427482	4.00E-09		
SPI	enable	3.07430795	4.00E-09		
SPI	result	3.07430933	1.00E-06	0x00	0x00
SPI	result	3.07431173	1.00E-06	0x0F	0xFA
SPI	result	3.0743141	1.00E-06	0x04	0xFA
SPI	result	3.0743165	1.00E-06	0x00	0x05
SPI	result	3.07431893	1.00E-06	0x00	0x00
SPI	result	3.07432133	1.00E-06	0x00	0x00
SPI	result	3.07432373	1.00E-06	0x00	0x00
SPI	disable	3.07432648	4.00E-09		
SPI	enable	3.07436228	4.00E-09		
SPI	result	3.0743637	1.00E-06	0x00	0x00
SPI	result	3.07436609	1.00E-06	0x03	0xFA
SPI	result	3.07436846	1.00E-06	0x08	0xFA
SPI	result	3.07437082	1.00E-06	0x00	0x05
SPI	disable	3.07437355	4.00E-09		
SPI	enable	3.07440622	4.00E-09		
SPI	result	3.07440762	1.00E-06	0x00	0x00
SPI	result	3.07441002	1.00E-06	0x03	0xFA
SPI	result	3.07441239	1.00E-06	0x28	0xFA
SPI	result	3.07441476	1.00E-06	0x00	0x05
SPI	disable	3.07441748	4.00E-09		
SPI	enable	3.07445014	4.00E-09		
SPI	result	3.07445156	1.00E-06	0x00	0x00
SPI	result	3.07445396	1.00E-06	0x03	0xFA
SPI	result	3.07445632	1.00E-06	0x48	0xFA
SPI	result	3.07445869	1.00E-06	0x00	0x05
SPI	disable	3.07446141	4.00E-09		
SPI	enable	3.07449408	4.00E-09		
SPI	result	3.07449549	1.00E-06	0x00	0x00
SPI	result	3.07449788	1.00E-06	0x03	0xFA
SPI	result	3.07450025	1.00E-06	0x68	0xFA
SPI	result	3.07450262	1.00E-06	0x00	0x05
SPI	disable	3.07450534	4.00E-09		
SPI	enable	3.07453801	4.00E-09		
SPI	result	3.07453942	1.00E-06	0x00	0x00
SPI	result	3.07454182	1.00E-06	0x03	0xFA
SPI	result	3.07454418	1.00E-06	0x88	0xFA
SPI	result	3.07454655	1.00E-06	0x00	0x05
SPI	disable	3.07454927	4.00E-09		
SPI	enable	3.07458194	4.00E-09		
SPI	result	3.07458335	1.00E-06	0x00	0x00
SPI	result	3.07458575	1.00E-06	0x03	0xFA
SPI	result	3.07458811	1.00E-06	0xA8	0xFA
SPI	result	3.07459048	1.00E-06	0x00	0x05
SPI	disable	3.0745932	4.00E-09		
SPI	enable	3.07462587	4.00E-09		
SPI	result	3.07462728	1.01E-06	0x00	0x00
SPI	result	3.07462968	1.00E-06	0x03	0xFA
SPI	result	3.07463205	1.00E-06	0xC8	0xFA
SPI	result	3.07463441	1.00E-06	0x00	0x05
SPI	disable	3.0746405	4.00E-09		
SPI	enable	3.07467326	4.00E-09		
SPI	result	3.07467468	1.00E-06	0x00	0x00
SPI	result	3.07467707	1.00E-06	0x03	0xFA
SPI	result	3.07467944	1.00E-06	0xE8	0xFA
SPI	result	3.0746818	1.00E-06	0x00	0x05
SPI	disable	3.07468453	4.00E-09		
SPI	enable	3.27487512	4.00E-09		
SPI	result	3.27487648	1.00E-06	0x00	0x00
SPI	result	3.27487888	1.00E-06	0x0F	0xFA
SPI	result	3.27488125	1.00E-06	0x00	0xFA
SPI	result	3.27488362	1.00E-06	0x00	0x05
SPI	result	3.27488602	1.00E-06	0x00	0x00
SPI	result	3.27488842	1.00E-06	0x00	0x00
SPI	result	3.27489082	1.00E-06	0x00	0x00
SPI	disable	3.27489361	4.00E-09		

Finally, pretty basic source code showing the example trying to connect (this shows DHCP, also tried specifying the local IP addr but no worky) -

#include <Ethernet.h>

int tInt = B5;
int tRst = B4;

SerialLogHandler logHandler(115200, LOG_LEVEL_INFO);
EthernetClient eClient;                                 // Global instance
byte mac[] = { 0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed };
IPAddress locIP(192, 168, 0, 150);                            
IPAddress servIP(192, 168, 0, 39);
IPAddress subN (255, 255, 255, 0);
int servPort = 1701;

void setup() {
    System.disableFeature(FEATURE_ETHERNET_DETECTION);

    pinMode(tInt, OUTPUT);                  // Since pulled-up, if mult. devc
    digitalWrite(tInt, HIGH);                   // Active low, so leave high
    pinMode(tRst, OUTPUT);                              
    digitalWrite(tRst, HIGH);
    pinMode(D5, OUTPUT);
                                            // Need pinMode 1st thing! (initSS() w/in Eth.beg)
    delay(1000);
    Log.info("Defined IP:  %s", locIP.toString().c_str());
    if (Ethernet.begin(mac) == 0) {
      Log.info("Failed to config w/ DHCP");
      Log.info("?IP is:  %s", Ethernet.localIP().toString().c_str());
    } else {
      Log.info("Actual IP is: %s", Ethernet.localIP().toString().c_str());
      cnxT = true;
    }

And note the repeated output to serial console is IP addr 5.0.0.0.
Any / all help would be greatly appreciated!

Why SPI “1”? When W5500 accepts the byte, it puts 0x01, 0x02, and 0x03 onto the MISO. You have 0x00, 0xfa, 0xfa therefore something is broken in your SPI communication. As long as you have such scope/logic analyzer, show at least one full access cycle with all four signals. Homework for you to deconstruct what you see in there and prove MOSI is correct (or find the issue and fix it).

Ah many thanks for the starter pointer.
Yea SPI1 is alternate SPI bus on Electron, as such you have to swap out SPI1.begin, etc. funcs.

Ok, and I’ve updated what I believe is a full access cycle, above (after logging all 4 channels on analyzer - clock, SS, MOSI, MISO; means bit less precision but analyzer still picks it up).

Where? I expect 4 separate time-aligned signal logging.

Apologies, you mean the enable and clock signals aren’t shown in data table, beyond miso and mosi?

Else lemme try to show trace output in a better video preview -
w5500-4-traces-short2

And here’s the SPI1 setup funcs -
image

I do not need video preview. I need one read/write cycle in picture which timing and waveform I can analyze.

Ah ok let’s try,

Overview (channel IDs) -

First two frames -

Close up of 1st frame -

Close up of 2nd frame -

I’m not sure why the 1st frame is ‘blank’ from MOSI (despite getting a MISO), tho SPI in Mode-0 if that helps… and SPI1 is dedicated to to just this w5500.
Thanks for your patience / support

MISO can’t be low level when chip is deselected. What W5500 module do you use, and what is connection circuit of everything into SPI bus?

Appreciate that insight,
Using the w5500 >> 48-LQFP (7x7)

  • eth_sck = SCLK
  • eth_SI = MOSI
  • eth_SO = MISO
  • cs (pin D5) = SCS
  • eth_int (output high else pull-up) = INT
  • eth_reset (output high else pull-down) = RST
  • pull-down on EXRES1

Pull-up / down here just means in hardware setup, but those overrode by pinMode as output high.

Else in code the CS pin in code per w5500 lib -
[w5500.cpp]
image

And -
[w5500.h]
image

I am almost convinced this is your problem. Value being read for MR - 0x05 - may be correct one if reserved bits read as 1. So you have problem with MISO in the first, second, and third sections (bytes) of the transaction.

Oh, now I can set those (int, reset) to stay at a value (override pull-up/down resistors), and I had them as OUTPUT High to avoid interfering w/ bus -
image

Not sure I understand what you are doing. Interrupt pin must be tristate at the controller side, and reset pin must be driven actively depending on the need.

You must stop driving MISO line at the controller side. Pull-ups are there to ensure it is in weak 1 when not driven by the SPI slave device.

OK thanks for that,

Actually there are only pull-up on int and pull-down on reset; not on MISO, MOSI (tho I read some folks prefer it on these as well).

So I output high on reset (while running normally), and leave int and MOSI, MISO alone. Let me know if that’s not correct (figured spi1.begin, etc. in w5500 libs controls the CS pin, so long pins are specified correctly).

In fact what does it mean to put w5500 chip in slave mode? Coz I’m not touching the int pin, or should I be?

INT is not a part of the SPI specification.
Your board must have MISO pulled up with let’s say 10k resistor, All other pins are actively driven by the MCU, but you may have pull-ups (all except CLK) or downs (CLK) if you wish.
INT may be pulled up with 10k resistor, and is an input to the MCU. It may be driven actively by the peripheral (W5500); pull-up is required in case peripheral output is open-collector or tri-state.
During SPI communication MCU drives CLK, CS, MOSI, and reads MISO. Means first three are in output mode at the MCU side, and fourth in input mode at the MCU side.

1 Like

Thank you very much for this.

Sorry made mistake in INT passage, corrected, please take a look.

Ok for now (bear with me),

  • if we pretend it’s fine as produced with no pull-ups/downs on MISO or MOSI (perhaps w5500 doesn’t care?),
  • and ignore my boot-up frames (on left side of my trace, per MCU docs)

→ Does it matter that my CS cycles High / Low each frame whereas SparkFun’s CS stays Low 'til done?

Focus on the right side of my trace (updated here) -
image

SparkFun example (upside down, noting they call PICO = MOSI and POCI = MISO) -

Not sure I get what you ask for. Look into the datasheet section 2, you will see everything you need regarding SPI access.

Main point was you stop driving MISO by MCU (its acronym name stands for Master In Slave Out). It is an output of SPI slave device, and input to the MCU. It is recommended to have pull-up, but will work without it. Next design ensure pull-up is in there.

1 Like