This project has moved and is read-only. For the latest updates, please go here.

Communication between 2 NRF24L01+ on STM32F4

Oct 6, 2014 at 11:06 AM

I've ordered 4 NRF24L01+ from ebay china, to link devices. My current NET Micro Framework device is a STM32F4 running netmf 4.2.

To simplify the development process for upcoming devices a little bit, I decided to connect an arduino mini pro via an USB/RS232 adapter as debug radio modem. Afters hours of reading, wire checking and cursing (It did not work), I decided to go one step back, and connect 2 wireless modules with SPI1 and SPI2 on my STM32F4. So I have similar conditions for each wireless module.

I followed the Sample project and
  1. created
  2. configured
  3. initialized (same address on slot 0)
  4. enabled
one NRF24L01 object for each wireless module. But nothing happened. None of the 4 eventhandlers got executed. The SPI pin configuration comes directly from the official stm32f4 documentation. For IRQ, CS end CE I took PIN A1-A3 for SPI1 and 3 other pins for SPI2. I can read out the addresses, so I think my wiring is correct.

Within the try & error process with the arduino I had 2 situations, where the arduino console told me, that multiple packages got successfully tramsmitted. That was minutes after restarting the arduino console. But I could not reproduce the situation.

The STM32F4 as well as the NRF24L01 are power supplied from a breadboard power connector which supplies 5v for the st and 3.3v for the rf24.

Any suggestions to prevent me from kicking the rf24 modules into trash? Maybe any diagnostic steps? I did not get familiar with all rf24 registers.

Thanks in advance
Oct 6, 2014 at 12:43 PM
Hi Christian,

If you are able to read the addresses from both modules connected to the STM32F4 then it sound like those are connected properly. Could you simplify your code (unless it's already short) and share it here? Since you are able to read from modules but not able to receive sent data, it sounds like there is a problem with the interrupt pin. You could try changing the interrupt pin contructor parameters and see if it helps. You could also add a print line in the internal interrupt handler to see if the problem is that the interrupt is not fired or does the handler read 0 bytes. Also maybe you have wrong pins attached to the IRQ.

Hopes this helps

Oct 6, 2014 at 12:55 PM
Hello Jakub, thanks for your answer. I will try changing/checking the IRQ pins. But what do you exactly mean by "Also maybe you have wrong pins attached to the IRQ" ? Just the wrong pin ? Or maybe pins I can't use for interrupts?

Oct 6, 2014 at 1:21 PM
I was thinking about the first one, that you declare wrong pin as the one attached to the module IRQ pin, but it is also an idea to check if the pin you are using supports interrupts.
Oct 7, 2014 at 7:39 AM
I've rechecked the wiring with an excel sheet. First there was an error with SPI1 which leads to an incorrect address on AddressSlot.One (it looses 1 bit 0x0F turns into 0x0E on the first byte).

It seems that I had irq pin misconfiguration as you suggested, because now I get interrupts on the senders side. But it runs into the TransmitFailed event. How could I find out what exactly is going wrong? I think there was an debugmessage saying retry count exceeded. But it was too late to do further investigation.

Oct 7, 2014 at 10:27 AM
Ok It's good you are moving forward. Can you please share your code so that I can validate it and maybe someone else will also benefit from it?
Oct 7, 2014 at 11:06 AM
Here's some code I've produced to test the environment. I've also tested the scenario with two different addresses configured, on both sides adding the opposite address into AddressSlot.One. and sending to _module1 AddressSlot.One.
NRF24L01Plus _module1 = new NRF24L01Plus() { Name = "Sender" };
NRF24L01Plus _module2 = new NRF24L01Plus() { Name = "Receiver" };
Timer t;

public override void Init()
    _module1.Initialize(SPI_Devices.SPI3, Pins.GPIO_PIN_A_14, Pins.GPIO_PIN_A_15, Pins.GPIO_PIN_D_0);
        _module1.Configure(new byte[] { 0x0F, 0x0F, 0x0F, 0x0F, 0x0F }, 77, NRFDataRate.DR2Mbps);

    // this handler executes on sender
    _module1.OnTransmitFailed += OnTransmitFailed;
    // this handler never executes
    _module1.OnTransmitSuccess += OnTransmitSuccess;

    _module2.Initialize(SPI_Devices.SPI2, Pins.GPIO_PIN_D_8, Pins.GPIO_PIN_D_10, Pins.GPIO_PIN_B_12);
    _module2.Configure(new byte[] { 0x0F, 0x0F, 0x0F, 0x0F, 0x0F }, 77, NRFDataRate.DR2Mbps);
    // both handlers are never executed
    _module2.OnDataReceived += this.OnReceive;
    _module2.OnInterrupt += _module2_OnInterrupt;
    t = new Timer((e) =>
                var adr = _module1.GetAddress(AddressSlot.Zero, 5);
                _module1.SendTo(adr, UTF8Encoding.UTF8.GetBytes("HI"));
            }, true, 0, 2000);
Oct 7, 2014 at 11:19 AM
_module1.Configure(new byte[] { 0x0F, 0x0F, 0x0F, 0x0F, 0x0F }, 77, NRFDataRate.DR2Mbps);
_module2.Configure(new byte[] { 0x0F, 0x0F, 0x0F, 0x0F, 0x0F }, 77, NRFDataRate.DR2Mbps);
You are setting the same address for both modules, those values should be different.
Also you can skip the third argument as this is the default value.
var adr = _module1.GetAddress(AddressSlot.Zero, 5);
 _module1.SendTo(adr, UTF8Encoding.UTF8.GetBytes("HI"));
This means you want module1 to send data to module1
Oct 7, 2014 at 11:30 AM
But I also have to add the opposite addresses into my AddressSlots ?
Oct 7, 2014 at 12:18 PM
I guess you have read how the modules work and this makes you confused. Using this library you don't have to touch the slots. Just send data to an address you want and that's it. Under the hood the library sets the slot0 to receiver address in order for ShockBurst ack to work.
Oct 7, 2014 at 1:05 PM
You're right :) As I also struggeled around with the arduino RF24 library I read a little bit about pipes and addresses.

Thank you for your help. I will try it later that day.
Oct 8, 2014 at 7:32 AM
Edited Oct 8, 2014 at 7:36 AM
Finally the connection between SPI1 and SPI2 radio on my stm32 board works. I think it was a mix of wrong configuration and faulted jumper wires from china. Even the communication between arduino and stm32 worked .. but only for the first time I reset the arduino. First package got sent, visual studio jumped into the breakpoint OnDataReceive and the correct byte array got received. Every call after the first neither the OnInterrupt gets called nor the InDataReceive gets called.

After some googling I've read some solved problems where people added 10uF capacitor in the chip. From my understanding this is obsolete if I use a breadboard powersupply with max 500ma from the USB bus.

Even if this is not a Gralin driver problem could you help?