1

I want to communicate between Arduino Mini Pro (china import) and a stm32f4 running netmf runtime. At the moment I'm able to communicate between SPI1 and SPI2 on the stm32 board.

After that I switched on the Arduino. I'm using the RF24 library and modified the GettingStarted sample to simply open pipes and send the same byte array again and again to the stm32.

It works for the first transmit but after that I did not receive any interrupts on the receiver side.

Both NRF24L01+ are power supplied by a breadboard power supply module which supplies 500ma (max USB bus). The Arduino is connected and power supplied by a CP2102 USB/Serial adapter.

NETMF Address: 0F0F0F0F0F Arduino Address: 0F0F0F0F0E

As arduino uses little endian, I reverse the bytes on stm32 side before writing the address into the pipe. But I'm already unsure if I need that step (adding the Arduino address on netmf side).

Here's my Arduino code:

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

RF24 radio(9,10);

const int payload_size = 4;
const char payload[] = "PING";

void setup(void)
{

    Serial.begin(57600);
    printf_begin();
    radio.begin();
    radio.enableDynamicPayloads();
    radio.setChannel(77);
    radio.setAutoAck(true);
    radio.setRetries(15,15);
    radio.setDataRate(RF24_2MBPS);
    radio.openWritingPipe((uint64_t)0x0F0F0F0F0FLL);
    radio.openReadingPipe(1,(uint64_t)0x0F0F0F0F0ELL);
    radio.stopListening();
    radio.printDetails();
}

void loop(void)
{
    unsigned long time = millis();
    bool ok = radio.write( payload, payload_size );

    if (ok)
        printf("SUCCESS %lu...\n",time);
    else
        printf("fail %lu...\n",time);

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

}

Here's my NETmf code

NRF24L01Plus _module = new NRF24L01Plus();


public override void Init()
{
    _module.Initialize(SPI_Devices.SPI2, Pins.GPIO_PIN_D_8, Pins.GPIO_PIN_D_10, Pins.GPIO_PIN_B_12);
    _module.Configure(new byte[] { 0x0F, 0x0F, 0x0F, 0x0F, 0x0F }, 77, NRFDataRate.DR2Mbps);

    // both handlers are never executed
    _module.OnDataReceived += this.OnReceive;
    _module.OnInterrupt += _module2_OnInterrupt;

    _module.Enable();

}
3
  • Need to see your code. From my experience with RF24 library GettingStarted example, is its not asynchronous. Meaning, one must be listening and the other should be sending.
    – PhillyNJ
    Oct 8, 2014 at 22:14
  • I've added the code sample Oct 9, 2014 at 6:32
  • I am not familiar with the NRF24L01Plus library or NETmf. Does NETmf support c? I think the RF24 Library needs to be on both devices. I am not 100% sure.
    – PhillyNJ
    Oct 11, 2014 at 11:32

1 Answer 1

1

I have a couple of projects that use the NRF24L01+ and the RF24 Library.

As I mentioned in my comment, the examples provided is not asynchronous. I am not sure if the library supports asynchronous operations. Nevertheless, in your example, one radio should be in transmit mode and the other receive. If you look at the examples, the author uses modes (role_ping_out and role_ping_back). Basicly, the author wrote the code so you can both send and receive. But you can't do send and receive at the same time.

If you look at the example cope in the library, you can see where you need to stop receiving and start sending:

radio.stopListening();

// Send the final one back.
printf("Sent response.\n\r");
radio.write( &got_time, sizeof(unsigned long) );

// Now, resume listening so we catch the next packets.
radio.startListening();

And on the other radio stop sending and start receiving:

radio.startListening();

// Wait here until we get a response, or timeout (250ms)
unsigned long started_waiting_at = __millis();
bool timeout = false;
while ( ! radio.available() && ! timeout ) {
__msleep(30); //add a small delay to let radio.available to check payload
  if (__millis() - started_waiting_at > 200 )
    timeout = true;
}

// Describe the results
if ( timeout )
{
  printf("Failed, response timed out.\n\r");
}
else
{
  // Grab the response, compare, and send to debugging spew
  unsigned long got_time;
  radio.read( &got_time, sizeof(unsigned long) );

  // Spew it
  printf("Got response %lu, round-trip delay: %lu\n\r",got_time,__millis()-got_time);
}

If this is a bit confusing, I would suggest you load the Getting Started example on both your radios. Once you get that working, you can get a better idea on how it works.

Good Luck

4
  • Thanks for your answer. As I mentioned, the first transmit works. On STM32 side (NET Micro Framework) the interrupthandler gets raised and I receive the data I sent from Arduino. But after the first receive the interrupthandler never gets called again. Oct 9, 2014 at 13:13
  • Hard to tell because you only posted half your code. Where the code on the receiver side?
    – PhillyNJ
    Oct 9, 2014 at 13:44
  • I've added the netmf code Oct 10, 2014 at 8:47
  • Keep in mind that in most cases you just need to send back Ack for feedback. The library automatically does that, so don't build your own Ack protocol.
    – xyz
    Jan 8, 2015 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.