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!
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.
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,
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:
/*
* 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...
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.
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 .
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.