Arduino crashing

I am interacting with an RFM22 chip (wireless transceiver) using the SPI interface, I read a signal and stream it over UDP (ethernet shield), the problem is that the code runs for about a minute then everything hangs up. I was thinking it was the shield who was hanging up, so I added a line which prints serial data to my screen. It turned out that, it was the arduino that was crashing as both the serial and the UDP streamming just freeze at the same time.

As far as I can tell the code is fairly simple, any tip about what is causing this crash?

Note: both of the RFM module and the Ethernet shield are using the SPI interface, however I have separate Slave select pin for each of them. I am thinking of adding delays along the code may be to alleviate any contention on the SPI data lines (not sure about that yet).
So what do you guys think? any idea(s), tip(s) will highly help.

Note: I even removed the variable declaration from the loop part (to ensure that each variable is declared only once).

Thx in advance.

void loop() {
  for (i = 0; i < 4; i++)
    // RF part
    freq = targetFreq[i];
    delay(delay20); // Let the freq settle
    rssi = rf22.rssiRead(); // reads an integer

    // UDP part
    Udp.beginPacket(RemIP, RemPort);

I think your Arduino is runnning out of Sram, but I don't have much knowledge about it. Especify which Arduino model are you using, whether Uno, Mega or else.

It turned out that, it was the Arduino that was crashing as both the serial and the UDP streaming just freeze at the same time.

What makes you think that would indicate that the Arduino crashes?

"mart256" Sorry I forgot to mention it is an Uno, "Paul__B" I added a print line in the loop (as shown in the code), and I can see that when the ethernet stops working the serial data will stop coming as well. This was my indication that, it was the Uno which is haning and not the Ethernet shield.


I rather thought you might think that. :grinning:

The point though, is that your code consists entirely of library calls, which perform "deep magic".

These functions are dependent on polling the status of the Ethernet interface, and if that status never acknowledges success, then the function can never return and it hangs. But that will be no fault of the Arduino code, it is merely doing what the program says; it is the Ethernet that has crashed.

The problem is called "blocking" code.

"Paul__B", thank you very much, this makes much more sense. Now I know what to do next.
Thank you again.