Problem using RF24 library with Particle Core

Hello all,

I am using the nRF24L01 modules with my Particle Core.

I am using the RF24 library from @BDub (https://github.com/technobly/SparkCore-RF24). For normal use case it works perfectly fine. I can send and receive data from multiple RF24 modules.

I have a strange problem while sending data to a node (RF24 module + Arduino Nano) which is offline. When I try to send data to this node, Core gets disconnected from cloud.

I observed the following LED sequence when this is happening.
–> Flasing Cyan
–> Flashing RED
–> Breathing Cyan
–> Flashing Green
–> Flashing Cyan
–> Breathing Cyan

I am also using the Blynk interface to initiate the data transfer over RF24 module. I also tried by totally disconnecting the Core from Spark cloud, I still have problem of disconnection.

RF radio is initialized with radio (15, 15) --> 4 ms delay and 15 retries --> 60 ms run time.
Also some run time from Blynk interface.

So is the core resetting ? If so, is it because of some Watchdog timer ?

I request the community to support me solve this issue with your experience.

Thank you.

With the flashing red, is it an SOS pattern followed by some slow blink?
Could you post your code?

1 Like

Hi,

With the Flashing RED, yes its kind of SOS pattern (moderate speed flashing) followed by small pause (Led completely off) and then slow blinking.

The case when the message transmission is success is always Okay. Only when message sent is failed most of the time I get this problem.

Here is the code:

/*
 * RF24 LIBRARY FOR SPARK CORE
 * =======================================================
 * Copy this into a new application at:
 * https://www.spark.io/build and go nuts!
 * !! Pinouts on line 44 below !!
 * -------------------------------------------------------
 *  Author: BDub
 * Website: http://technobly.com
 *    Date: Feb 19th 2014
 * =======================================================
 * https://github.com/technobly/SparkCore-RF24
 */

/*
 Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.
 */

#include <application.h>
#include <SparkCorePolledTimer.h>
#include <BlynkSimpleParticle.h>
#include "BlynkHomeIfc.h"

/*Blynk Authentication */
char auth[] = "myAutcode";
WidgetTerminal Debug_Terminal(V2);
WidgetLED LED_ConnectionStatus(V1);

RF24 m_radio(D6, A2);
RF24Network m_rfNetwork(m_radio);

SparkCorePolledTimer  every50ms(50);
SparkCorePolledTimer  every1sec(1000);

void CyclicEvery50ms( void );
void CyclicEvery1s( void );

void notifyBlynkConnecStatus( void );
void updateRelayStatustoPhone( void );

unsigned uint8_t reqReceived = 0;

void setup(void)
{
  pinMode(D7, OUTPUT);
  Serial.begin(57600);
  m_radio.begin();
  m_rfNetwork.begin(/*channel*/ 90, /*node address*/ 00);
  
  //Radio Parameters
  // delay is in 250us increments (4ms max), retries is 15 max.
  m_radio.setRetries(15,15);
  m_radio.printDetails();

  /* Cyclic timer settings */
  every50ms.SetCallback(CyclicEvery50ms);
  every1sec.SetCallback(CyclicEvery1s);
  
  delay(1000);
  Blynk.begin(auth);
}

void loop(void)
{
  /*Blynk Cyclic handling */
  Blynk.run();
  
  /* RF Network Cyclic Handling */
	m_rfNetwork.update();
	
	/* Read any available messages */
  while ( m_rfNetwork.available() )
  {
    // If so, grab it and print it out
    RF24NetworkHeader header;
    m_rfNetwork.peek(header);

    if(header.type == MSG_TYP_STATUS)
    {
      handleStatusMsg();
    }
  }

  /* For Cyclic Handling */
  every50ms.Update();
  every1sec.Update();
}

/*****************
* cyclic functions
******************/
/****************************************************************************
* Cyclic 50 ms function,
* Send command if any
******************************************************************************/
void CyclicEvery50ms( void )
{
  if( reqReceived == 1)
  {
	uint16_t command = 5555;
	
	blynkPrint("Sending command ...");

	RF24NetworkHeader header(/*toNode*/ 1, /*message type */ 1);
	bool ok = m_rfNetwork.write(header, &command, sizeof(command));
	if (ok)
	{
		blynkPrint("ok");
	}
	else
	{
		blynkPrint("failed");
	}
  }
}


/*******
* Blynk
********/
/****************************************************************************
* Cyclic 1s function, Update HW connection status to Blynk
******************************************************************************/
void CyclicEvery1s( void )
{
    if(LED_ConnectionStatus.getValue())
    {
      LED_ConnectionStatus.off();
    }
    else
    {
      LED_ConnectionStatus.on();
    }
}
/******************************************************************************
* Blynk switch pressed
*******************************************************************************/
BLYNK_WRITE(V0)
{
  int pinData = param.asInt();
  if(pinData == 1)
  {
    reqReceived = 1;
  }
  else
  {
    reqReceived = 0;
  }
}

/******************************************************************************
* Blynk print to Terminal
*******************************************************************************/
void blynkPrint( char *string )
{
  Debug_Terminal.println(string);
  Debug_Terminal.flush();
}

How many slow blinks have you got between two SOSs?
https://docs.particle.io/guide/getting-started/modes/photon/#red-flash-sos

Your code above is cloud connected and hence this

  while ( m_rfNetwork.available() )
  {
    ...
  }

might pose a problem if m_rfNetwork.available() remains true or any of the functions inside the loop block for 10+sec.
Try adding Particle.process() inside the loop and add some Serial.print() statements to see where your code fails
e.g. before and after above loop to see if you get stuck in there, and in there to see where it is hanging.

@ScruffR Thank you. Definetly, I will add the Serial.Print statements to debug further.
Between, after thoroughly observing the RED led flash pattern, I am not really sure if it is SOS. I have uploaded the video temporarily in youtube (https://youtu.be/aHPqRP6Y7Rw). When you get time, can you please have a look at this video. For me it seems like one slow blink between two SOSs.

Yup, it’s one blink (Hard Fault).
Probably a mem violation of some sort.

@ScruffR Thanks for confirming.
I had looked through other post regarding the reasons for Hard Fault. Most reasons are memory violation. I got a bit idea. I will debug through my code and see if I can find any thing. I will update my progress too …
Other than Memory violation, are there any other reasons that could cause this error ?

I’ve not really come across other reasons, but mem violations sometimes come in various disguises, so it might be one but you might not recognize it as such :wink:

I do not know the exact reason but somehow I solved the problem and I don’t see the issue any more.

When a particular node is offline, RFNetwork layer that I am using tries couple of times to send the message over RF network. Between every re-try there is a small delay. All these trails is done in a thread blocking call. So every send request to offline node took more than 1.5 sec (loop is blocking until this time). So there there are fast and repeated requests from Blynk, I guess this time is accumulation and some where the system is crashing.

I fixed the problem by modifying the network layer, reducing the delay time and number of re-tries. With the I reduced the blocking time from 1.5 sec to 300 ms and so far looks fine. This issue is not seen any more from past 3 months.

Thanks for the support.