TMRh20 RF24 library does not like MFRC522 library ! ( SOLVED)

I am using ( or atleast trying ) to send RFID data via a RF link using the following libraries :

For RFID : GitHub - miguelbalboa/rfid: Arduino RFID Library for MFRC522

For RF24 : https://github.com/TMRh20/RF24/archive/master.zip

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

/****************** User Config ***************************/
/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7,8 */
RF24 radio(7, 8);
/**********************************************************/

byte myAddress[6] = "RxBBB";                                         // Radio pipe addresses of this receiver - must match with one in Tx code Slave1.
boolean recvData[2];
byte ackPayLoad[8] = {1,2,3,4,5,6,7,8};

#define RfidRst    9                                                  // RFID reset pin
#define RfidSel    10                                                 // RFID select pin

// INSTANTIATE THE RFID READER MFRC522
//MFRC522 mfrc522(RfidSel, RfidRst);

void setup()
{
  Serial.begin(9600);
  Serial.println(F("*** STARTING RECIEVER *** "));

  // INITIALIZE THE MFRC522 READER
  //mfrc522.PCD_Init();

  // Setup and configure radio
  radio.begin();
  radio.setChannel(108);                                              // Above most Wifi Channels
  radio.setDataRate( RF24_250KBPS );
  radio.setPALevel(RF24_PA_MAX); 
  radio.enableDynamicPayloads();                                      // Ack payloads are dynamic payloads
  radio.openReadingPipe(1, myAddress);
  radio.enableAckPayload();
  radio.writeAckPayload(1, &ackPayLoad, sizeof(ackPayLoad));          // pre-load data for first acknowledgement

  radio.startListening();
}

//****************************************************
void loop(void)
 
{
  byte pipeNo = 1;
  if ( radio.available(&pipeNo))                                           // Is payload available from Tx ?
  {
    radio.read( &recvData, sizeof(recvData));                              // Get the Payload from Tx & check what user wants to do
    //getRFID();
    radio.writeAckPayload(pipeNo, &ackPayLoad, sizeof(ackPayLoad ));       // Send Ack Payload to Tx with the RFID data
  }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/*
// FUNCTION TO READ RFID TAG AND CONVERT IT TO A 4 BYTE DATA

int getRFID() {


  if ( ! mfrc522.PICC_IsNewCardPresent()) {                             //New PICC ? ... continue
    return 0;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) {                              //Get Serial and continue.
    return 0;
  }
  for (int i = 0; i < mfrc522.uid.size; i++) {
    ackPayLoad[i] = mfrc522.uid.uidByte[i];
  }
  mfrc522.PICC_HaltA();                                                 //Stop reading
  return 1;
}
*/

I am able to get an active Radio Link with the transmitter, only when I disable all references to the MFRC522 library ( as in the copied code above ). I am not sure where the conflict is. I have taken care to avoid clashes in the SS pins for both the RF24 and RFID module.

Any possible points to check ?? Thanks in advance …

If you are using an Uno suggest you try a pin other than 10 for the MFRC522 in case it is interfering with the use of SPI by the nRF24. When using SPI pin 10 must be an OUTPUT in order for the Uno to act as an SPI master.

If both devices use SPI the problem may be due to each of them needing different SPI settings. It was also mentioned elsewhere that some SPI devices don’t properly release MISO.

…R

Thanks Robin. Your link served as a good reminder and as advised spending sometime to read things helped !!

The problem is solved. I just added the line SPI.begin(); before Setup() and the modules started linking immediately. Did not change the SS pin for RFID and it remains as 10. I can now read the RFID connected to the receiver.

Maybe i will clean up both the Transmitter and Receiver code and post later for someone who searches for one such set up.

The RFID TX and Rx codes tested with nRF24 module both on Transmitter and Receiver. The RFID module is a MIFARE type ( available on E-bay) and connected to the Receiver module. The RFID info read by it is sent via nRF24 module to a matching Transmitter which displays the RFID on the serial monitor. This is a basic AckPayLoad type setup and can be expanded to suit other such requirements.

The Tx Module :

/*
  Radio Transmitter sketch using nRF24L01 modules...works together with nRF24_RFID_Rx

  nRF24L01 Module to UNO pins :
  GND  > GND
  Vcc  > 3.3V
  CE   > 7
  CSN  > 8
  SCK  > 13
  MOSI > 11
  MISO > 12
  IRQ  > Not Used

  The Tx sends a Payload to the Rx module once every 0.5 Sec comprising of a two element Boolean array.
  Though not used now, these booleans can be used to clear or request for RFID IDs later as required.
  Though the Rx module sends 8 bytes from the RFID tag, the Tx uses only the first four bytes which is the
  RFID UID.

  This code uses the Call Response method wherein the Tx and Rx modules retain thier roles as is and the
  RFID is sent by the Rx module as a response to the query from Tx.

*/

#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>


RF24 radio(7, 8);                                              
byte slaveAddress[] = "RxBBB";                                 // Radio pipe addresses for Slave

boolean txReadyClear[2];                                       // The Tx to Rx payload is a bool array
byte ackPayLoad[8] = {0, 0, 0, 0, 0, 0, 0, 0};
byte pinSS = 10;

void setup() {

  Serial.begin(9600);
  Serial.println(F("*** STARTING TRANSMITTER *** "));

  SPI.begin();

  // Setup and configure radio
  radio.begin();
  radio.setChannel(108);                                       // Above most Wifi Channels to avoid interefernce
  radio.setDataRate( RF24_250KBPS );                           // Set the bitrate
  radio.setPALevel(RF24_PA_MAX);                               // Set the transmit power..
  radio.enableAckPayload();                                    // Allow optional ack payloads
  radio.enableDynamicPayloads();                               // Ack payloads are dynamic payloads
  radio.setRetries(5, 10);                                     // Delay, count

  pinMode(pinSS, OUTPUT);
}

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$
void loop(void)
{
  rfLinkQuery();
  delay(500);                                                   // Change this to suit your requirement
}

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

// FUNCTION TO KEEP SENDING QUERY PAYLOADS ..

void rfLinkQuery()
{
  byte uid_RFID[4];
  radio.openWritingPipe(slaveAddress);                           // Open the writing pipe to Slave

  if (radio.write(&txReadyClear, sizeof(txReadyClear)))          // Send the query payload
  {
    delay(5);
    if ( radio.isAckPayloadAvailable() )                         // Sent. Now read the Ack Pay load from Rx module..
    {
      radio.read(&ackPayLoad, sizeof(ackPayLoad));
    }
    Serial.print( "RFID UID : " );                               // Display it...
    Serial.print(ackPayLoad[0], HEX);
    Serial.print(ackPayLoad[1], HEX);
    Serial.print(ackPayLoad[2], HEX);
    Serial.println(ackPayLoad[3], HEX);
  }
  else
  {
    Serial.println ( " Radio Link Fault ! " );                    // Send by Tx failed...
  }
}

The Rx Module :

/*
  Single channel receiver  to be used with nRF24_RFID_Tx.ino

  This Receiver is configured for AckPayLoad and on receipt of a payload 
  from the Tx module, sends back the payload with the RFID tag reference.

  The Payload from Tx contains two booleans and if required these can be used
  for clearing the RFID tag reference or getting the RFID on demand. 

  nRF24L01 Module to UNO pins :
  GND  > GND
  Vcc  > 3.3V
  CE   > 7
  CSN  > 8
  SCK  > 13
  MOSI > 11
  MISO > 12
  IRQ  > Not Used

  MFRC522 Module to UNO pins :
  GND  > GND
  Vcc  > 3.3V
  RST  > 9
  SDA  > 10
  SCK  > 13
  MOSI > 11
  MISO > 12
 
*/


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

RF24 radio(7, 8);                                                   // Set up nRF24L01 radio on SPI bus plus pins 7,8

byte myAddress[6] = "RxBBB";                                         // Radio pipe addresses of this receiver - must match with one in Tx code Slave1.
boolean recvData[2];
byte ackPayLoad[8] = {1,2,3,4,5,6,7,8};

#define RfidRst    9                                                  // RFID reset pin
#define RfidSel    10                                                 // RFID select pin


MFRC522 mfrc522(RfidSel, RfidRst);                                    // Instantiate the reader MFRC522

void setup()
{
  Serial.begin(9600);
  Serial.println(F("*** STARTING RECIEVER *** "));

  SPI.begin();
  
  mfrc522.PCD_Init();                                                 // Initialize the  MFRC522 reader

  radio.begin();                                                      // Set up and configure Radio
  radio.setChannel(108);                                              // Above most Wifi Channels to avoid interference
  radio.setDataRate( RF24_250KBPS );
  radio.setPALevel(RF24_PA_MAX); 
  radio.enableAckPayload();
  radio.enableDynamicPayloads();                                      // Ack payloads are dynamic payloads
  radio.openReadingPipe(1, myAddress);
  radio.writeAckPayload(1, &ackPayLoad, sizeof(ackPayLoad));          // pre-load data for first acknowledgement

  radio.startListening();
}

//****************************************************
void loop(void) 
{
  byte pipeNo = 1;
  if ( radio.available(&pipeNo))                                           // Is payload available from Tx ?
  {
    radio.read( &recvData, sizeof(recvData));                              // Get the Payload from Tx & check what user wants to do
    getRFID();
    radio.writeAckPayload(pipeNo, &ackPayLoad, sizeof(ackPayLoad ));       // Send Ack Payload to Tx with the RFID data
  }
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

// FUNCTION TO READ RFID TAG AND CONVERT IT TO A 4 BYTE DATA

int getRFID() {

  if ( ! mfrc522.PICC_IsNewCardPresent()) {                             //New PICC ? ... continue
    return 0;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) {                              //Get Serial and continue.
    return 0;
  }
  for (int i = 0; i < mfrc522.uid.size; i++) {
    ackPayLoad[i] = mfrc522.uid.uidByte[i];
  }
  mfrc522.PICC_HaltA();                                                 //Stop reading
  return 1;
}

// ............END .............

Should the

  pinMode(pinSS, OUTPUT);

not be placed before the

  SPI.begin();

?

Whandall:
Should the

  pinMode(pinSS, OUTPUT);

not be placed before the

  SPI.begin();

?

Very true... but this slip happened as initially there was no SPI.begin(); line at all, and yet the Tx code was working. Later I added the line and I saw no issues. Should have corrected before posting. Thanks