Main Site Documentation

Nordic NRF24L01+ between NETMF and ARDUINO


#1

Hi,
I have a G120HDR and an Arduino Pro Mini, with two Nordic NRF24L01 spi modules.
I mounted a module for each MCU, on NETMF using Gralin library, and on Arduino using RF24 (full) library.

I’m trying to make a simple send/receive (unidirectional) communication between the two boards. (NETMF is receiving, arduino is transimitting)

I succeded (I hope) in connecting hardware, since getting infos from the NRF24L01 board, it replies with correct data. So I expect SPI is working on both boards.

If I connect two boards on the G120 and i try to send and receive, it works, so the code in netmf should be good.

I cannot try the same thing on arduino since the pro mini ha s only one spi port, but I’m using the GettingStarted sample, so I think is correct.

SHould there be a known difference to be considered, or someone has an idea of what can I try?

Here the code on NETMF side:


        static NRF24L01Plus n;

        public static void Main()
        {
            n = new NRF24L01Plus();

            n.OnDataReceived += n_OnDataReceived;
            n.OnTransmitSuccess += n_OnTransmitSuccess;
            n.OnTransmitFailed += n_OnTransmitFailed;

            n.Initialize(SPI.SPI_module.SPI1, Pin.P0_6, Pin.P0_1, Pin.P2_0);


            byte[] address = Encoding.UTF8.GetBytes("NetP1");

            n.Configure(address, 10, NRFDataRate.DR1Mbps);
            n.SetAddress(AddressSlot.Zero, address);
            n.SetAddress(AddressSlot.One, address);
            n.SetAddress(AddressSlot.Two, address);
            n.SetChannel(10);

            n.Enable();

            Thread.Sleep(Timeout.Infinite);

        }




        static void n_OnDataReceived(byte[] data)
        {
            Debug.Print(new string(Encoding.UTF8.GetChars(data)));
        }


and on the Arduino side:




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

RF24 radio(9,10);


void setup(void)
{

  Serial.begin(9600);
  printf_begin();
  printf("\n\rRF24\n\r");

  //
  // Setup and configure rf radio
  //
  radio.begin();

  // optionally, increase the delay between retries & # of retries
  radio.setRetries(15,15);
  radio.setChannel(10);
  // optionally, reduce the payload size.  seems to
  // improve reliability
  //radio.setPayloadSize(8);
  
----tryed with or without
  radio.enableDynamicPayloads();
  radio.setAutoAck(true);
  radio.setCRCLength(RF24_CRC_16);
------

  //
  // Open pipes to other nodes for communication
  //

  // This simple sketch opens two pipes for these two nodes to communicate
  // back and forth.
  // Open 'our' pipe for writing
  // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)


  radio.openWritingPipe((uint64_t)0x4E65745031LL);
  //
  // Dump the configuration of the rf unit for debugging
  //

  radio.printDetails();

}

void loop(void)
{

    // Take the time, and send it.  This will block until complete
    unsigned long time = millis();
    printf("Now sending %lu...",time);
    bool ok = radio.write( &time, sizeof(unsigned long) );
    
    if (ok)
      printf("ok...");
    else
      printf("failed.\n\r");


    // Try again 1s later
    delay(3000);

}


Thanks for help!
J


#2

@ jacoporunchi - I’ve never used these boards, so I can’t help, but more information would help others to do so.

What’s exactly is happening or not happening?

Is the G120 getting any data? Or is it getting data, but just not in the correct format?


#3

Many thanks for the hint…

The event OnDataReceived is never called, so I think nothing is arrived to the NETMF board.
Also the arduino, in the end, writes “failed”.

I’ve read some other posts, and it seems if the arduino sets to false the return of the write function, it is why it has not received the ack from the other board.

I hope someone could suggest me what to try to understand the problem…

Thanks


#4

@ jacoporunchi - Could you provide a simple wiring diagram of how everything is connected?


#5

Sure! I’m a little community-newbie… THere is a (software) convention to draw circuits?


#6

Fritizing is a simple and free to show basic diagrams.

Also you could just take a photo :wink:


#7

Thank you again.
The image is attached. It is not the best wiring diagram, but for the next time i will be using Fritzing…

J


#8

There are some default settings in gralin driver, beside address and channel. You could try to set it “by hand” in RF24. Default data Rate is 2Mbps…

 
// Enable dynamic payload length
            Execute(Commands.W_REGISTER, Registers.FEATURE,
                    new[]
                        {
                            (byte) (1 << Bits.EN_DPL)
                        });

            // Set auto-ack
            Execute(Commands.W_REGISTER, Registers.EN_AA,
                    new[]
                        {
                            (byte) (1 << Bits.ENAA_P0 |
                                    1 << Bits.ENAA_P1)
                        });

            // Set dynamic payload length for pipes
            Execute(Commands.W_REGISTER, Registers.DYNPD,
                    new[]
                        {
                            (byte) (1 << Bits.DPL_P0 |
                                    1 << Bits.DPL_P1)
                        });

  // Set retransmission values
            Execute(Commands.W_REGISTER, Registers.SETUP_RETR,
                    new[]
                        {
                            (byte) (0x0F << Bits.ARD |
                                    0x0F << Bits.ARC)
                        });



#9

Hi, thank you for reply.
I tryed setting 1Mbps data rate on netmf, after realizing rf24 was using 1mbps by default. No results at all.
I will try leaving default on netmf and setting 2mbps on rf24.
Should I use setDynamicPayloads(true)?
setAutoAck(true)?
Should I do something with retransmission values?

I did not understand if channel and address could be set as I have done on NETMF, or if I should adapt rf24 on some gralin’s default also for address and channel…

Thanks


#10

Dynamic payloads should be ok:


 Execute(Commands.W_REGISTER, Registers.DYNPD,
                    new[]
                        {
                            (byte) (1 << Bits.DPL_P0 |
                                    1 << Bits.DPL_P1)
                        });

same goes to the auto ack:


 Execute(Commands.W_REGISTER, Registers.EN_AA,
                    new[]
                        {
                            (byte) (1 << Bits.ENAA_P0 |
                                    1 << Bits.ENAA_P1)
                        });

channel must match on both sides.
For addresses, I think that sould be ok:


byte[] RADDR = { 240, 240, 240, 240 ,225};
m_nRf.Configure(RADDR, 10);

and on arduino


const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
radio.openWritingPipe(pipes[0]); 

#11

There is also excellent register description on this site : http://nrqm.ca/nrf24l01/firmware/


#12

Great for the register doc!
I’m going to try with these settings… Dynamic payloads and autoack ahould be on by default in gralin’s lib, and should be configured only on arduino, or is it necessary to write registers manually also on netmf?


#13

No, are part of default configuration…


#14

Thanks for the hint, but it does not work…
I tryied to reflect Gralin’s config on rf24 enabling dynamicPayload and autoAck, and using address 0xF0F0F0F0E1LL as suggested.
Channel is 10 on both boards, but it continues not triggering datareceived event and writing failed on arduino (sending).

There is something else I can test, or there is somone who succeded in using rf24 between arduino and netmf?

J


#15

Reverse the bytes for the address on the netmf side. The Arduino side is using a 64-bit integer that is sent little end first. The netmf side is using a byte array which is sent big end first.


#16

Hi, thanks for help!

I tried it, but it does not work, it does the same.
It does not work also with an address like F0F0F0F0F0.

I also tried to read all registers on both sides, but they seems the same, for channel, address, auto ack, dynamic payload, crc…

registers values are



ARDUINO-TX	GHI-RX
CONFIG: 		12		7
EN_AA: 		63		3
EN_RXADDR: 		3		3
SETUP_AW:		3		3
SETUP_RETR:		255		255
RF_CH:			10		10
RF_SETUP:		15		15
STATUS:		14		14
OBSERVE_TX:		0		0
RPD			0		0
RX_ADDR_P0:		240		240	
RX_ADDR_P1:		32		194
RX_ADDR_P2:		0		195
RX_ADDR_P3:		0		196
RX_ADDR_P4:		0		197
RX_ADDR_P5:		0		198
TX_ADDR:                     240         231
DYNPD:			0		3
FEATURE:		0		4


Did I forget to look for something in registers?

Thanks


#17

This might be solution:


#18

No luck… It seems not to work anyway…

I’ve no idea what to try…

Thanks again…


#19

I don’t have Arduino at the moment, but, I was able to establish communication between spider and uno. Just with attachments, that I downloaded from this site. Maybe you should recheck your wiring?


#20

Wiring seems to be good… What did you do with irq pin?