ENC28J60 Notworking with MFRC522 in Arduino mega2560

ENC28J60 Notworking with MFRC522 in Arduino mega2560

#include <EtherCard.h>
#include <ArduinoJson.h>
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 5 //
#define SS_PIN 53 //
unsigned long UID[4];
unsigned long UID1;

// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x79,0x2F,0x30,0x31 };

byte Ethernet::buffer[1000];
static uint32_t timer;
static byte myip[] = { 192,168,0,189 };
// gateway ip address
static byte gwip[] = { 192,168,0,2 };
static byte netmask[] = { 255,255,248,0 };
static byte dns[] = { 192,168,0,2 };
const char website[] PROGMEM = "jizzakhturism.uz";
int tekshiruv=0;
MFRC522 mfrc522(SS_PIN, RST_PIN);

// called when the client request is complete
static void my_callback (byte status, word off, word len) {
Serial.println(">>>");
Ethernet::buffer[off+1000] = 0;
String fullResponse = (const char*) Ethernet::buffer + off;
fullResponse=fullResponse.substring(fullResponse.indexOf("{"), fullResponse.indexOf("}")+1);
//fullResponse.substring(fullResponse.indexOf())
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(fullResponse);
Serial.print(root["a"].as());
}

void setup () {
Serial.begin(57600);
Serial.println(F("JSPI TEST"));

InitRfid();
InitInternet();
}

void loop () {
ether.packetLoop(ether.packetReceive());

if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
String my_str ;
Serial.println("Sizning kartangiz: ");
for (int i = 0; i < mfrc522.uid.size; i++) {
UID[i] = mfrc522.uid.uidByte[i];
my_str+=String(UID[i], HEX); ;
//Serial.print(UID[i], HEX);
}
Serial.println(my_str);
Serial.println();
Serial.print("<<< REQ ");
ether.browseUrl(PSTR("/"), "", website, my_callback);
delay(1000);
}

}

void NetSend(){
Serial.println();
Serial.print("<<< REQ ");
ether.browseUrl(PSTR("/"), "", website, my_callback);
}

void InitRfid(){
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details
}

void InitInternet(){
// Change 'SS' to your Slave Select pin, if you arn't using the default pin
if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
Serial.println(F("Failed to access Ethernet controller"));
if (!ether.staticSetup(myip, gwip, dns))
Serial.println(F("DHCP failed"));

ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);

#if 1
// use DNS to resolve the website's IP address
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
#elif 2
// if website is a string containing an IP address instead of a domain name,
// then use it directly. Note: the string can not be in PROGMEM.
char websiteIP[] = "192.168.0.5";
ether.parseIp(ether.hisip, websiteIP);
#else
// or provide a numeric IP address instead of a string
byte hisip[] = { 192,168,0,5 };
ether.copyIp(ether.hisip, hisip);
#endif
ether.printIp("SRV: ", ether.hisip);

}

void ShowReaderDetails() {
// Get the MFRC522 software version
byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.print(F("MFRC522 Software Version: 0x"));
Serial.print(v, HEX);
if (v == 0x91)
Serial.print(F(" = v1.0"));
else if (v == 0x92)
Serial.print(F(" = v2.0"));
else
Serial.print(F(" (unknown)"));
Serial.println("");
// When 0x00 or 0xFF is returned, communication probably failed
if ((v == 0x00) || (v == 0xFF)) {
Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));
}
}

I have this exact same issue, but with an Uno. Not able to determine why. They both work independantly, but when they are on the same SPI hardware, neither works. I even manually made sure all the RC522 SS pins were grounded.

It looks like the moment the MISO and MOSI of the RC522s connect, they cause this issue.

I'm trying to use a ESP8266 instead, but its not going much better. Also, I'm using 9 RC522 on one Uno. Its totally possible/doable.