Monday, September 3, 2012

avr nRF24L01 library running on atmega - v.02

This is my Nordic Semiconductor nRF24L01 driver for atmega8 micro, it should work even with other atmel micro with small changes.
Most of the works is based upon nRF24L01 avr lib by Stefan Engelke http://www.tinkerer.eu/AVRLib/nRF24L01 and arduino lib by 2011 J. Coliz http://github.com/maniacbug/RF24.



This library is more stable than the previos one, which you can also find in this blog. There are some bugfix I've corrected in the source code, and the developer board schematics, added 3 diode to drop down power voltage on nRF24L01 and a capacitor to stabilize it.

Testing done with Eclipse, avrgcc on atmega8 @ 1Mhz.



Code


Notes
  • read risk disclaimer
  • excuse my bad english

117 comments:

  1. Hey Davide,

    awesome work. I just recently tried to use this on a couple of atmega328p chips. I'm using Atmel Studio 6, and the code compiles fine.

    I got the chips into RX and TX mode (one flash, and two flashes) and then nothing else. It seems that as soon as any sort of information is printed to the UART the program stops.

    I even compiled the UART test code from Peter Fleury's web site and got it working to make sure that it wasn't a problem with the code. I'm at a bit of a loss now, is there anything specific you think I would have to change to get this working with the atmega328p?

    Thanks very much

    ReplyDelete
    Replies
    1. I am new to Atmel studio. Can't make anything other than .ino files burn to my board. these won't. they say they won't connect. Can you please introduce me a bit to this new environment?
      thanks!

      Delete
    2. As far as i Know, the best resource you can find for startup using Atmel Studio is here: http://www.avr-tutorials.com/avr-studio-6/avr-studio-6
      This project it is developed with Eclipse + Eclips AVR plugin + avrgcc as compiler. You could google for this toolchain and get all the infromation you need.

      Delete
  2. hello,

    a couple of things i suggest you:
    * to check chip and wiring, use the nrf24l01 arduino library to test all is working, usually the arduino libs are working on atmega328p, you can also select same addresses and channell to mix arduino and my code (maybe you can run arduino on tx and atmel studio compiled code on rx, or viceversa)
    * if you have a logic analizer check the spi bus
    * if you do not have a logic analizer write some uart checkpoint to know where the source block
    * disabling NRF24L01_ACK the trasmitter should trasmit continuously, and the led should blink

    hope this helps you

    ReplyDelete
    Replies
    1. Hi Davide

      I want to exactly what you suggested here, AKA mix arduino on one end (ie transmitter) and code written in atmel studio on the other end.

      the problem is that the arduino libraries use a string as the address but in your code you have defined an array.

      how can I make these two compatible? what should I change in your code or in the Arduino library?

      Delete
    2. Hello, this ic communicate via pipe address, the 5 byte address you should also find in the Arduino library you are using. Try to set it up using checking that pipe address matches.

      Delete
    3. In the Arduino side I'm using mirf library and it works fine. I changed the address and the channel. But still can't comunicate to the module that runs your code.

      Delete
    4. I take a look at the mirf library, notice that the setRADDR and setTADDR name has 5 bytes "clie1" and "serv1" in the library ping_server and ping_client examples, those are the pipe addresses. Convert the string to hex and you will get the pipe address written to the nRF24L01 registers.

      Delete
  3. Hi Davide - thanks so much for the very quick response!

    Actually, replacing the included UART library with the one from Peter Fleury's web site seemed to do the trick. There must have been some atmega328p related bug that was preventing things from working.

    Ciao e grazie mille from Canada ;)

    ReplyDelete
  4. Hello Davide! I have made two boards with Atmega8 and nrf24l01 by your schematics, and i also compile your sopurcw files in AVR Studio + Winavr. In 1Mhz of CPU frequency everything works fine. And then i've tried to run chip in 4Mhz internal oscilator conection works, but at reciever UART debug output strange message appeared "getting data, on pipe 7" and with packet data "ppppppppp". Then i tried in 8MHz internal oscilator and 7.3728Mhz quarz resonator at this frequency was no conection at all, i even had changed SPI prescaler to F_CPU/128 but nothing changed. How do you thin where the problem is???

    ReplyDelete
    Replies
    1. I've try now changing freq to internal 8Mhz oscillator on my dev boards (with Atmega8 Low Fuse = E4), all works with no issues, without changing SPI. Compiled with Eclipse + WinAVR-20100110.
      Is is possible that if you are using AVR Studio you have to set F_CPU in code (#define F_CPU 8000000UL)

      Delete
    2. Hello again. Well i have stopped at 4Mhz quartz resonator and add a plug for 7 pipe, to stop recieving incorrect data. Seems like it mostly works fine. I have already run a range test and have conection at 85 meters outside in strait vision. I have ordered two more NRF24L01 and i will try to create network of them. Also i wrote an article in russian resource with my boards and video of how they work.
      Here it is :
      http://we.easyelectronics.ru/AVR/byudzhetnaya-radiosvyaz-dlya-mikrokontrollerov-avr.html
      I think it will be interesting for you.

      Delete
    3. good job! and thank you for linking my blog article.

      Delete
    4. Hello Mr. David.
      There are a few questions you as a source of experimental results.
      1. Internal Clock Speed ​​Max 4Mhz. 8Mhz is Not done.
      (SPR1 = 1, SPR0 = 1, SPI2X = 0) //clock/128

      Communications, set different number of transmitting and receiving side of the Channel.
      tx = ch2, rx = ch76, no problem.

      I do not know why.


      Difficult because a lot Clock
      I was able to find the cause of your source.
      Infinite thank you to you.

      Delete
    5. hello,

      spi clock: you should setup your SPI clock according to your micro FCPU, i run test with 1Mhz CLOCK, and (0<<SPR1)|(1<<SPR0), so my SPI clock is 1Mhz/16, read nrf24l01 datashet to know the max SPI freq.

      channel settings depends on operation mode. roughly speaking you have to setup the TX address according to your reciving address. page 41 of nrf24l01 sheet contains a good example to understand how this chip works.

      Delete
  5. wondering the Transmitting and receiving side of the channel assign.
    The current code channel is additionally fixed.

    Different channels to communicate with you at the same time for more than two sets of different
    Seem to need a way to assign.

    Do you have any ideas to solve this problem for you?

    ReplyDelete
  6. Hello I have used your code I wrote about above it works fine. Now I would like to add interrupt processing function nrf24l01 I wrote the appropriate bits in the CONFIG register but IRQ signal from the module does not come (I checked the oscilloscope), you may have encountered the same problem and can help me with advice. Here's a link to my code:https://github.com/diygoodies/NRF24L01_ATMEGA8.

    ReplyDelete
    Replies
    1. hello, it's been a while that i do not look at the datasheet for this ic, so i may be wrong.
      read 8.5 chapter,and 9.1 table from datasheet.
      try setting to 0 MASK_RX_DR, MASK_TX_DS and MASK_MAX_RT.

      looking at your code, it seems you set those to 1, instead of 0

      nrf24l01_writeregister(NRF24L01_REG_CONFIG, nrf24l01_readregister(NRF24L01_REG_CONFIG) | (1<<NRF24L01_REG_RX_DR) | (1<<NRF24L01_REG_TX_DS) | (1<<NRF24L01_REG_MAX_RT));

      Delete
    2. Thank you very much this was a problem. I need to print documentation and read carefully.

      Delete
  7. Hello Davide,

    I use the same setup as you do. 2 atmega328P running @ 1MHz.

    on start up the LEDs blink as they should, than the usart spits out this:

    starting as rx...
    info
    STATUS: 0E
    CONFIG: 08
    RF_CH: 02
    RF_SETUP: 0F
    EN_AA: 3F
    EN_RXADDR: 03
    OBSERVE_TX: 00

    AND

    starting as tx...
    info
    STATUS: 0E
    CONFIG: 08
    RF_CH: 02
    RF_SETUP: 0F
    EN_AA: 3F
    EN_RXADDR: 03
    OBSERVE_TX: 00

    sending data, on pipe 0...

    after that nothing happens.
    what could be the cause of this problem? I checked my wiring an my chip should be working fine.

    ReplyDelete
    Replies
    1. if you have got a logic analyzer, check the data sent to and from the nrf24l01, if not, try debug using uart output in the library functions.
      try different hardware if you have
      try using other libraries, arduino code for example.
      try using arduino as tx and this as rx, or viceversa.

      Delete
    2. I don't have a logic analyzer or arduino. I tried to debug with the uart. It seems that i get stuck in the loop where the function "nrf24l01_write()" polls the MAX_RT and TX_DS bits in the status register. When i read the status register in this loop it outputs 0000 1110. With my scope i can see that the payload and bufferout data are correctly outputted on the mosi.

      uint8_t nrf24l01_write(uint8_t *data) {
      uint8_t i = 0;
      uint8_t ret = 0;

      //set tx mode
      nrf24l01_setTX();

      //write data
      nrf24l01_CSNlo; //low CSN
      spi_writereadbyte(NRF24L01_CMD_W_TX_PAYLOAD);
      for (i=0; i<NRF24L01_PAYLOAD; i++)
      spi_writereadbyte(data[i]);
      nrf24l01_CSNhi; //high CSN

      //start transmission
      nrf24l01_CEhi; //high CE
      _delay_us(15);
      nrf24l01_CElo; //low CE

      //stop if max_retries reached or send is ok
      do {
      _delay_us(10);
      }
      while( !(nrf24l01_getstatus() & (1<<NRF24L01_REG_MAX_RT | 1<<NRF24L01_REG_TX_DS)) );

      if(nrf24l01_getstatus() & 1<<NRF24L01_REG_TX_DS)
      ret = 1;

      //reset PLOS_CNT
      nrf24l01_writeregister(NRF24L01_REG_RF_CH, NRF24L01_CH);

      //power down
      nrf24l01_writeregister(NRF24L01_REG_CONFIG, nrf24l01_readregister(NRF24L01_REG_CONFIG) & ~(1<<NRF24L01_REG_PWR_UP));

      //set rx mode
      nrf24l01_setRX();

      return ret;
      }

      Delete
    3. johan De Neef, I am also stuck in the while loop that polls MAX_RT and TX_DS. Did you ever find a solution?

      Delete
    4. For anyone else stuck here...I realized that my compile optimization (O1) in Atmel Sutdio didn't seem to like how it was coded. I created a temporary unit8_t variable to stored the status of if the max retried was reached or if the send was ok.

      uint8_t temp = (nrf24l01_getstatus() & (1<<NRF24L01_REG_MAX_RT | 1<<NRF24L01_REG_TX_DS)

      This allowed me to keep the compiler optimization of O1 on.

      Delete
  8. Can this be caused due to the fact that i am using a atmega328 chip instead of a atmega8? they have the same pinout so it should work.
    Also: i had some problems with the included uart library becouse it was outdated. You might want to update it to peter fleury's 2012 version. That one works perfect.

    ReplyDelete
    Replies
    1. the incuded uart does not work with 328, i had probem with this too.
      just update with the new one provided by peter fleury.
      my library shoud work with atmega328 too without any changes.

      Delete
  9. Hello Davide. It is possible to use the code in bi direction mode? On this week I have solder your schematic and try to remove "txrxrole from wail() cycle".
    After it work very unstable, receive is ok but transmission bad. I can receive transmitted signal. Only sometimes.
    Where is problem?

    Also I will check tx pulses on ant on original firmware. Every second transaction does not get confirmation (ACK) from PRX side!!!
    If you will connet oscilloscope you will see: after key pres: 2 pilses 8 pulses 2.. 8..
    Why does work so?

    ReplyDelete
    Replies
    1. hello, unluckly It's a few time that i does not read use the nrf24l01 ic, so check what i'm telling you, cause i do not remember all the things around this ic.
      It could be possible to run in in bi-direction, just implement this function (change setup registers at the init stage) as proposed in the nrf24l01 datasheet.
      I do not understaind what did you remove, the wail() cycle?
      For the ACK, check that the 0x01 register at the init stage (NRF24L01_ACK). Also check you are using correct TX/RX proper pipe addresses.

      Delete
    2. Thank you Davide, for your answer. Problems solved.
      The radio modules from China, work with bugs because very low power capacitors. When the nrf24l01 modul start TX the power drop. Also I forgot use different addresses for each device. I don't remove wail(), I remove only "if(txrole)".
      Now work correctly :) Bi-direction also fine. I happy) Thank you again.

      Delete
  10. Hello dear Davide.

    I would like to use your code in my project.
    I have a device for sending data which is used mega16 in that and a device for receiving data is xmega128A1.
    I tried to convert your code and it seems perfect but it is not working.
    In sender device I get this in usart :

    starting as tx...
    info
    STATUS: FF
    CONFIG: 00
    RF_CH: 00
    RF_SETUP: 00
    EN_AA: 00
    EN_RXADDR: FF
    OBSERVE_TX: 00
    sending data, on pipe 0... ok
    sending data, on pipe 1... ok
    .....
    //***********************
    And in a receiver device I get this:
    starting as Rx...
    info
    STATUS: 0F
    CONFIG: 0E
    RF_CH: 0E
    RF_SETUP: 0E
    EN_AA: 0E
    EN_RXADDR: 0E
    OBSERVE_TX: 0E

    I attach my codes to this email, would you please guide me where is my mistake?!

    http://www.mediafire.com/download/l4lr0yobqsbpsrk/AvrAPP.rar

    ReplyDelete
    Replies
    1. hello,
      check my suggestion above, and in the mail you send me.

      Delete
  11. Hi Davide,

    I'm trying to include your code into my domotica project for my house, sadly I'm experiencing that the code is not working.

    The problem is that it's giving me failes on sending data all the time.

    For my setup I'm using a Atmega328P and I allready updated the uart library to the latest one from the website of Peter Fleury. The 328P is running at 8Mhz and my power supply is fine, I already included an extra 10uF cap.

    Here are a few screenshots of my logic analyser and terminal; (ignore the last 3 channels)
    https://www.dropbox.com/s/hsbxm5xzto1ruem/screenshot.png
    https://www.dropbox.com/s/y0oppsc4jtulnkd/screenshot2.png

    Here I used switched CE (to PB1) and CSN (to PB0) to just check if my wiring was off;
    https://www.dropbox.com/s/ii4ostct0zxk530/screenshot3.png

    Could you tell me what I might be doing wrong? In the code I saw your using PB0 as CE and PB1 as CSN (SS) right? Why then is there the PB2 (SS) defined in the SPI library?

    Thank you!
    Jjshortcut

    ReplyDelete
    Replies
    1. hello, unluckly It's a few time that i does not use and read datasheet for the the nrf24l01 ic, so i do not remember the protocol, but if you read datasheet you can see if what your logic analyzer get is the right.
      PB2 is defined but not used.
      yes, PB0 as CE and PB1 as CSN (SS) right.
      check you have setup the correct way TX and RX address, it could be that you have no ack from RX.
      try different hardware if you have
      try using other libraries, arduino code for example.
      try using arduino as tx and this as rx, or viceversa.

      Delete
    2. Hi, Yesterday I tried a little bit more, maybe this weekend I do have more time but what do you mean by the correct TX and RX adresses? These are defined in the .h file, so these should be OK right?

      Delete
    3. yes, default should work.
      set one device as TX, other as RX.
      for more info: look at datasheet fig. "Example of a datapipe addressing in Multiceiver"

      Delete
  12. Hi Davide!
    Correct me if I'm wrong, I should make 2 identical PCB's and flash the same hex on both Atmega8's (avr_sample_nrf24l01.hex you released)? No need to define which one is TX and which one is RX before compiling, and no PCB change for both?
    Thanks

    ReplyDelete
    Replies
    1. Correct, one pcb has to be a pin header close, one not. The pin header switch define the board TX/RX status.

      Delete
    2. I connected things on protoboard according to you schematic, and flashed provided hex. On one chip i shorted the role header.

      After initial blinks (first on RX, second on TX), i got 1s blink loops on TX, and nothing on RX. Also, I got no response from pressing button. Is that supposed to be on sample hex?

      Since this is not the first schematic and code which doesn't work for me, is it possible that my RF modules are burnt or broken, although SPI is working?

      Delete
    3. There are many errors that can occours. Wiring / hardware / software, compilation... Check my "October 23, 2012 at 9:43 AM" Suggestion up here.

      Delete
  13. it gives conflicting type spi_writereadbyte error

    ReplyDelete
    Replies
    1. I suppose you mean at compile time. I do not encounter this error, compiling with avrgcc. Check that all the libraries (the spi one), are in the correct path.

      Delete
  14. David,

    I am trying to implement a pair of encoder/decoder to this set up you have but i am having difficulty, it seemed to work partially. Have you tried something like this before. Your help would be appreciated.

    ReplyDelete
  15. This is what i am thinking Davide, The encoder operates at 9600bps I am connecting this to the USART Rx port of the mega88 for transmission over the NRF and then on the receiving end I am connecting decoder to the USART Tx port for receiving. I am thinking that this should work. Any ideas on how this could work?

    ReplyDelete
    Replies
    1. You could try, it should not be so hard to build, but you need two good nRF24L01 modules, cheaper modules sometimes fails on TX/RX and a microcontroller for every encoder. For a precise trasmission do ACK and implemenets some sort of CRC. Alternatives could be 315 or 433 Mhz modules, they already works over uart, any speed, again cheaper modules i've tryed have poor transimission quality, so you have to implement your code check. Bluetooth uart module is the already tested and running solutions. There are a few Zigbee UART modules that can do that works, and zigbee is really a good choice, if you can not find UART modules you again need a microcontroller for each encoder.

      Delete
  16. Thanks Davide, will do some experiment to see how i can get this to work.

    ReplyDelete
  17. Ciao Davide, hai qualche suggerimento dove dovrei mettere le mani per convertire questa libreria scritta per un ATMEGA8 a un SAMD21 ovvero Cortex-M0+?

    ReplyDelete
    Replies
    1. Ciao, di base, la libreria SPI, quella UART se devi fare il debug, e tutte le chiamate a modifiche di stato alle porte, in dipendenza di cosa usi per la scrittura.

      Delete
    2. Ok grazie ci sto lavorando adesso non sembra difficile e' tutto molto chiaro e organizzato bene! Complimenti e grazie!

      Delete
    3. Ciao. Sei stati in grado di utilizzare questa libreria RF24 o RF24Network con un SAMD21? Io sto utilizzando un Adafruit Feather M0 con un NRF24L01+.

      Delete
    4. Ciao, purtroppo non ho mai provato l'utilizzo su SAMD21.

      Delete
  18. This comment has been removed by the author.

    ReplyDelete
  19. hi,i want to use nrf24L01+ in proteus but i cann't find it's library
    would you help me?
    what can i do?
    please say eay way to access this file
    thanks

    ReplyDelete
    Replies
    1. Hello, i'm sorry but I've never use proteus, so i can not help you that way.

      Delete
  20. Hello Davide, Thak you for this library. I have implemented your code in 1 of my projects, and it works perfect with a 1MHz clock on a atmega8 and atmega328p. But with a 16Mhz clock the TX mode is not working. (And yes i did change (FCPU to 16MHz in the source file) Do you have any idea what could be causing this problem?

    ReplyDelete
    Replies
    1. Hello, supposing you have also the fuse of your atmega to 16Mhz, look at the SPI Clock Rate, and Double SPI Speed Bit, try to change that one. Also a logic analizer could help to understand what is not working on the TX communication.

      Delete
  21. Hello,

    I want to do this today, i have everything soldered, but I am missing the 1uF capacitor to stabilize the nrf.... i also have 1N4007 (not 4004) diodes. Would these changes be a problem?

    Thanks!

    ReplyDelete
    Replies
    1. Hello. 1n4004 will work. Diodes are there to the drop down voltage for the nRF24L01 that needs 3.3V. Anyway most of the time nRF24L01 boards even accept 5V, check your board specifications. You can use other caps to stabilize voltage, any above 1uF will work.

      Delete
  22. what must i do with my download file from this page.,? i use atmel studio, can give me some help

    ReplyDelete
    Replies
    1. Hello, I've never test it with Atmel studio, because i use Eclipse with the AVR plugin, and i complie it with avrgcc. Anyway, to use it on Atmel Studio, create a new project, and add all the files here. Then compile one hex for sender (#define ROLETX 1, #define ROLERX 0) - and one as receiver (#define ROLETX 0, #define ROLERX 1), and upload to your micro. You have to set the righe include and path for you ATmel Studio complier.

      Delete
    2. very thanks for your answer. i already done with the program in atmel studio and i already test it in atmega8., but i dont understand with "the program" because i'm very amateur in this., can you help to know about the program and maybe help me to in send string., please mail me in adianfajar@gmail.com or maheda.ardiansyah@yahoo.com

      Delete
    3. Hello, unluckly i've no manual for this. All i have is that code, you can send a string just using the nrf24l01_write and nrf24l01_read functions. But if you are starting writing for microcontroller, maybe it's better start with something simpler, or start with some Arduino. For Arduino there are well written libraries for this IC.

      Delete
    4. oh, thanks very much i will try as i can., one more question., for set transmiter and receiver just change "#define ROLETX 0
      #define ROLERX 1" or i must change other thing., and can i set it so the atmega can send and receive data or be transceiver.,?

      Delete
    5. Sorry my mistake. It's a few i do not see this code.
      You can compile this code as it is, to set one as receiver an one as trasmetter is set the variable txrxrole, reading the status of the PIN of the ROLE. (BUTTONROLE_PIN & (1<<BUTTONROLE)). Or, if you would like to edit this code, just set one txrxrole for reciver and one for transmitter.

      Delete
    6. are that mean i don't need to change "#define ROLETX 1
      #define ROLERX 0" just change pinc 1 to set it to be an transmitter or receiver and data in pinc 0? by the way, i use you "main.c" program on "src" program.

      Delete
    7. Yes nothing to change. The Rx Tx role is selected by shorting or not PC0 to VCC, like you see in the schematics 2PIN switch.

      Delete
    8. oh, thanks very much., i hope i can make it be transmitter. so in this program the input data is in PC1? data is just 1 and 0 or what?

      Delete
    9. PC1 is just a trigger that causes the transmit to send data.
      That's that trigger check code "if ((BUTTONSEND_PIN & (1<<BUTTONSEND)) != 0) {..."

      Delete
    10. so where is the data? what must i do if i want send some data ?

      Delete
    11. Take a look at the nrf24l01_write and nrf24l01_read functions.

      Delete
    12. okey, my mistake. i didn't read it first., thanks so much for your big help.

      Delete
    13. can i get your email or something, so i can ask again if i get some trouble.,

      Delete
    14. if i want to sent some data, i must give 1 in pc1 or it will automatic sent.,?

      Delete
    15. You just can use nrf24l01_write on the transmitter and nrf24l01_read on the receiver. The you have to add to trigger the transmission of data with something like a switch or a timer. As i tell you, if this is one of your first project, it's maybe better to switch to Arduino, which is fairly simple than plain c code.

      Delete
  23. Hello ,

    I want to do related project . In my project there will be one receiver and more than one transmitter (25-35) . So i want all transmitter have an id and . when i push the one of button on transmitter . transmitter will send pushed button and his id. Ä° m not sure what happens if there is 30 transmitter. it can be handle with this module? please give your advice
    Thank you for nice tutorial

    ReplyDelete
    Replies
    1. Hello, Not the native way, take a look at datasheet, capter 7.7 Multiceiver. For 30 you could implment you how protocol.

      Delete
  24. Hello Davide. Great work on the library! I am trying this out on a Atmega8. I have quintuple checked my pin connections. I am trying to just read a register from the NRF24L01 to see if my SPI is working correctly, but everytime I read any register, the value of SPDR is always 0xFF. I am at a loss to get my the NRF24L01 working. Also, does your library assume that the NRF24L01 will be a receiver? It appears that way based off of the nrf24l01_init() function. Thank you!

    ReplyDelete
    Replies
    1. Hello, it could be something in the SPI line, some timing related to F_CPU and fuse settings problem, or it also could be your hardware. Check your SPI line with a scope or a logic analyzer. Check your nRF24L01 board with another library and/or hardware. The board is in RX mode by default, but everytime you call nrf24l01_write the IC it is set to TX, and then again to RX.

      Delete
    2. I will have to acquire a logic analyzer to verify the SPI line. I did a loopback test of connecting MOSI to MISO and that appeared to work correctly. I have the fuse SUT_CKSEL set to INTRCOSC_1MHZ_6CK_0MS and F_CPU defined to F_CPU=1000000UL. I don't have any capacitors or miscellaneous electronic components connected. I have a dedicated 3.3V supply for the NRF24L01 and an STK500 running the Atmega8 at 5V.

      Delete
    3. I think you should have a commong ground between the two power source. Also better, try getting the 3.3V out of the 5V using a regulator to avoid ground noise.

      Delete
    4. I created a common ground between the two supplies since I don't have any voltage regulators on hand. It seems that I am able to read the register successfully now! Thank you so much for the help. It's been a while since I have done anything with electronics. :)

      Delete
    5. Thank you! The only problem I face now is getting the transmission of data from one NRF24L01 to the other NRF24L01. I have researched and it seems that a common solution is to add a 10 microfared capacitor across the power and ground of the NRF24L01's.

      Delete
  25. Hi Davide!

    I want to make few changes in the code that you've written. I want to write two separate codes for transmitting and receiving side.
    The doubt I have is about the following part. Do we need to write something similar to this on the receiving side as well?
    "
    if(sendpipe == 0) {
    //set tx address for pipe 0
    nrf24l01_settxaddr(addrtx0);
    } else if(sendpipe == 1) {
    //set tx address for pipe 1
    nrf24l01_settxaddr(addrtx1);
    } else if(sendpipe == 2) {
    //set tx address for pipe 2
    nrf24l01_settxaddr(addrtx2);
    } else if(sendpipe == 3) {
    //set tx address for pipe 3
    nrf24l01_settxaddr(addrtx3);
    } else if(sendpipe == 4) {
    //set tx address for pipe 4
    nrf24l01_settxaddr(addrtx4);
    } else if(sendpipe == 5) {
    //set tx address for pipe 5
    nrf24l01_settxaddr(addrtx5);
    }

    "

    ReplyDelete
    Replies
    1. Hello, Al the code section inside the "if(txrxrole == ROLETX) {" is for the transmitter, so the code you are reporting here can be skipped on tx side.

      Delete
    2. Hello, txrxrole == ROLETX stands for transmission side.

      Delete
    3. Do we need to use IRQ pin of the nRF module if we're not using interrupts? What should be it's default state?
      What is SS? Slave select, right? If it is not being used, then why has it been initialized?

      Delete
    4. "so the code you are reporting here can be skipped on tx side.", it should be skipped on the receiver side, right?

      Delete
    5. Yes sorre, should be skipped on the rx side. If you take a look at the nRF24L01 datasheet you can find all there, SS, IRQ and so on.

      Delete
  26. Hi. I would like to create a RF network with 6 nRF24L01+ working with a SAMD21 processor (Adafruit Feather M0 Basic Proto). I tried to use the library but this error occurs:

    "In file included from C:\Users\Alejo\Documents\Arduino\libraries\RF24\RF24.cpp:9:0:

    C:\Users\Alejo\Documents\Arduino\libraries\RF24\nRF24L01.h:27:21: error: expected unqualified-id before numeric constant

    #define CONFIG 0x00

    ^

    C:\Users\Alejo\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel/Device/ATMEL/samd21/include/component/eic.h:705:34: note: in expansion of macro 'CONFIG'

    __IO EIC_CONFIG_Type CONFIG[3]; /**< \brief Offset: 0x18 (R/W 32) Configuration n */

    ^

    C:\Users\Alejo\Documents\Arduino\libraries\RF24\nRF24L01.h:27:21: error: expected unqualified-id before numeric constant

    #define CONFIG 0x00

    ^

    C:\Users\Alejo\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel/Device/ATMEL/samd21/include/component/wdt.h:290:34: note: in expansion of macro 'CONFIG'

    __IO WDT_CONFIG_Type CONFIG; /**< \brief Offset: 0x1 (R/W 8) Configuration */

    ^

    exit status 1
    Compilation Error"

    Do you know how can I solve this problem?

    Thank you very much.

    ReplyDelete
    Replies
    1. Hello, I'm sorry but I've never tested it on SAMD21. This project is for 8-bit micro. Tested on avrgcc compiler.

      Delete
  27. What are the BUTTONROLE and BUTTONSEND for? What are they connected to?

    ReplyDelete
    Replies
    1. Hello, BUTTONROLE is to select the TX or RX role of the sample board. BUTTONSEND is to send sample data from TX to RX board.

      Delete
  28. Thx, I've uploaded the code using Atmel studio 6.2 though to my arduino uno (atmega328), im not getting any response back though using the Serial Monitor, any advice?

    ReplyDelete
    Replies
    1. Hello, this project has been tested on ATmega8 @ 1Mhz, compiled with avrgcc. I've not tested it on ATmega328 @ 16Mhz, compiled with Atmel studio compiler, you have to debug it. You can use a simple logic analizer to check the i2c bus, or, if you do not have one, you can debug using UART output, and check where and if the code stucks, and what are the registers values.

      Delete
  29. hi davide...
    i was trying to interface nrf24L01 with atmega16 running on internal oscillator of 1Mhz. i'm simply reading a status register in while loop but....sometimes i got 0x0e value from status register and sometime nothing....also ...i'm not able to read status register in loop ...why?? please help!!

    ReplyDelete
    Replies
    1. Hello, there may be a few factor involved. Have you checked with other board. Also, keen in mind that the content of that register is always to be read after an high to log CNS transition.

      Delete
  30. hi to mr davide gironi
    i am hamid
    i have a problem with Nrf2401 modoule and brushless motor.
    when i connect a brushless motor to nrf24l01 moudole my brushless motor dont work/
    i try to connect 2 servo and 1 brushless motor to my rc plane by codevision and mega32.
    please help me my frind
    your frind from iran
    thank you

    ReplyDelete
    Replies
    1. Hello, at first check if it works without your motor attached, just send some data and check it. You can use the serial port as a simple debug method.

      Delete
  31. Hi Davide;

    Thank you for your useful code. It works very well.

    Just one question. in the spi.h, the SS pin if defined as PB2 but in the schematic the CSN pin of the nRF module is connected to the PB1 and is working OK.

    how can I free the PB1 pin(because I need this pin for another purpose) and use, for example, the PB6?

    ReplyDelete
    Replies
    1. Hello and thank you for this feedback. It may be unclear I've notice. PB1 is connected to nRF24L01 CSN pin. SS it's not used and not connected. You can just change the PB1 definition in nrf24l01.h NRF24L01_CSN to PB6, it should work.

      Delete
    2. Thank you. I just changed the PB1 to PB6.

      Delete
  32. Hey bro ,
    All Works Great but the only problem nrf24l01_write(bufferout)
    returns 0 even when it send the packet correctly
    thanks anyway :)

    ReplyDelete
    Replies
    1. Hello, thank you! It's a few that I do not take a look at this code, anyway I've connected it right now, it returns 1 to me. Check the nrf24l01_getstatus return. Add caps to the power line, or use clean power, sometimes it's power line noise that make communications dirty.

      Delete
  33. hey davide,
    thanks for the source code, but i have problem.
    how can i transfer data using 2 transmitter to 1 receiver ?

    ReplyDelete
    Replies
    1. Hello, you can use the multiceiver mode (take a look at "7.7 Multiceiver" paragraph of the nrf24l01 datasheet). In the main sample you can see that tx can use different pipe.

      Delete
  34. Hi Davide,
    I've noticed you attached the IRQ pin of the nrf24l01 to the pin PD2, and I believe that is the interrupt of the module, but you did not activated the INT0 interrupt vector on the microcontroller, did you (since it's nowhere to be found on the attached code)?
    Thanks for sharing!

    ReplyDelete
  35. Hello, this project is pretty old so i may be wrong, if i remember well the interrupt was attached just for completeness board purpose, indeed it is not used and is there just for future use.

    ReplyDelete
    Replies
    1. Hello Davide,

      It works really well! Just wanted to share that I found out that IRQ pin does change it state, all left to do is activate an interrupt on the micro-controller.

      Thanks again for sharing your work!

      Delete
    2. Hello, and thank you for sharing your results here!

      Delete
  36. Hi David,,
    can you show me the power supply you are using?
    I have a problem with power supply
    thank you

    ReplyDelete
  37. Awesome project sir, thank you for your hardwork. Now I'll try as you did

    ReplyDelete