Ethernet shield and two RFC522 conflict

Hi everyone!
At first I want to say that there was a dozen of my problem related topics, I’ve red them all and still cannot find solution working for me.
My problem is:
I have an Arduino Mega and Ethernet Shield + 2x RFC522 modules connected to it.
Eth shield by itself works fine. Eth shield + one RFC522 works fine. When connecting the second RFC522 program can’t find my Ethernet Shield. Rst pin and ss pins for both RFC522 modules do not collide with Eth shield pins.

My main code:

#include <SPI.h>
#include <MFRC522.h>
#include <ArduinoJson.h>
#include <Ethernet.h>
#include "eth.h"
#include "rfid.h"

#define     RFCfgReg            0x26<<1 //increase range

#define RST_PIN         41         // Configurable
#define SS1_PIN          42      // Configurable
#define SS2_PIN          43 

MFRC522 mfrc522_1(SS1_PIN, RST_PIN);  // Create MFRC522 instance
MFRC522 mfrc522_2(SS2_PIN, RST_PIN);

#define server_ip "192.168.1.20"
#define port 80

#define LOCK_DELAY 2000


void openLock(){
  digitalWrite(5, HIGH);
  delay(LOCK_DELAY);
  digitalWrite(5, LOW);
}

void beepOk(){
  digitalWrite(22, HIGH);
  delay(100);
  digitalWrite(22, LOW);
  delay(50);
  digitalWrite(22, HIGH);
  delay(100);
  digitalWrite(22, LOW);
}

void beepErr(){
  digitalWrite(22, HIGH);
  delay(300);
  digitalWrite(22, LOW);
  delay(50);
  digitalWrite(22, HIGH);
  delay(150);
  digitalWrite(22, LOW);
  delay(125);
 
}

void setup() {
  // disable SD card
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
  
  Serial.begin(9600);
  SPI.begin();            // Init SPI bus

  


  //Ethernet.init(10);
  pinMode(22, OUTPUT); //tone generator
  pinMode(5, OUTPUT); //lock
  digitalWrite(5, LOW);
  digitalWrite(22, LOW);
  

  // disable SD card

  mfrc522_1.PCD_Init();       // Init MFRC522
 // mfrc522_2.PCD_Init();   // Init MFRC522 
  mfrc522_1.PCD_DumpVersionToSerial();    // Show details of PCD - MFRC522 Card Reader details
  Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
  //mfrc522_2.PCD_WriteRegister(RFCfgReg, (0x07<<4)); // Set Rx Gain to max
  //mfrc522_1.PCD_WriteRegister(RFCfgReg, (0x07<<4)); // Set Rx Gain to max
  mfrc522_2.PCD_Init();   // Init MFRC522 
  mfrc522_2.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 2 Card Reader details
  //check_id(1);
  beepErr();
  //SPI.end();
  //SPI.begin();
  

 
  //pinMode(4, OUTPUT);
  //digitalWrite(4, HIGH);
  //Ethernet.init(10);
   //SPI.end();
  Serial.println("Start Eth conf");
  byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
  if (!Ethernet.begin(mac)) {
    Serial.println(F("Failed to configure Ethernet using DHCP"));
    delay(2500);
    // Check for Ethernet hardware present
    if (Ethernet.hardwareStatus() == EthernetNoHardware) {
      Serial.println("Ethernet shield was not found.");
      while (true) {
        delay(1); // do nothing, no point running without Ethernet hardware
      }
    }
    if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");
      delay(2500);
    }
      return;
  }else{
    Serial.print("DHCP assigned IP: ");
    Serial.println(String(Ethernet.localIP())); 
    } 

  
  
  Serial.println("Hello!");
  
  
  /*//=====INITIALIZE ETHERNET SHIELD=====
  // Start the Ethernet connection:
  //byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
  byte mac[] = {0xAD, 0xDE, 0xBE, 0xEF, 0xFE, 0xED};
  if (!Ethernet.begin(mac)) {
    Serial.println(F("Failed to configure Ethernet using DHCP"));
    //while(true){beepErr();}
    delay(2500);
    // Check for Ethernet hardware present
    if (Ethernet.hardwareStatus() == EthernetNoHardware) {
      Serial.println("Ethernet shield was not found.");
      //while(true){beepErr();}
      //while (true) {
        //delay(1); // do nothing, no point running without Ethernet hardware
      //}
    }
    if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");
      //while(true){beepErr();}
    }
      return;
  }else{
    Serial.print("DHCP assigned IP: ");
    Serial.println(String(Ethernet.localIP())); }  */
  check_uid("4294943244", 0); //test connection
}

void loop() {
  SPI.begin(); //who knows why, doesn't work without this line
    // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
  if ( mfrc522_1.PICC_IsNewCardPresent()) {
    Serial.println("1 detected");
     unsigned long uid = getID(mfrc522_1);
      if(uid != -1){
         Serial.print("Card detected, UID: "); Serial.println(uid);
         if(check_uid(String(uid), 1) == 1){
          beepOk();
          openLock();
         }
         else{
          beepErr();
         }
       }
   } 
   //Serial.println("loop");
  else if(mfrc522_2.PICC_IsNewCardPresent()){
    Serial.println("2 detected");
    unsigned long uid = getID(mfrc522_2);
    if(uid != -1){
      Serial.print("Card detected, UID: "); Serial.println(uid);
      if(check_uid(String(uid), 0) == 1){
        beepOk();
        openLock();
        //Serial.print("ok 2");
      }
      else{
        beepErr();
        Serial.print("err 2");
      }
    } 
  } 

    return;
}
    // Look for new cards

It might look messy because i was trying many different solutions.
Does somebody have any ideas?

Which Ethernet shield are you using? (post a link if possible)

I notice that in the code you have posted there is no call to Ethernet.Init() (all such lines are commented out - why?

What tells you the ethernet shield cannot be found as opposed to another type of failure?

Can you post a picture of how you have everything connected together - probably save significant time rather than asking lots of questions.

How is everything powered?

countrypaul:
Which Ethernet shield are you using? (post a link if possible)

I notice that in the code you have posted there is no call to Ethernet.Init() (all such lines are commented out - why?

What tells you the ethernet shield cannot be found as opposed to another type of failure?

Can you post a picture of how you have everything connected together - probably save significant time rather than asking lots of questions.

How is everything powered?

Hi! Thank you for your time.
For my Ethernet Shiled I use SunFounder Ethernet Shield W5100.
Ethernet.Init() is commented because it doesn't seem to do any difference. It doesn't affect the result no matter if it's present or not. I tried the code with it - no change in result.
The whole thing is powered by 9V 1A power supply through Arduino. Do you think it might be a power issue?
My connection look like: there is an ethernet shield on the top of Arduino connected directly into it and there are my two RFC522s sharing MOSI, MISO, SCK, RST and with two different pins for SDA. It might be problematic to post an image right now but I'll edit my post later.

The reason I asked for a photo was to see how the MOSI, MISO and SCK are all connected together. SPI is a bus, but I just wondered whether you had a star configuration and if that could cause a problem?

countrypaul:
The reason I asked for a photo was to see how the MOSI, MISO and SCK are all connected together. SPI is a bus, but I just wondered whether you had a star configuration and if that could cause a problem?

It turned out to be a power related issue. My second RFC522 was connected by a long ethernet cable, it might have dropped some current along the way. Now I'm powering two of my RFS522s with a separate power source and they also have common GND pin with Arudino.
Countrypaul, thank you for your advice!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.