ethernet shield cant set static IP

Hi there!

I am building a small project with MRFC522 and ethernet shield.
A client of mine has a lot of W5100 ehternet shields and old Uno-s.

The stuff works like following:

  • somone swipes a mifare card on the mrfc522 and the information gets sent to a http server which decides whether the card is valid or not, by answering 0 or 1. This switches a relay and lights aup a led.

The stuff works lika a charm.

However the client wants to have a small footprint as mpossible, and asked me to have only the mrfs522 at the normal height, and the uno should be placed above the ceiling tiles.

This means that the MRFS shoud be at a distance at about 2m from the uno.

This messed up the working system.
Because both MRFS522 and ehternet shield use SPI, which isn’t meant to be used over meter distances.

I have gotten a bit around some of the problems by adding this code:

SPI.setClockDivider(SPI_CLOCK_DIV128);
SPI.begin();

now the card is read 100% well over the reader. BUT the ethernet shield stopped working. I set each device with static ip like this:

#include <SPI.h>
#include <Ethernet.h>
#include <MFRC522.h>
#include <Adafruit_NeoPixel.h>
[......]
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 123, 149);
IPAddress myDns(192, 168, 123, 1);
EthernetClient client;
[......]
Ethernet.begin(mac, ip, myDns);
  Serial.print("My IP address: ");
  Serial.println(Ethernet.localIP());

when I print my IP address over the serial console, i get random IP-s, like this:

My IP address: 224.160.189.0
My IP address: 192.212.247.16
My IP address: 255.0.0.16
My IP address: 0.0.189.0

Can the hardware or the software get changed in some way to get the ehternet shield working?
If i disconnect tha 2M cable, it works like a charm again…

thx

CadilLACi

Can the hardware or the software get changed in some way to get the ehternet shield working?

You already know the answer to that. The Ethernet shield does not expect the SPI bus speed to be that slow. If you want the Ethernet shield to work, you need to run the bus at the proper speed.

Of course, that means no 2 meter cables connecting the RFID reader to the Arduino.

You have, it seems to me, two choices. Tell the client to suck it up, and keep all the hardware together. Or, get a different client.

Seriously, you may be able to separate the antenna from the RFID reader, so the antenna is the only thing near where the card is to be scanned, and the actual reader is out of sight.

The Ethernet library stores the IP address you give it into the W5100 chip and fetches it from there when you call .localIP() so if you are getting garbage you are having trouble with your Ethernet shield. Try removing any other devices you have on the SPI bus, including any SD card. If that helps, you have a hardware problem.