RF24 module and MFRC522 RFID reader : SPI bus contention ?

What's the length of the wires to the nrf24 and to the mfrc522?

A little history: I found your post because I also have an RF/RFID combination project, and it initially wasn't working. The project is intended to be used by someone other than me, so I thought I'd be clever and wire it up so that the nrf24 module and the mfrc522 module could be connected via rj45 connectors running a patch cord between the arduino board and a mini board with the RF or RFID modules.

I initially had the nrf24 connected by itself and ran some testing. I found that I couldn't connect a patch cord longer than about 8 inches. If I did, the code would hang and not get past my network.update() line (see the Network_Ping example in the RF24Network library) at the beginning of the loop block.

Ok. Fine. I'll use a shorter RF patch cord.

Separately, I made sure my RFID code worked by commenting out all of the radio code. It worked well with a longer patch cord ~5 ft.

As soon as I connect up both modules with all code uncommented, the RF code would hang again. Unplugging the RFID patch cord got it working again.

So, I soldered up a temporary board using a protoboard and put a female header pin close to the Arduino into which I could directly plug in the nrf24 module. Same thing for the RFID.

Success! Shorter connections helped.

Then, to test, I left the nrf24 module connected into the header and used the 8 in patch cord to extend the RFID.

That also worked.

However, when I went to the 5 ft. patch cord, no luck.

To verify my findings, I wanted to test your code to see if the same thing would work with different code. I didn't have an example of the RX code you were using, but searching for ackPayLoad examples, I found the blog at shantamraj.wordpress.com. I had to modify your code to work with my pinouts and to work with his data. I also modified his data a little to receive the RFID_Data you were sending.

Using these code modifications, I got your code to work with his. I found the same cord length issues I was having: the 8 in. cord and the direct connection worked fine, and the 5 ft. cord didn't. Too bad for me. I'll just have to make it work.

However, the modified code is below. This code works for me with 2 Arduino nanos and their respective nrf24 hardware. I've tried to comment the beginning of the lines where I modified your code. I may have missed some.

Your code (TX side):

#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
#include <MFRC522.h>
/****************** User Config ***************************/
/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7,8 */
/*changed per my setup*/    //RF24 radio(7, 8);
/*changed per my setup*/    RF24 radio(9, 10);
/**********************************************************/
/* RFID interface configuration apart from SPI bus */
/*changed per my setup*/    //#define RfidRst    9                                           // RFID reset pin
/*changed per my setup*/    //#define RfidSel    10                                          // RFID select pin
/*changed per my setup*/    #define RfidRst    15                                           // RFID reset pin
/*changed per my setup*/    #define RfidSel    14                                          // RFID select pin
/*********************************************************/
/*changed to work with RX from URL*/   //byte rf_Address[6] = { "3_PTX" };                               // Radio pipe refernce of this RFIDReader,
/*changed to work with RX from URL*/   const uint64_t pipe[1] = { 0xF0F0F0F0E1LL };
MFRC522 mfrc522(RfidSel, RfidRst);                             // Instantiate the reader MFRC522
byte RFID_Data[4];                                             // Data to Rx unit
/*changed to work with RX from URL*/   //bool resetRFID;                                                // Reset data frrom Rx
/*changed to work with RX from URL*/   int resetRFID;
unsigned long prevMillisA;
unsigned long intervalA = 500;
unsigned long rfStatusTimeOut;
byte rfidTxCount;
bool blockMfrc522;

byte RF_OK_Out = 3;
byte RFID_OK_Out = 4;

void setup() {
	Serial.begin(9600);
	Serial.println(F("*** STARTING TRANSMITTER *** "));
	SPI.begin();
	mfrc522.PCD_Init();                                          // Initialize the  MFRC522 reader

																 // Setup and configure radio
	radio.begin();
	radio.setChannel(108);                                       // Above most Wifi Channels
	radio.setDataRate(RF24_250KBPS);
	radio.setRetries(5, 10);                                     // Delay, count
	radio.enableAckPayload();                                    // Allow optional ack payloads
	radio.enableDynamicPayloads();                               // Ack payloads are dynamic payload

	pinMode(RF_OK_Out, OUTPUT);
	pinMode(RFID_OK_Out, OUTPUT);
}

void loop(void)
{
	if (!blockMfrc522) getRFID();                               // Read the RFID tag... when not transmitting

	if (RFID_Data[0] == 0 && RFID_Data[1] == 0 && RFID_Data[2] == 0 && RFID_Data[3] == 0)
	{
		digitalWrite(RFID_OK_Out, LOW);                            // Handle the RFID led..
	}
	else
	{
		digitalWrite(RFID_OK_Out, HIGH);
	}
	//******************************************************
	//if (millis() - prevMillisA > intervalA)
	if (blockMfrc522)
	{
		prevMillisA = millis();
		//blockMfrc522 = true;
		send_rfid();                                             // Transmitt the last read RFID
		blockMfrc522 = false;
	}
	//******************************************************
	if (millis() - rfStatusTimeOut > 2000)                      // Update RF24 comm status
	{
		digitalWrite(RF_OK_Out, LOW);
	}
	else
	{
		digitalWrite(RF_OK_Out, HIGH);
	}
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void send_rfid()
{
/*changed to work with RX from URL*/   	//radio.openWritingPipe(rf_Address);                                 // Open the writing pipe with own reference
/*changed to work with RX from URL*/   	radio.openWritingPipe(pipe[0]);
	bool rfTxStatus = (radio.write(&RFID_Data, sizeof(RFID_Data)));     // Send the RFID info
	if (rfTxStatus)          // PROBLEM : THIS BOOL NEVER RETRUNS TRUE
	{
		if (radio.isAckPayloadAvailable())                              // Sent. Now read the Ack Pay load from Rx module..
		{
			radio.read(&resetRFID, sizeof(resetRFID));                      // If ackPayLoad is True , reset RFID data
		}
		/*changed to work with RX from URL*/   		//if (resetRFID)
		/*changed to work with RX from URL*/   		if (resetRFID == 2)
		{
			RFID_Data[0] = 0;
			RFID_Data[1] = 0;
			RFID_Data[2] = 0;
			RFID_Data[3] = 0;
/*added to verify data cleared*/   			Serial.println("data reset");
		}
		rfStatusTimeOut = millis();                                     // Hold the RF_OK LED 
	}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// FUNCTION TO READ RFID TAG AND CONVERT IT TO A 8 BYTE DATA

int getRFID()
{
	// Look for new cards
	if (!mfrc522.PICC_IsNewCardPresent()) {
		return;
	}
	// Select one of the cards
	if (!mfrc522.PICC_ReadCardSerial()) {
		return;
	}
	for (int i = 0; i < mfrc522.uid.size; i++) {
		RFID_Data[i] = mfrc522.uid.uidByte[i];
	}
	blockMfrc522 = true;
	char scannedRFID[10];
	sprintf(scannedRFID, "%02X%02X%02X%02X", RFID_Data[0], RFID_Data[1], RFID_Data[2], RFID_Data[3]);
	Serial.println(scannedRFID);

	mfrc522.PICC_HaltA();
	return 1;
}

Receiver code (based on URL above):

#include<SPI.h>
#include<nRF24L01.h>
#include<RF24.h>
const uint64_t pipe[1] = {0xF0F0F0F0E1LL};
RF24 radio(8, 9);
int rec[1] = {2};
byte RFID_Data[4];
void setup()
{
  Serial.begin(115200);
  radio.begin();
  delay(100);
  radio.setChannel(108);
  radio.setDataRate(RF24_250KBPS);
  radio.setAutoAck(true);
  radio.enableAckPayload();
  radio.enableDynamicPayloads();
  radio.openReadingPipe(1, pipe[0]);
  radio.startListening();
  radio.setRetries(15, 15);
}
void loop()
{
  if ( radio.available() ) {
    radio.writeAckPayload( 1, rec, sizeof(int) );
    radio.read( &RFID_Data, sizeof(RFID_Data) );
    Serial.print("Data got is: ");
    char scannedRFID[10];
    sprintf(scannedRFID, "%02X%02X%02X%02X", RFID_Data[0], RFID_Data[1], RFID_Data[2], RFID_Data[3]);
    Serial.println(scannedRFID);
  }
}

Hope this helps.