nRF24L01 working program for Atmega 328p

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everyone, I am searching for a C program and library for nRF24L01 for a school project. I know there are a lot of examples out there but I am not too expert to understand them, I tried everything but I can't make them work. So I want to ask if anyone has a easy understandable and working program to share with me. 

Thank you :)

Last Edited: Sun. Oct 6, 2019 - 11:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, let's see...

 

Most of the examples are pretty straight forward. What might you be missing?

 

Your NRF modules are almost certainly counterfeit parts that actually contain  SI24R1 chips, which are a compatible chip, and would be fine if they wre not fraudulently labled NRF24L01. These have one bug that might trip you up. If you send the same packet over and over, a real NRF will increment the 3 bit packet id field so the receiver will know this is a fresh packet being sent and not reject it as a retransmit because the ack was lost. The SI chip has a bug here and if you send packets containing the same data over and over, the receiver will spot the first, but not tell your program about the rest. To be sure this isn't happening to you, include a packet count byte that you increment and now the receiver will see all of them.

 

So, first thing is to get SPI working and make sure you can set the CS and CE pins high and low. Like make a tiny program that sets one of them high, then low once a second or so and probe it with an LED or meter so you can see the pin going. This will also tell you if your processor is running the speed you intend.

 

If you put your hardware together, then write a big program and load it, it will certainly not work. Take baby steps. Start with toggling the CS pin and see if you can see the CS pin changing. Then the CE pin. Then write continuous data, like 0xA5 out the SPI. You should see something besides a steady high or low on the SCK and MOSI pins. When you know you have all this, add your library and try something like setting the address and read it back, toggle a pin or something if you read back what you wrote out. Now you know you're talking to the NRF.

 

Now, set both sender and receiver to the same channel, speed and address. Have one send something out, like the status of a button or something, and the other toggle a pin when it receives a message.

 

Build your program small function by small function, and when you've gotten all it little bits working, your project will be done. In my case, I include "cry" as a development step.

 

 

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So I'm trying to write a simple code to enable the chip. I put the CS pin always high and the CE pin high for 10us. Now I have to set the Power up mode, the number of bit of the data, the data rate and the clock (something else?). To set the Power Up mode I need to act on the CONFIG register, but how do I write in it? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You need to raise and lower both pins in operation. Since you can do that, you have first step working. Second is to get SPI working.

 

For want of any good reason, my NRF example is here:  http://barefootelectronics.com/NRF24L01.aspx  All you need to adapt for your processor is the SPI code, but you can google an example for your specific setup, I expect.

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What do I have to change to make the libraries work in my Atmega?