making the nRF24L01 and mfrc522 work together on SPI

Hey, this is my first time posting on the forum and after searching the whole forum I’m pretty desperate now. I’m not a newbie I have worked with arduinos for a couple of years so I though maybe this would be easy. Oh man I was wrong.
Okay so my problem is that nRF24L01 and MFRC522 (RFID reader) both use the SPI bus which is okay because we can make multiple slaves use the SPI bus and disable or enable them using the Chip Select pin. But no matter how much I tried this it doesn’t seem to work. By the way my wiring is correct because both of the modules work perfectly alone but when I initialize both and set the Chip select of either one to HIGH it ignores it and they try to work together (but only the NRF module works it keep on printing a message i’m sending from my other arduino). On top of that I tried to initialize just one but disable it’s Chip Select pin by setting it to HIGH, my logical expectation was for it not to send any data to the arduino yet it does. Which lead me to think either i’m doing this all wrong or those two libraries can’t work together.
This is my code :

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);

RF24 radio(5, 6); // CE, CSN
const byte address[6] = "00001";

#define buttonPin 3
#define lock 2

bool buttonState;
bool islocked;

void setup() {
  Serial.begin(115200);
 
  pinMode(SS_PIN, OUTPUT);
  digitalWrite(SS_PIN, HIGH);
  pinMode(RST_PIN, OUTPUT);
  digitalWrite(RST_PIN, HIGH);
  
  SPI.begin();
  mfrc522.PCD_Init();
  
  pinMode(6, OUTPUT);
  digitalWrite(6, HIGH);
  
  radio.begin();
  printf_begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN); 
  radio.printDetails();
  radio.startListening();
  
  pinMode(lock, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() {
  
  digitalWrite(6, HIGH);
  digitalWrite(SS_PIN, LOW);
  digitalWrite(RST_PIN, LOW);

  FindCard();

  digitalWrite(SS_PIN, HIGH);
  digitalWrite(RST_PIN, HIGH);
  digitalWrite(6, LOW);

  if (radio.available()) {
    Serial.println("Radio Avialable");
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.println(text);
  }

  delay(300);
}
void FindCard()
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content = "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
    content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "1A 7E BE 05")
  {
    Serial.println("Authorized access");
    Serial.println();
    digitalWrite(lock, HIGH);
    delay(2000);
    digitalWrite(lock, LOW);
  } else {
    Serial.println(" Access denied");
  }
}

Typically to select a chip you would pull it's chip select LOW. Not HIGH.

Typically the libraries handle the (de-)assertion of their CS, no need to mess with them.

Delta_G:
Typically to select a chip you would pull it's chip select LOW. Not HIGH.

That's what i'm doing, well I think. firstly i'm enabling the RFID (by pulling the CS pin low) and disabling the NRF (by pulling the CS pin high). Then search for a card. Then disabling the RFID and enabling the NRF searching for the message.

Whandall:
Typically the libraries handle the (de-)assertion of their CS, no need to mess with them.

Well that seems to work if the NRF is set as a transmitter but when it's set as a receiver with this line "radio.startListening();" it causes some problems. I'm really confused at this point because I tried every possible combination. WellIi'm going to try to remove everything relation to the CS pins and understand the problem.
Thanks for the response that means a lot ^^.

What Arduino are you using, how do you power the NRF and the MRF?

I am using an Arduino nano and powering it from a USB while powering the two modules with 3.3V of course. I should note that I succeeded in making both work while commenting the initialization lines of the other.

AlcatrazTN:
I am using an arduino nano and powering it from a USB while powering the two modules with 3.3V of course.

From the Nano? That delivers hardly enough juice to run a NRF.
You could try to add a seperate 3.3V supply.
You could give the NRF a small capacitor (2-10 µF) directly connected to its power pins,
I add such a capacitor to all my NRF modules, improving reliability greatly.

Are you sure ? because they work fine until they work together. Right now I tried to make the code the bare minimum (this is my setup and update the rest is the same)

void setup() {
  Serial.begin(9600);

//Initializing the radio 
  radio.begin();
  printf_begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.printDetails();
  radio.startListening();

//Initializing the MFRC 
  SPI.begin();
  mfrc522.PCD_Init();

  pinMode(lock, OUTPUT);
}

void loop() {

  if (radio.available()) {
    Serial.println("Radio Avialable");
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.println(text);
  }

  FindCard();

  delay(300);

}

The result i'm getting is the NRF is reciving data but the MFRC is not reading the card
but when I just comment this line "radio.startListening();" the MFRC works and obviously the NRF doesn't because it's not recieving anymore

AlcatrazTN:
Are you sure ? because they work fine until they work together.

If the power supply is marginaly strong enough for the NRF,
do you thing adding more consumers makes the situation better?

Do you have an additional capacitor on the NRF module?

radio.setPALevel(RF24_PA_MIN);

limits the power demand of the NRF somehow, but running the additional MRF limits the power somehow.

well I thought they are in parallel so i'm pretty sure they are getting 3.3V both or do you think there is maybe something weird going on ?
yes I do have a capacitor for sure. Because it only works with a capacitor from what I habe tried.
Tried changing it to MAX but still the same result the NRF working and the led of the MRF is lit so my guess it's not communicating with the arduino. Is there a way to see which module is using the SPI BUS.
Do you think that maybe the NRF is using the bus without stop and not letting the MFR send anything to the arduino ?

AlcatrazTN:
well I thought they are in parallel so i'm pretty sure they are getting 3.3V both or do you think there is maybe something weird going on ?

Weird? No.
Both devices share the same power line and add their demand, so it is absolutely reasonable
that one device alone works, but both operating at the same time, don't.

AlcatrazTN:
yes I do have a capacitor for sure. Because it only works with a capacitor from what I habe tried.

Which is an indication of a marginal power supply.

AlcatrazTN:
Tried changing it to MAX but still the same result the NRF working and the led of the MRF is lit so my guess it's not communicating with the arduino.

That would raise the power demand of the NRF and can impose problems when rx and tx are nearby.

AlcatrazTN:
Is there a way to see which module is using the SPI BUS.

Yes, use a cheapo 8-bit logic analyzer.

AlcatrazTN:
Do you think that maybe the NRF is using the bus without stop and not letting the MFR send anything to the arduino ?

No. Both the NRF hardware as well as the library are well behaved.

Have you tried that and it worked for you my kind sir ?

I tried a lot of things in my life, you have to be more specific. :wink:

Have you tried to supply a decent 3.3V to the modules?

I'm talking about making NRF and RFID work together.
How do you suggest doing it ? I only have a 12V power supply at hand and I don't have a stepdown board. I can just supply it to the arduino and it will regulate it right ?.

No. That would make things worse.

You can power the Nano from USB and use a 3.3v regulator module (switched or linear) from the 5V rail
to power your 3.3V modules.
There is a quite handy modul with a regulator and a socket for the NRF module.
The nano IO shield provides sockets for the Nano, NRF and a XBee module and has a 3.3V regulator on board.

AlcatrazTN:
I'm talking about making NRF and RFID work together.

No, I have not run both of them in the same setup,
but I have used a NRF and SPI TFT without problems together.

@AlcatrazTN, you sent me a PM with a reference to this Thread.

I have been watching it and it seems you are getting good advice from @Whandall who probably knows more about nRF24s than I do.

You may wish to look at this Simple nRF24L01+ Tutorial

...R

A good power supply to the NRF is essential for its operation.
The power provided by Nanos differs widely among the many different Nanos on the market.

I would eliminate that known possible source of error by using one of the modules above.

Thank you both guys for the help !
Whandall can you give me model reference because I haven't used 3.3v regulators ? preferably something I can solder on a PCB.