I’m trying to update an old product that a client wants more of. The old product used a FEZ Panda II and a GHI Ethernet Shield.
I’m attempting to replace it with a Fez Duino and a standard Arduino Ethernet shield (W5500). The device software and TinyCLR installs are all current. To debug,m I’ve removed the Nuget W5500 driver and used the source from GitHub.
My pin declarations and initialisation code is:
var cs = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PB1); // Arduino D10 - Correct for Arduino SPI CS
var reset = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PC4); // Arduino D7
var interrupt = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PA15); // Need to find a pin for this. Standard ethernet shields don't support IRQ
var spiController = SpiController.FromName(SC20100.SpiBus.Spi6); // Arduino D11, D12, D13
var networkController = new W5500Controller(spiController, cs, reset, interrupt);
The throw new Exception("Insufficient buffer space available"); exception is thrown in the following code in W5500Driver.cs :
internal int WriteData(int slot, ref ushort ptr, byte[] src, int offset, int len)
{
if (len > this.memsize)
throw new Exception("The size of the payload exceeds the socket memory size of " + this.memsize + " bytes");
var freeSize = this.SocketRegisterReadUshort(SocketRegisters.TX_FSR, slot);
if (len > freeSize)
throw new Exception("Insufficient buffer space available");
this.buffer[0] = (byte)((ptr >> 8) & 0xff);
this.buffer[1] = (byte)(ptr & 0xff);
this.buffer[2] = (byte)(this.SocketTxRegisterBlock(slot) | SPI_WRITE);
Array.Copy(src, offset, this.buffer, 3, len);
this.WriteRead(this.buffer, 0, len + 3, this.buffer, 0, 0, 0);
ptr += (ushort)len;
return len;
}
The var freeSize = ... line is asking the WizNet chip how much free memory it has left in that particular socket (slot). The len that you are trying to send exceeds that size, but is apparently smaller than the total available memory for that slot, meaning that it would have fit if only something else wasn’t there already. ‘something else’ meaning bytes from a previous send or an ongoing receive.
There are three possible solutions:
Reduce the number of sockets that was configured when the W5500Controller was created. This is the fifth argument in the constructor for W5500Controller, and it defaults to 8. You could set it to 4 and that would double the amount of memory that you have available per socket, but will still allow you to have four sockets open at the same time. Note that this value has to be a power of 2 (1, 2, 4, 8, …)
Wait for whatever send or receive is in progress to complete and free up the buffer before you start this send.
Thanks. Yep, I know it’s after the free size, and it’s getting zero back. I was really hoping I wasn’t going to have to debug the GHI Wiz5500 drivers. I’m in the process of doing that. The code hasn’t sent anything - this is right in the initialisation code of their example on their website. The only thing that has been sent to the chip is a soft reset command at this point.
The one thing that looking at the code has made clear is that the reset and interrupt lines aren’t needed, so I’ve changed them both to null. Some documentation would sure be nice.
Pulled the logic analyser out and the MISO pin is stuck low. Happens with multiple W5500 shields, so it’s either hardware on the Fez Duino or a psuedo-hardware issue like a misconfiguration of the SPI module pins. Sigh. Much debugging for what was supposed to be a quick and dirty port. No wonder I keep losing money…
as far i know W5100 and W5200 and W5500 Arduino Shields
suffer from RESET issues and try different “no arduino shield” or fix this shields “on power up and can hang it on spi mode”
Well, I guess I’m stuck. The SPI implementation is down in the weeds, so I can’t see the PIN selection definitions. If any GHI person reads this, here’s what my logic analyser sees on the SPI lines. Note that this is with multiple boards, and I’ve checked for shorts on the FEZ Duino board, that checks OK.
but in arduino you need to trigger 5v on shield to work (or have selector 3.3v with 5v) and pins for SPI to have proper connections from D10,D11,D12,D13
Forget it. I forgot something critical - the Arduino Ethernet shields use the ICSP connector for the SPI port for the Wiz5100. Sigh. I got caught out as the original product used the Panda II board and the GHI Ethernet shield, which used Arduino D10-D13 for the Wiznet chip. These only connect to the SD card on an Ardunio shield. Back to the drawing board.