[SOLVED] RPI2 + NRF24L01 SPI problem ?

14 posts
by meandrey » Sun Feb 08, 2015 4:29 pm

I want to add a NRF24L01 to my RPI 2 in order to communicate with an arduino.
I followed the instructions from http://hack.lenotta.com/arduino-raspber ... h-nrf24l01 but it gets stuck when i run:
Code: Select all
sudo ./remote -m 81

Preparing interface

Having a look in the code it looks like that after "Preparing interface" print the program gets stuck at RF24.begin

I did rpi-update a few minutes ago so my kernel version is 3.18.6-v7.

Code: Select all
Linux version 3.18.6-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.8.3 20140303 (prerelease) (crosstool-NG linaro-1.13.1+bzr2650 - Linaro GCC 2014.03) ) #753 SMP PREEMPT Sun Feb 8 14:53:56 GMT 2015

My /boot/config.txt would look like this:
( i will add only the end of the file because everything else is commented)
Code: Select all


Bellow you can see the result for "lsmod":

Code: Select all
Module                  Size  Used by
i2c_dev                 6027  0
snd_bcm2835            18850  0
snd_pcm                75388  1 snd_bcm2835
snd_seq                53078  0
snd_seq_device          5628  1 snd_seq
snd_timer              17784  2 snd_pcm,snd_seq
snd                    51667  5 snd_bcm2835,snd_timer,snd_pcm,snd_seq,snd_seq_device
evdev                   9950  2
joydev                  8903  0
w1_therm                2559  0
spi_bcm2708             5153  0
i2c_bcm2708             4990  0
w1_gpio                 3680  0
wire                   25704  2 w1_gpio,w1_therm
cn                      4636  1 wire
uio_pdrv_genirq         2958  0
uio                     8119  1 uio_pdrv_genirq

Also attached you can find images with the connections from the module to rpi. I would say that everything is correct.
Could it be a problem with RF24 library on RPI2. Did anyone managed to add a NRF24 module to rpi2?




Sorry for the long post.
Thank you.

PS: I tried also with the python3 (Cython) wrapper over the RF24 library: https://github.com/jonathongrigg/rf24
here i get the following error:
Code: Select all
can't send spi message: Invalid argument
Posts: 5
Joined: Sun Feb 08, 2015 12:08 pm
by rtramon » Mon Feb 09, 2015 10:21 am
On rpi 2 model b the base address for the peripherals is different.
I haven't checked but the bcm2835 library might need to be updated.
Posts: 11
Joined: Sat Jul 07, 2012 10:06 am
Location: 't Gooi
by meandrey » Mon Feb 09, 2015 11:28 am
Bellow is the code from bcm285.h. do you think changing the #define BCM2835_PERI_BASE from 0x20000000 to 0x3F000000 should do it?

Or a change is needed to all the other addresses?

Code: Select all
// Physical addresses for various peripheral register sets
/// Base Physical Address of the BCM 2835 peripheral registers
#define BCM2835_PERI_BASE               0x20000000
/// Base Physical Address of the System Timer registers
#define BCM2835_ST_BASE         (BCM2835_PERI_BASE + 0x3000)
/// Base Physical Address of the Pads registers
#define BCM2835_GPIO_PADS               (BCM2835_PERI_BASE + 0x100000)
/// Base Physical Address of the Clock/timer registers
#define BCM2835_CLOCK_BASE              (BCM2835_PERI_BASE + 0x101000)
/// Base Physical Address of the GPIO registers
#define BCM2835_GPIO_BASE               (BCM2835_PERI_BASE + 0x200000)
/// Base Physical Address of the SPI0 registers
#define BCM2835_SPI0_BASE               (BCM2835_PERI_BASE + 0x204000)
/// Base Physical Address of the BSC0 registers
#define BCM2835_BSC0_BASE       (BCM2835_PERI_BASE + 0x205000)
/// Base Physical Address of the PWM registers
#define BCM2835_GPIO_PWM                (BCM2835_PERI_BASE + 0x20C000)
 /// Base Physical Address of the BSC1 registers
#define BCM2835_BSC1_BASE      (BCM2835_PERI_BASE + 0x804000)
Posts: 5
Joined: Sun Feb 08, 2015 12:08 pm
by meandrey » Mon Feb 09, 2015 2:02 pm

I managed to test the change and it's working.
Here is a list the changes of what i did based on https://github.com/edoardoo/RF24RaspberryCommunicator which is using https://github.com/stanleyseow/RF24 library.

1. Go to RF24RaspberryCommunicator/RF24/RPi and edit bcm2835.h the following line from
Code: Select all
 #define BCM2835_PERI_BASE               0x20000000

Code: Select all
#define BCM2835_PERI_BASE               0x3F000000

2. Go to RF24RaspberryCommunicator/RF24 and change in "Makefile" the argument -march=armv6zk to -march=armv7-a
Code: Select all
sudo make clean && sudo make && sudo make install

4. Go to RF24RaspberryCommunicator/ and change in another "Makefile" he argument -march=armv6zk to -march=armv7-a
Code: Select all
sudo make clean && sudo make

6. Test it:
Code: Select all
sudo ./remote -m 81
Posts: 5
Joined: Sun Feb 08, 2015 12:08 pm
by bradix14 » Tue Feb 10, 2015 6:21 pm
Am I correct in assuming that some or all of these fixes do not apply to the Pi B+ ?

I can't get the NRF working with the B+. Any tips? The Pi just doesn't see the hardware.
Posts: 13
Joined: Mon Feb 09, 2015 7:34 am
by acmbc » Sun Feb 15, 2015 9:53 am
I am having exactly the same problem - although on an early (Rev. 1) Model B.

Have tried disabling Device Tree, edited config.txt in /boot to make sure SPI and I2C are on and Device Tree is off, etc..., etc... but to no avail.

Everything was working up to Feb. 8 and then boom....update broke SPI

Has anyone with a model B/B+ had any joy getting things back to normal?
Posts: 1
Joined: Sun Feb 15, 2015 1:13 am
by diSE » Wed Feb 25, 2015 11:02 am
Hello guys i have the same issue after rpi-update to 3.18.7+
Do you know how to solve this ?
Posts: 3
Joined: Wed May 29, 2013 8:18 pm
by slgeo » Mon Mar 02, 2015 7:28 pm
meandrey, thx, its work!
Posts: 2
Joined: Mon Mar 02, 2015 7:22 pm
by shahidhk » Tue Mar 03, 2015 12:02 pm
Can you please confirm which board have you used? I trien on a RPi 2 Model B v1.1 and it is always giving me this output:

Code: Select all
================ SPI Configuration ================
CSN Pin      = CE0 (PI Hardware Driven)
CE Pin      = Custom GPIO22
Clock Speed    = 8 Mhz
================ NRF Configuration ================
STATUS       = 0xff RX_DR=1 TX_DS=1 MAX_RT=1 RX_P_NO=7 TX_FULL=1
RX_ADDR_P0-1    = 0xffffffffff 0xffffffffff
RX_ADDR_P2-5    = 0xff 0xff 0xff 0xff
TX_ADDR       = 0xffffffffff
RX_PW_P0-6    = 0xff 0xff 0xff 0xff 0xff 0xff
EN_AA       = 0xff
EN_RXADDR    = 0xff
RF_CH       = 0xff
RF_SETUP    = 0xff
CONFIG       = 0xff
DYNPD/FEATURE    = 0xff 0xff
Data Rate    = 1MBPS
Model       = nRF24L01
CRC Length    = 16 bits
PA Power    = PA_MAX

Any clue?
Posts: 1
Joined: Tue Mar 03, 2015 12:00 pm
by slgeo » Wed Mar 04, 2015 2:22 pm
RPI 2 model 1.1
Code: Select all
================ SPI Configuration ================
CSN Pin          = CE0 (PI Hardware Driven)
CE Pin           = Custom GPIO22
Clock Speed      = 8 Mhz
================ NRF Configuration ================
STATUS           = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     = 0xf0f0f0f0e1 0xf0f0f0f0d2
RX_ADDR_P2-5     = 0xc3 0xc4 0xc5 0xc6
TX_ADDR          = 0xf0f0f0f0e1
RX_PW_P0-6       = 0x20 0x20 0x00 0x00 0x00 0x00
EN_AA            = 0x3f
EN_RXADDR        = 0x02
RF_CH            = 0x4c
RF_SETUP         = 0x07
CONFIG           = 0x0e
DYNPD/FEATURE    = 0x00 0x00
Data Rate        = 1MBPS
Model            = nRF24L01+
CRC Length       = 16 bits
PA Power         = PA_MAX
Posts: 2
Joined: Mon Mar 02, 2015 7:22 pm
by xavbabe » Tue May 12, 2015 10:24 am
I too am getting the error
Code: Select all
can't send spi message: Invalid argument

Any help?
Posts: 5
Joined: Sat Aug 09, 2014 11:52 am
by pe7er » Wed Nov 25, 2015 10:59 pm
Thank you meandrey for your excellent post!

While compiling I got the following error:
remote.cpp: In function ‘int main(int, char**)’:
remote.cpp:98:12: error: ‘sleep’ was not declared in this scope
Makefile:28: recipe for target 'remote' failed
make: *** [remote] Error 1

I solved that error by editing remote.cpp
Code: Select all
sudo nano remote.cpp

and added in head of that file:
Code: Select all
#include <unistd.h>
Kind regards,
Peter Martin
OS: Debian 8, Raspbian
User avatar
Posts: 12
Joined: Wed Jun 20, 2012 9:39 am
Location: Nijmegen, Netherlands
by KohlyHawkins » Wed May 04, 2016 7:21 pm
Hey guys,

Just checking in to see if there is any update on the RPi 2 Model B issue hanging up at the "Preparing Interface" stage. I have followed everything on the original blog for the project, which sent me here for Raspberry 2 problems. I also followed everything on this thread, but I'm still getting caught on the "Preparing Interface" step.

I'm on Raspberry Pi 2 Model B Version 4.1.19-v7+ and an Arduino Uno R3. Hopefully someone out there has figured out a fix for the RPi 2!

Posts: 1
Joined: Fri Feb 19, 2016 5:09 am
by tiagotaz » Sat Jun 25, 2016 8:21 pm
Hey Guys,

I Have a problem with the raspberry and module nrf24l01, I think is about this post.

When I send a parameter it`s work without problem, but when i use this some times to receive and send the stop of work and I need reset raspberry to came back to work. I don`t no why this happing can you help me?
Posts: 1
Joined: Sat Jun 25, 2016 8:11 pm