1

What I have

Raspberry Pi 3 B

RF24L01

RF24 Library TMRh20

How I've Connected It

Based on the library indications:

RF24L01 pin | RPi 3B
1 GND       | 9 GND
2 VCC       | 1 (3.3V)
3 CE        | 15 (GPIO22)
4 CSN       | 24 (GPIO8) (CE0)
5 SCK       | 23 (GPIO11) (SPI_CLK)
6 MOSI      | 19 (GPIO10) (SPI_MOSI)
7 MISO      | 21 (GPIO9) (SPI_MISO)

Pic of Pins

The Code (Executable, built using TMRh20 library)

#include <RF24/RF24.h>

using namespace std;

// Pin 22 used for CE, as said before in pin connections
RF24 radio(22,0);

int main(int argc, char** argv)
{

  printf("Starting...\n");

  radio.begin();

  printf("Done\n");

  return 0;

}

Output

Output

Problem / Question

As you can see, a segmentation fault error (in Spanish) happened. I've also activated the SPI interface using:

sudo raspi-config

So, why do I get this execution error?

Isn't the initialization valid?

Update

I've also tried moving ping CE from RF24, that was connected to GPIO22 (pin 15) to pin 26 (CE1), because I saw this in the dependence BCM2835.

Then, I enabled SPI again, built and execute again, getting the same result.

Btc Sources
  • 123
  • 7

2 Answers2

2

I just ran into the same issue, and discovered that it will segfault if you do not run the program as root (sudo). It would be great if it could be more helpful, but alas. Try putting sudo in front of the ./test

Determined the problem by finding this comment in the source code:

If the library runs with any other effective UID (ie not root), then bcm2835_init() will attempt to open /dev/gpiomem, and, if successful, will only permit GPIO operations. In particular, bcm2835_spi_begin() and bcm2835_i2c_begin() will return false and all other non-gpio operations may fail silently or crash.

Source: https://github.com/nRF24/RF24/blob/95ef8bdadf9068796444151c162749eb5bad4c26/utility/RPi/bcm2835.h#L63-L67

Paul
  • 121
  • 2
1

First, I noticed that building the library as told on the documentation with:

sudo make install -B

Run inside another configure, which deletes yours. That said, what I did was, from my $~ directory:

cd ./RF24/
sudo ./configure --driver=SPIDEV

Went to the file Makefile.inc and replace (as told by Joan in a comment):

CC=...-gcc --> CC=gcc
CXX=...-g++ --> CXX=g++

Then, install the library (notice no -B option, so my Makefile.inc file is not replaced by the new created by a new run of configure):

sudo make
sudo make install

Finally, go to the examples folder (where my program is) and compile it. Modifying first my makefile of course:

cd ./examples_linux/

Edit Makefile

PROGRAMS = receiver

Compile and run:

sudo make
./receiver

My program now executes fine without any error and without needing sudoers.

Btc Sources
  • 123
  • 7