Connecting nRf24L01 to Atmega328PU with external 8Mhz Crystal problem

Hi,
I am trying to fix the problem of communicating two nRf24l01+ together, one connected to Arduino Uno and another connected to Atmega328PU with 8Mhz external crystal. The bootloader on Atmega328PU is “Arduino Pro or Pro Mini” 3.3V 8Mhz. The problem is the nRf24L01+ on Atmega328PU is not responding (working). I am using RF24 library as shown in the code below. There are several things that I already tried:
1- To make sure that both nRf24L01+ modules work, I connected one to Arduino Uno and another to Arduino Mega and they work perfectly. So, the problem is not from the nRf modules.
2- I changed the external crystal of atmega328PU to 16 Mhz and changed the bootloader to Arduino Uno. Didn’t work again.
The circuit diagram is shown below:

The Transmitter Code:


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

RF24 radio(7, 8); // CE, CSN

const byte address[6] = "00001";
const int btn = 4;
int buttonState = 0;
int programState = 0;

void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
  pinMode(btn, INPUT);
}

void loop() {
  buttonState = digitalRead(btn);
    // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
    if ((buttonState == LOW) && (programState == 0)) {
          programState = 1;
    } 

    else if((buttonState == HIGH)&& (programState == 1)){
        const char text[] ="Hello World"; // you can customize this text to your wish
        radio.write(&text, sizeof(text));
        programState = 0;
        Serial.println("BUTTON");

        delay(1000);
  }

}

The Receiver Code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
const int output = 2;

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
  pinMode(output,OUTPUT);
  digitalWrite(output, LOW);
  delay(1000);
}

void loop() {
  if (radio.available()) {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.println(text);
    if (strcmp(text,"Hello World")==0){
    
        Serial.println("CORRECT");
        digitalWrite(output, HIGH);
        delay(2000);
        digitalWrite(output, LOW);
        delay(2000);
    }  
  }
}

I moved your topic to an appropriate forum category @john1n.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

how is breadboard setup powered?

I forgot to put source pins. I just edited the image

Atmega328 have not power?

I put a note on image. it is connected to external 3.3V source

well. seems right side is ok.
left: button is wrong connected

I tried the same connection for Arduino UNO to send data to Arduino Mega using two nrf modules and it worked well. So, I don't think the problem caused by wiring of button.

and not from sketch

After some searching, I found that some people mentioned that changing board_build.f_cpu, MY_BAUD_RATE, or SPI.setClockDivider solved their problem. I tried last one and change it form 16MHZ to 8MHZ as:

  SPI.setClockDivider(SPI_CLOCK_DIV2);//Run the data in at 16MHz/2 - 8MHz

But didn't work for me.

did you check if bare chip working in this setup?

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