SPI Problem with SD-CARD Reader and RC522

Hi @ all,

I have a SPI problem.

I have an ARDUINO MEGA 2560.

On the ICSP ( in the middle of the board ) is a SD-CARD Reader connected
On Pin 50-53 is a RC522 ( RFID ) connected.

The Card Reader is working without any problem, but not the RC522. He's doing nothing.

Even if I load the sample sketch for the RC522 ( CardReader is still connected on hardware side, but not inside the program ), the RC522 is doing nothing.

Any idea why ?

Regards
Stefan

You need to post the code.

Have you separate select pins for the two devices?

There are other Threads about problems with SD Card readers not behaving properly - I think they don't put the SPI system back into the correct state when they are finished. But I don't have one of those readers - just a DIY one that I cobbled together and which does not have a problem.

It may help to call the initialization code for your RC522 device immediately before trying to access it - one of the problems of not being able to see your program!

...R

Here is the code:

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

#define SS_PIN 53
#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("Scan PICC to see UID and type...");
}

void loop() {
	// Look for new cards
	if ( ! mfrc522.PICC_IsNewCardPresent()) {
		return;
	}

	// Select one of the cards
	if ( ! mfrc522.PICC_ReadCardSerial()) {
		return;
	}

	// Dump debug info about the card. PICC_HaltA() is automatically called.
	mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}

As you can see, there's no SD Card Reader inside the code. It's only connected on Hardware side.

StefanKDS:
As you can see, there's no SD Card Reader inside the code. It's only connected on Hardware side.

I don't understand. I thought the problem was caused by the combination of the two devices.

And you have not said what I/O pin you are using to select the SD Card reader

In case you are not aware the pins on the ICSP header are directly connected to the SPI pins on the end of the board. I suspect you have both devices using pin 53

,,,R

The CS PIN for the SD Card is Pin 5.

You're right. In the end I have to use both devices.
But it was not working so I load only a test for the RC522 on the MEGA, but all other hardware is still connected

I presume the RC522 works properly when the SD Card reader is not connected?

Are you sure the SD Card reader is correctly connected?

Not having either piece of hardware I suspect I can't help further.

...R