Using SPI to use Nrf24L01 and RC522

Hello Arduino Forum!

I am back and I have a question regarding how to use the SPI interface to use two different modules that both require the MOSI, MISO, SS, and SCK pins of the Arduino Mega.

If there is an easier way to do this or some library out there that simply changes the pin layouts of these modules, I would GREATLY appreciate a link. Even to a crash course on using the SPI slave select functionality would be amazing!

On to the project,

Currently I am designed a device using a Mega2560 that at its core will read a RFID tag ( using the RC522 module, which may or may not be replaced later with a stronger reader ) and transmit that data to an Arduino Uno using a pair of Nrf24L01+ High Powered radio antennas.

The Mega arduino has many other included modules ( Such as a RTC, LCD Display, some LEDS here and there and a Piezo Buzzer ), so I do not believe I can simplify this project by just picking up a shield and just using the RC522 reader, all the modules are required and the Mega's expansive pin board is needed.

The issue I am running into is that every library I have come across requires the RC522 reader and Nrf24L01+ Transmitter to independently utilize pins 50-53 ( the SPI interface as I understand it ). My first approach to this problem was to simply "split" the pins in a sense by wiring the components to a breadboard with pin 50 for example go to both the RFID reader and the Radio, but as you can guess I have not had much success with this approach.

Doing further research, I come across this:

To my understanding, you can wire these components to any pin as long as they are defined and the code effectively only runs one of the modules at a time, using the SS ( slave select ) pin to power up and down the respecting module needed.

I am a little concerned that this is out of my depth and am looking for any clear examples to further m knowledge on:

A) how to setup the modules on any pin so that both modules can be used on the same Mega

B) a small example code on what it would be like to "selecting" these devices as the code is run

This forum has already provided excellent insight on helping me getting the Radio Module setup and anymore advice would be greatly appreciated! I am highly enjoying learning how to code these microprocessors and am looking forward to working on a solution.

For SPI the MOSI MISO and SCK lines are shared among all the devices. When you want to talk to a particular device you need to pull Chip Select line LOW for that device (Called CSN for the nRF24). Obviously only one SPI device should have its CS line LOW at any one time.

EDIT to correct my HIGHs and LOWs - sorry for any inconvenience - I believe the above is correct now.

...R

With the exception of the chip enable pins you wire all the pins from both readers to the SPI pins. You then put one chip enable pin low and go through the sequence of reading the interface. Then you place it high and put the other one low and repeat.

If you are using a 5V Arduino system you need to cut these down to 3V3 with a potential divider. You do not need to do this for the single signal going from the reader back to the Arduino.

I made a three RFID unit for a Raspberry Pi where I used a data selector chip to route the chip select line to the appropriate reader. The full article is in the free to download MagPi No 47

Obviously only one SPI device should have its CS line high at any one time.

I think these devices have ~CE, pronounced not chip enable, which means they are active low.

fig 1.pdf (24.6 KB)

Grumpy_Mike:
I think these devices have ~CE, pronounced not chip enable, which means they are active low.

Agreed - I have corrected my error in Reply #1.

The nRF24 can tolerate 5v on its input pins but it needs 3.3v on its Vcc pin.

...R