Go Down

Topic: NRF24L01 can not be initialized (Read 2062 times) previous topic - next topic

seaking

Aug 18, 2012, 07:52 pm Last Edit: Aug 19, 2012, 10:21 am by seaking Reason: 1
Hey,

I've bought 2 NRF24L01 (the green ones with 10 Pins) on ebay and I connected them that way:

NRF24L01             Arduino Uno Pin              Arduino Mega 1280 Pin
VCC                             3,3V                                          3,3V
CE                                 9                                              48
CSN                             10                                              49
SCK                             13                                              52
MO                              12                                              50
MI                                11                                             51
IRQ                              -                                                -
GND                            GND                                           GND

I use the RF24 Library and the GettingStarted Sketch

Uno:
Code: [Select]
RF24 radio(9,10);

Mega:
Code: [Select]
RF24 radio(48,49);

(For Serial Output see attatchments)

The output of the Mega is very similar to the uno's.

The screenshots are taken with only one device up! And it does not change if I have both up (one is transmitting and one responding/receiving).
When both were running I scanned with my phone for available Bluetooth Devices but nothing was found.


Your screenshot seems to indicate the device is not getting detected properly.
It should display the correct addressing on boot:     RX_ADDR_P0-1   = 0xf0f0f0f0d2 0xf0f0f0f0e1


I can recreate your issue by reversing the following line:

RF24 radio(49,48);


My best bet is that you just have a couple wires reversed.

seaking

Unfortunately this was not the solution and I tried a slightly different Pin config from another website but the zeros in the config stay. 

P18F4550

What version of IDE are you using?

I still use 0018 with spi.h because when SPI.H was included with Arduino IDE package eveything stopped working

I have used NRF24l01's without problems,

TMRh20 is right CE & CSN are the wrong way round, I do remember having to define CSN in my code and remember to make it an OUTPUT

NRF24l01's work out of the box so theres no real need to mess with the registers unless you know what your doing

seaking

I use the current IDE 1.0.1 wit SPI.h

I do remember having to define CSN in my code and remember to make it an OUTPUT

Well I cannot use radio.csn(int bla) because is defined as private in the header file or do you mean to change it in the header file?



When both were running I scanned with my phone for available Bluetooth Devices but nothing was found.




The nRF24L01 is not a bluetooth device.
www.bajdi.com

seaking



The nRF24L01 is not a bluetooth device.

Sure my mistake

@P18F4550 my 1.0.1 IDE SPI.h :
Code: [Select]
/*
* Copyright (c) 2010 by Cristian Maglie <c.maglie@bug.st>
* SPI Master library for arduino.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of either the GNU General Public License version 2
* or the GNU Lesser General Public License version 2.1, both as
* published by the Free Software Foundation.
*/

#ifndef _SPI_H_INCLUDED
#define _SPI_H_INCLUDED

#include <stdio.h>
#include <Arduino.h>
#include <avr/pgmspace.h>

#define SPI_CLOCK_DIV4 0x00
#define SPI_CLOCK_DIV16 0x01
#define SPI_CLOCK_DIV64 0x02
#define SPI_CLOCK_DIV128 0x03
#define SPI_CLOCK_DIV2 0x04
#define SPI_CLOCK_DIV8 0x05
#define SPI_CLOCK_DIV32 0x06
//#define SPI_CLOCK_DIV64 0x07

#define SPI_MODE0 0x00
#define SPI_MODE1 0x04
#define SPI_MODE2 0x08
#define SPI_MODE3 0x0C

#define SPI_MODE_MASK 0x0C  // CPOL = bit 3, CPHA = bit 2 on SPCR
#define SPI_CLOCK_MASK 0x03  // SPR1 = bit 1, SPR0 = bit 0 on SPCR
#define SPI_2XCLOCK_MASK 0x01  // SPI2X = bit 0 on SPSR

class SPIClass {
public:
  inline static byte transfer(byte _data);

  // SPI Configuration methods

  inline static void attachInterrupt();
  inline static void detachInterrupt(); // Default

  static void begin(); // Default
  static void end();

  static void setBitOrder(uint8_t);
  static void setDataMode(uint8_t);
  static void setClockDivider(uint8_t);
};

extern SPIClass SPI;

byte SPIClass::transfer(byte _data) {
  SPDR = _data;
  while (!(SPSR & _BV(SPIF)))
    ;
  return SPDR;
}

void SPIClass::attachInterrupt() {
  SPCR |= _BV(SPIE);
}

void SPIClass::detachInterrupt() {
  SPCR &= ~_BV(SPIE);
}

#endif

P18F4550

I've started using different radio's now, not used nrf24l01's for a while, but when i did this is what i did

Code: [Select]
#include <Spi.h>
#include <mirf.h>
#include <nRF24L01.h>

int l=65;   // Cant remember what this was
int ledPin =  8;
void setup()
{
//  Serial.begin(9600);
    pinMode(ledPin, OUTPUT);

  Mirf.init();
  Mirf.setRADDR((byte *)"clie1");
  Mirf.payload = sizeof(int);
  Mirf.config();

}

void loop()
{
// byte data[Mirf.payload];
  Mirf.setTADDR((byte *)"serv1");

  int temp = analogRead(0);  // read analog 0
  Mirf.send((byte *) &temp); // send the value
 
  while(Mirf.isSending())
  {
  }

  digitalWrite(ledPin, HIGH);  // blip the led to say it's sent
  delay(50);               
  digitalWrite(ledPin, LOW);   
  delay(950);     

}

Here is my pin configuration, it seems to differ slightly from what you posted initially, so thought it might be worth posting:

Mega:
48 (CE), 49 (CSN), 50 (MISO), 51 (MOSI), 52 (SCK)

RF24 radio(48,49);


Nano/Uno:

9 (CE), 10 (CSN), 11(MOSI), 12(MISO), 13(SCK)

RF24 radio(9,10);

seaking


Here is my pin configuration, it seems to differ slightly from what you posted initially, so thought it might be worth posting:

Mega:
48 (CE), 49 (CSN), 50 (MISO), 51 (MOSI), 52 (SCK)

RF24 radio(48,49);


Nano/Uno:

9 (CE), 10 (CSN), 11(MOSI), 12(MISO), 13(SCK)

RF24 radio(9,10);



I do have the exact same Pin Config ;) and It does not work, now I tried the Mirf libraray but this does not even compile the examples :
Code: [Select]
.../arduino-1.0.1/libraries/Mirf/Mirf.cpp: In member function 'void Nrf24l::init()':
.../arduino-1.0.1/libraries/Mirf/Mirf.cpp:85: error: 'OUTPUT' was not declared in this scope
.../arduino-1.0.1/libraries/Mirf/Mirf.cpp:85: error: 'pinMode' was not declared in this scope
.../arduino-1.0.1/libraries/Mirf/Mirf.cpp: In member function 'void Nrf24l::ceHi()':
.../arduino-1.0.1/libraries/Mirf/Mirf.cpp:285: error: 'HIGH' was not declared in this scope
.../arduino-1.0.1/libraries/Mirf/Mirf.cpp:285: error: 'digitalWrite' was not declared in this scope
.../arduino-1.0.1/libraries/Mirf/Mirf.cpp: In member function 'void Nrf24l::ceLow()':
.../arduino-1.0.1/libraries/Mirf/Mirf.cpp:289: error: 'LOW' was not declared in this scope
.../arduino-1.0.1/libraries/Mirf/Mirf.cpp:289: error: 'digitalWrite' was not declared in this scope
.../arduino-1.0.1/libraries/Mirf/Mirf.cpp: In member function 'void Nrf24l::csnHi()':
.../arduino-1.0.1/libraries/Mirf/Mirf.cpp:293: error: 'HIGH' was not declared in this scope
.../arduino-1.0.1/libraries/Mirf/Mirf.cpp:293: error: 'digitalWrite' was not declared in this scope
.../arduino-1.0.1/libraries/Mirf/Mirf.cpp: In member function 'void Nrf24l::csnLow()':
.../arduino-1.0.1/libraries/Mirf/Mirf.cpp:297: error: 'LOW' was not declared in this scope
.../arduino-1.0.1/libraries/Mirf/Mirf.cpp:297: error: 'digitalWrite' was not declared in this scope

an it seem that the Mirf.ce() and Mirf.csn() set funtions had been removed.

MDreamer

add:

#include <Arduino.h>

underneath:

#include <WProgram.h>

in Mirf.h in the library files

Maayan Dreamer 

wisepi

:)
add:
#include <Arduino.h>
underneath:
#include <WProgram.h>
in Mirf.h in the library files
Maayan Dreamer

====== it's ok and Solve my problem======

Go Up