ATmega328p-pu + NRF24L01: Sketch freezes on microcontroller but works on arduino

So i got my NRF24L01 modules to work with my arduino Uno and Micro and i wanted to replace them for a standalone ATmega328p-pu without any other components.

I started off by bootloading the microcontroller using my arduino UNO and the info on http://arduino.cc/en/Tutorial/ArduinoToBreadboard and i tested this with a blink sketch.

So i just have an atmega on my breadboard and a voltage regulator to drop the 9V battery to 3.3V to power the atmega and the nrf module.

This is the code i uploaded to my microcontroller:

/*
 Copyright (C) 2012 James Coliz, Jr. <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.
 
 Update 2014 - TMRh20
 */

/**
 * Simplest possible example of using RF24Network 
 *
 * TRANSMITTER NODE
 * Every 2 seconds, send a payload to the receiver node.
 */

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>

RF24 radio(9,10);                    // nRF24L01(+) radio attached using Getting Started board 

RF24Network network(radio);          // Network uses that radio

const uint16_t this_node = 01;        // Address of our node in Octal format
const uint16_t other_node = 00;       // Address of the other node in Octal format


int led = 8;


struct payload_t {                  // Structure of our payload
  int test;
  int moop;
};

void setup(void)
{
 
   pinMode(led,OUTPUT);
   digitalWrite(led,HIGH);
   delay(2000);
   digitalWrite(led,LOW);
   delay(2000);
   digitalWrite(led,HIGH);
   delay(2000);
  SPI.begin();
  radio.begin();
  network.begin(/*channel*/ 90, /*node address*/ this_node);
}

void loop() {
  digitalWrite(led,LOW);
  network.update();                          // Check the network regularly
  delay(2000);
  digitalWrite(led,HIGH);
  delay(2000);
  digitalWrite(led,LOW);  
  payload_t payload = { 5, 1337 };
  RF24NetworkHeader header(/*to node*/ other_node);
  network.write(header,&payload,sizeof(payload));
  delay(2000);
  digitalWrite(led,HIGH);
  delay(2000); 
 }

I’m using led blinks for debugging and i’m just sending 2 random integers to just check if it works.
The microcontroller stops in this section:

 network.write(header,&payload,sizeof(payload));

To check if there was something wrong with the sketch i uploaded this exact sketch to my arduino micro and it worked fine.

I connected the atmega328p-pu to the nrf24 module like so:

nrf24 ------- atmega328
GND —> GND
VCC —> VCC
CE ----> PB1
CSN ----> PB2
SCK -----> PB5
MOSI —> PB3
MISO → PB4
IRQ —> /

NRF24L01 Pin layout: http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
ATmega328 Pin layout: http://arduino.cc/en/Hacking/PinMapping168

I’m currently using the RF24 library http://tmrh20.github.io/RF24/

I’m using a 3.3V regulator on the breadboard so that i can use a 9V battery. I checked the voltages on the circuit and it’s 3.3V so no mistakes there. The NRF is also on 3.3V.

I have absolutely no idea why this doesn’t work. Any and all suggestions are very much welcome.

It's funny how the thing you expect is definitely not the problem, is in fact the problem.

I powered the atmega with the ground and 3.3V from the arduino uno (no other connections) and then it all works fine.

I really don't understand what's going on when the network.write happens and i'm positive everything had 3.3V.

Very weird.

The battery has not enough current maybe it is discharged. Thats what I think.

Bullzeyes: It's funny how the thing you expect is definitely not the problem, is in fact the problem.

I powered the atmega with the ground and 3.3V from the arduino uno (no other connections) and then it all works fine.

I really don't understand what's going on when the network.write happens and i'm positive everything had 3.3V.

Very weird.

Just wondering, the voltage controller you use, how much current can it supply? If the current is to much, the voltage can drop far below the 3.3V and even jump up and down.

EDIT: i was looking for the current intake of the NRF24 and found this: http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo

Thought you might like it. It has a solution to sudden voltage drops if the unit has a current surge in the sending it does.

Hi

Try a 47uf electrolyte cap near to the NRF24 Vcc and ground, this should solve it.

Regards

Phil

I’m using this Voltage regulator(TO-220):http://iprototype.be/docs/volt-regulator-3.3V-technisch-datasheet.pdf

I don’t have any other caps but the caps that came with the starter package of the Arduino :s At the moment i’ve found a 2x AA battery holder that i’m using and it’s working great.

Is there a way to calculate what kind of cap i need or is it just from datasheets that i can get this information ?

I have 100 uF, 100nF and 100pF. Can i use a 100uF instead ?

Thanks for the help guys !

In regards to bypass capacitors, the difference between 47µF and 100µF is pretty much immaterial.

OK?

{I would have said 10µF myself but ...}

Bullzeyes: Is there a way to calculate what kind of cap i need or is it just from datasheets that i can get this information ?

I have 100 uF, 100nF and 100pF. Can i use a 100uF instead ?

100uF is fine. It's just used to "catch" the sudden voltage drops during a power surge. The higher the value of cap, the more power it can deliver.

Normaly a datasheet is a good referance for things like caps or resistors. You only want to calculate if it's being used for controlling things or RC-networks.

Let us know if it works!

This worked ! I put the 100 uF cap right in front of my VCC and GND of my NRF module in the 3.3V and GND slots of my breadboard.

Thanks for the help guys !

Hi

Paul__B: In regards to bypass capacitors, the difference between 47µF and 100µF is pretty much immaterial.

OK?

{I would have said 10µF myself but ...}

I tried 1uf, 10uf, 22uf and only at 47uf did the NRF24 start working reliability. Same thing as OP I was going via a low dropout regulator, I think they cannot react quick enough to the power demands. It doesn't draw much overall but draws a lot in very short bursts I guess.

Regards

Phil

Phil-D: I was going via a low dropout regulator, I think they cannot react quick enough to the power demands. It doesn't draw much overall but draws a lot in very short bursts I guess.

No and yes.

The regulator can most certainlyreact quick enough, it is just limited in the amount it can provide. On that basis, my previous comment was wrong, I had forgotten the context. A smaller value which would normally be perfectly appropriate for bypassing to suppress transients, is not enough, you want a big reservoir in order to provide power for the whole transmission burst which the 3.3V regulator could simply never handle.