Atmega328 pins D0 and D1 for ce and csn with nrf24l01

Is it possible to use D0 and D1 as the CE and CSN for connecting the 328 to the nrf24l01? It seems the answer should be yes, but for some reason I cannot get these pins to work for this although they are working fine for other uses. I've only had success using them as inputs, so perhaps using them as outputs requires an extra step. I'm starting with a blank 328 chip with no bootloader.

Why would one use the only hardware serial pins for that purpose?
Especially when it does not seem to work as expected?

What sketch was used to show/test the claim?

I've used up all of the other pins, including the analog ones for various sensors. I could swap the ce and csn connections over to other digital pins and bring those connections to D0 and D1 but it's not preferred if I can make it work this way.

The code for testing:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(0, 1); // CE, CSN
const byte address[6] = "00001";
boolean button_state = 0;

void setup() {
pinMode(6, OUTPUT);

radio.openReadingPipe(0, address);  
void loop()
if (radio.available())              
{, sizeof(button_state));   
if(button_state == HIGH)
digitalWrite(6, HIGH);

digitalWrite(6, LOW);


The code should be in code tags, and a little formatting would make it more readable.

Does CSN work?

Try running radio.printDetails(); in setup,
you will have to call printf_begin(); before and #include <printf.h>.

The above sketch only receives, so how do you know it does not work?

Both CE and CSN have to work in order to receive the data, so I don't know if just CSN works (not sure how I would test that).

When I switch the CE, CSN numbers to 2,3 then the test LED works. It's just the basic transmit code for the nrf24l01 connected to a nano as the transmitter.

Where would the output of printf be found? I'm not familiar with that one.

If I had to debug this, I would start with only the radio connected and not using pins D0 and D1. Once that works, move CE and CSN to D0 and D1 and see if it works.

Once you have the radio working on D0 and D1, you can incorporate the rest of your sketch.

You don't say which 328P you're using; DIL or QFP? The QFP has two additional (analog) inputs so if you're not already using that, it might be an option. Most Unos use the DIL, the Nano and ProMini use the QFP.

Please edit post #3, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.