Go Down

Topic: Ethernet + 2 SPI devices (Read 12153 times) previous topic - next topic

adilutan

Hi!

I have a problem with my Arduino uno R3.I want put one Ethernet shield and 2 RC522 ( )

When I put one RC522 without Ethernet, it works perfectly but when I connect the Ethernet, the both doen't work.
How can I connect another SPI devices when I have the Ehernet shield conected?
Thank's!

SurferTim

You must insure that only one SPI device is active at a time. The way I get them to work is connect the hardware and test each device with the other device disabled.

If you have each device on its own slave select, then try this with the working RC522 code and the ethernet shield connected. I disabled the SD SPI also so if you have a card in the SD slot, it won't interfere with the RC522.
Code: [Select]
void setup() {
    Serial.begin(9600);

    // disable SD SPI
    pinMode(4, OUTPUT);
    digitalWrite(4, HIGH);

    // disable w5100 SPI
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH);

    // rest of your setup
}

Does your RC522 work with this setup?

adilutan

it works but I want to read a card  and after send it via Ethernet.How can I do this?

SurferTim


it works but I want to read a card  and after send it via Ethernet.How can I do this?

Not a problem. I am doing this now with the w5100 and the SD, but the theory is the same. What pins are you using for the RC522 slave selects?

adilutan

I resolved the problem.Thank you!
I use 7 for SS.

guilherme07

Hello my friend!

I'm currently at  the same boat you were before the solution. My problem is that I have just one SPI device ( 1 RC522) and I need to send it through ethernet shield. How did you resolved this issue ? I would really appreciate your help! Tks in Advance,

SurferTim

Same as above. Use a slave select for the RC522 that is not D10 or D4. The solution for adilutan was using D7.


letinas

#7
Nov 11, 2014, 09:30 pm Last Edit: Nov 11, 2014, 09:33 pm by letinas
Hi!

I have a similar problem with the same configuration.
After reading this and similar threads, it was quite obvious that pins 4 and 10 can not be used.
Therefore I used pin 8 as SS pin for my RFID-RC522.

The problem is that if the memory card is inside, I would see any response on Serial monitor when RFID device is scanned, or there would be error message: "MIFARE_Read() failed: The CRC_A does not match."

The code is following:
Code: [Select]

/*
 * Dump block 0 of a MIFARE RFID card using a RFID-RC522 reader
 * Uses MFRC522 - Library to use ARDUINO RFID MODULE KIT 13.56 MHZ WITH TAGS SPI W AND R BY COOQROBOT.
 -----------------------------------------------------------------------------
 * Pin layout should be as follows:
 * Signal     Pin              Pin               Pin
 *            Arduino Uno      Arduino Mega      MFRC522 board
 * ------------------------------------------------------------
 * Reset      9                5                 RST
 * SPI SS     10               53                SDA
 * SPI MOSI   11               52                MOSI
 * SPI MISO   12               51                MISO
 * SPI SCK    13               50                SCK
 *
 * Hardware required:
 * Arduino
 * PCD (Proximity Coupling Device): NXP MFRC522 Contactless Reader IC
 * PICC (Proximity Integrated Circuit Card): A card or tag using the ISO 14443A interface, eg Mifare or NTAG203.
 * The reader can be found on eBay for around 5 dollars. Search for "mf-rc522" on ebay.com.
 */

#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 8    //Arduino Uno; CHANGED TO 8 TO AVOID CONFLICT WITH ETHERNET
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);        // Create MFRC522 instance.

void setup() {
        Serial.begin(9600);        // Initialize serial communications with the PC
       
       
       
        SPI.begin();                // Init SPI bus
        mfrc522.PCD_Init();        // Init MFRC522 card
        Serial.println("Print block 0 of a MIFARE PICC ");
}

void loop() {
       
        // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
        MFRC522::MIFARE_Key key;
        for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;
       
        // Look for new cards
        if ( ! mfrc522.PICC_IsNewCardPresent()) {
                return;
        }

        // Select one of the cards
        if ( ! mfrc522.PICC_ReadCardSerial())    return;
       
        Serial.print("Card UID:");    //Dump UID
        for (byte i = 0; i < mfrc522.uid.size; i++) {
          Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
          Serial.print(mfrc522.uid.uidByte[i], HEX);
        }
        Serial.print(" PICC type: ");   // Dump PICC type
        byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
        Serial.println(mfrc522.PICC_GetTypeName(piccType));
         
        byte buffer[18]; 
        byte block  = 0;
        byte status;
        //Serial.println("Authenticating using key A...");
        status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
        if (status != MFRC522::STATUS_OK) {
           Serial.print("PCD_Authenticate() failed: ");
           Serial.println(mfrc522.GetStatusCodeName(status));
           return;
        }
       
        // Read block
 byte byteCount = sizeof(buffer);
 status = mfrc522.MIFARE_Read(block, buffer, &byteCount);
 if (status != MFRC522::STATUS_OK) {
    Serial.print("MIFARE_Read() failed: ");
    Serial.println(mfrc522.GetStatusCodeName(status));
 }
        else  // Dump data
 for (byte index = 0; index < 16; index++) {
    Serial.print(buffer[index] < 0x10 ? " 0" : " ");
    Serial.print(buffer[index], HEX);
    if ((index % 4) == 3) Serial.print(" ");
 }
        Serial.println(" ");
        mfrc522.PICC_HaltA(); // Halt PICC
        mfrc522.PCD_StopCrypto1();  // Stop encryption on PCD
       
}


I have tried using other pins, but with no success. Without memory card everything works perfectly.

EDIT:
If SD SPI disabled, as SurferTim suggested, everything works...

SurferTim

#8
Nov 11, 2014, 09:52 pm Last Edit: Nov 11, 2014, 10:12 pm by SurferTim
If you have a SD card in the slot, you must disable it in setup before calling SPI.begin().
Code: [Select]
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);

You will also need to make two minor mods to the SD library. I'll try to find those for you. Otherwise the SD card does not release the MISO line.

letinas

Will I be able to use SD card if I disable it first?
Please do try to find the mods...

My plans are to make a RFID lock which logs users and allows access according to data on a website.
:)

SurferTim

Yes, you can use the SD card. Just insure that all other SPI devices are initialized or the SPI slave select line is HIGH when you call SD.begin(). Calling SPI.begin() on an Uno will disable the w5100 (sets D10 as OUTPUT and HIGH) on the ethernet shield, so you don't have to do that one.

Here is a link to the fix that releases the MISO line on a SD card. I just modified the two files with the one line change each.
http://forum.arduino.cc/index.php?topic=276274.msg1945270#msg1945270

Asetyde

Hi , i've same problem , a wiz5200 and c522 in same device , but i understand that i must put one in d10 and one in d7 but other ? all same d11 d12 d13 ? both device has same pin , can someone explain a clear method , if not this posts can not useful .

thanks alex

SurferTim

All devices use the SPI data lines in common. On an Uno, those are D11, D12, and D13. All must have separate slave select lines. The wiznet w5200 slave select should be on D10. That library is the most difficult to change the slave select on, but it can be done. Use D8 and D9 for the others. If the w5200 has a SD card on it, that uses D4 for the slave select.




Asetyde

#13
May 11, 2015, 03:13 pm Last Edit: May 11, 2015, 03:16 pm by Asetyde
but my problem is on mfrc522 rfid and wiz5200 , is not possible put rc522 slave ? i think is more simple than network

my lan card :






has not sd

SurferTim

You have some pins on there that must be connected somewhere. The reset line must be HIGH and the pwdn line must be LOW.

Almost everything on the Arduinos is simpler than the w5200 and networks.

Go Up