spirilis

[Energia Library] Nordic nRF24L01+ library

349 posts in this topic

Hi! I've had some trouble trying to configure this. 

 

1) My transreceiver doesn't have an antenna. But the weird thing is that using the "Channel Scanner" from the example of the library when I touch one of the cables it starts receiving information, and when I release it it stops.

 

2) What's the pin configuration?? 

 

I am working on a Quadcopter, and so far I would like to send the GPS coordinates to an LCD using two transreceivers: one flying, the other receiving. Please help!!!!! 

THANKS!

Share this post


Link to post
Share on other sites

Edit: Probably misunderstood your question. You would like to put two transceivers on a single Launchpad? Then read below :)

 

There are probably two options. Having both transceivers on the same SPI bus and assigning different CSN, CE and IRQ pins to them. To do this, you need to create two radio objects, for example:

Enrf24 radio1(CE_1,CSN_1, IRQ_1);
Enrf24 radio2(CE_2,CSN_2, IRQ_2);

Then you repeat the begin and configuration code for both. I havent tested this yet myseld, but should work in theory.

 

The second option is to use two different SPI buses, for that the Enrf24 library needs to be adapted, to support SPI argument as well. Again, writing this without testing:

 

Enrf24.h must have the constructor fixed and an include added.

#include <SPI.h>

Enrf24(SPIClass *mySPI, uint8_t cePin, uint8_t csnPin, uint8_t irqPin);
SPIClass *_mySPI;

Enrf24.cpp must have the constructor fixed and all instances of "SPI." changed by "_mySPI->"

/* Constructor */
Enrf24::Enrf24(SPIClass *mySPI,uint8_t cePin, uint8_t csnPin, uint8_t irqPin)
{
  _mySPI = mySPI;
  _cePin = cePin;
  _csnPin = csnPin;
  _irqPin = irqPin;

  rf_status = 0;
  rf_addr_width = 5;
  txbuf_len = 0;
  readpending = 0;
}

Then in your main code you call this fixed library by:

//radio
Enrf24 radio(&SPI, ENRF24L_CE, ENRF24L_CSN, ENRF24L_IRQ);

where SPI can be SPI0 for channel 0, SPI1 for channel 1, SPI for channel 2 (default), SPI3 for channel 3.

 

This should work in theory, but needs to be tested. There could be a neater solution though.

RamonCardona likes this

Share this post


Link to post
Share on other sites

Follow the tutorial you have posted, just repeat the connections on the second launchpad., Load one with TX demo and the other with RX demo that comes with this library.

Share this post


Link to post
Share on other sites

I did, I connected everything in both tivas the same way, and just modified the three ports used. 

 

Here's the code. 

 

?#?include? <Enrf24.h>
#include <nRF24L01.h>
#include <string.h>
#include <SPI.h>

Enrf24 radio(PE_1, PE_2, PE_3);
const uint8_t rxaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };

const char *str_on = "ON";
const char *str_off = "OFF";

void dump_radio_status_to_serialport(uint8_t);

void setup() {
Serial.begin(9600);

SPI.begin();
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);

radio.begin(); // Defaults 1Mbps, channel 0, max TX power
dump_radio_status_to_serialport(radio.radioState());

radio.setRXaddress((void*)rxaddr);

pinMode(BLUE_LED, OUTPUT);
//digitalWrite(BLUE_LED, LOW);

radio.enableRX(); // Start listening
}

void loop() {
char inbuf[100];

dump_radio_status_to_serialport(radio.radioState()); // Should show Receive Mode

while (!radio.available(true))
;
if (radio.read(inbuf)) {
Serial.print("Received packet: ");
Serial.println(inbuf);

if (!strcmp(inbuf, str_on))
digitalWrite(BLUE_LED, HIGH);
if (!strcmp(inbuf, str_off))
digitalWrite(BLUE_LED, LOW);
}
}

void dump_radio_status_to_serialport(uint8_t status)
{
Serial.print("Enrf24 radio transceiver status: ");
switch (status) {
case ENRF24_STATE_NOTPRESENT:
Serial.println("NO TRANSCEIVER PRESENT");
break;

case ENRF24_STATE_DEEPSLEEP:
Serial.println("DEEP SLEEP <1uA power consumption");
break;

case ENRF24_STATE_IDLE:
Serial.println("IDLE module powered up w/ oscillators running");
break;

case ENRF24_STATE_PTX:
Serial.println("Actively Transmitting");
break;

case ENRF24_STATE_PRX:
Serial.println("Receive Mode");
break;

default:
Serial.println("UNKNOWN STATUS CODE");
}
}

Share this post


Link to post
Share on other sites

So, I modified the order of the ports... 

Instead of  

Enrf24 radio(PE_1, PE_2, PE_3);

 

I am using 

Enrf24 radio(PE_3, PE_2, PE_1);

 

And what it does is just print "NO TRANSRECEIVER PRESENT"

Share this post


Link to post
Share on other sites

Yeah they need to be in the order of CE, CSN, IRQ.

Edit: err actually that wouldn't matter there so long as PE_2 is CSN.

 

Sent from my Galaxy Note II with Tapatalk 4

Share this post


Link to post
Share on other sites

This seems like it must be a simple "problem," but I can't figure it out.  I have a Stellaris launchpad, the NRF24L01+ boosterpack board that I have added the radios to, I only have the single row of headers on the boosterpack (like the original 430G2 launchpad), and have downloaded the energia Enrf24 library.  The stellaris passes all the blink tests with energia, so I loaded up the txdemo, imported the Enrf24 library, and hit upload and got the following:

 

 

Enrf24_TXdemo.ino:9:14: error: 'P2_0' was not declared in this scope

Enrf24_TXdemo.ino:9:20: error: 'P2_1' was not declared in this scope
Enrf24_TXdemo.ino:9:26: error: 'P2_2' was not declared in this scope
 
Must be this line that is bombing:
 
Enrf24 radio(P2_0, P2_1, P2_2);  // P2.0=CE, P2.1=CSN, P2.2=IRQ

 

I'm guessing I somehow need to define the Stellaris pins...any hints?
 
Apologies if this is not the right thread to post to.
 
Thanks in advance.

Share this post


Link to post
Share on other sites

With some schematic tracing and launchpad pin correlation, here is what I found:

 

nrf24l01                   nrf24l01               430G2                   Stellaris 

boosterpack              Signal             Launchpad              Launchpad

 

Pin 7                           SCLK                 P1.5                       SCK(2)

Pin 8                            CE                    P2.0                       PA_5

Pin 9                           CSN                   P2.1                       PA_6

Pin 10                         IRQ                    P2.2                       PA_7

Pin 14                         MISO                 P1.6                       MISO(2)

Pin 15                         MOSI                 P1.7                       MOSI(2)

 

SPI(2) is the default SPI on the Stellaris

 

so I modified the sketch to add the following:

// Add Stellaris Pin mapping
#define P2_0   PA_5     // CE
#define P2_1   PA_6     // CSN
#define P2_2   PA_7     // IRG

Now the Sketch compiles...next, see if it all works!

Share this post


Link to post
Share on other sites

Ah yes, actually I shouldn't be using Px_y notation anyhow cause the boosterpack pins are meant to be referenced by number.

 

Sent from my Galaxy Note II with Tapatalk 4

Share this post


Link to post
Share on other sites

Fwiw, finally got off my ass and tested one of the SI24R1 modules I bought recently.  Got a 20pk of them from China... these are "enhanced" clones of the nRF24L01+ made by a Taiwanese company supposedly, they're available for a similarly dirt-cheap price as the nRF24L01+ modules with the same look, pinout & PCB trace antenna, but one fancy feature is a new +7dBm TX mode.

 

My Enrf24 library has supported this for a while now, but I hadn't tested it with live hardware 'til now.  I'm pleased to say it seems to work.  I made a simple test node with a LaunchPad, Nordic boosterpack and SI24R1 module, then tried at -6dBm, 0dBm and 7dBm with the node behind the concrete foundation wall where I had noticed packet loss start to occur at 0dBm.  Indeed at 0dBm it was losing ~50-75% of the frames, -6dBm a bit more, but at 7dBm it was only losing <25% on average.  Crude test, but seems to validate it.  I didn't test it side-by-side with an authentic nRF24L01+ @ 0dBm though ... perhaps another day.

 

Also, everything I read about it indicated the need to do some funky stuff with the CE pin and waiting longer for it to wake up (due to some sort of silicon bug).  I don't do that in my library, but my wakeup delay is already a bit conservative/long, and it seems to work fine.

bluehash likes this

Share this post


Link to post
Share on other sites

So it occurred to me that I might have made a small change or 2 in the last ~1 year since I posted a release zipfile of this code, and since energia.nu now has a link to this thread I'm going to post the latest code up here & change the first post to point here.

Enrf24_v1_8.zip

sinhtran03 and reaper7 like this

Share this post


Link to post
Share on other sites

Just thought I'd check in here and say THANK YOU! Excellent library, easy to use, easy to set up, etc.

I have it working now, sending packets from a g2553 to a Tiva-C, works perfectly.

 

I used the pin map chart Maddox675 posted, as I bought the modules alone rather than with a boosterpack.

spirilis likes this

Share this post


Link to post
Share on other sites

I've been working with this library some more, and I've run into an issue.

It only seems to work correctly if Serial.begin() is called.

I can remove the dump_radio_status bits and everything that actually uses serial and it still works just fine, but if I take out Serial.begin the radio does not function.

It compiles just fine, but nothing comes out of the radio.

 

I looked at the library a little bit but didn't see anything obvious, no huge shock there as it compiles.

My guess is that it's something in the serial/i2c/spi hardware, but I haven't tested this.

 

It came up as I'm trying to convince the radio to run on a 2452 and am using the timer for other things, so timerserial is out. Compiled and ran it, but nothing came out of the radio. Changed boards in Energia, stuck a 2553 into the launchpad, recompiled/uploaded, and it didn't work either.

Added Serial.begin() and nothing else, and it works great.

 

I'm happy to do more testing, but I'm short on directions to investigate.

Share this post


Link to post
Share on other sites

I've been working with this library some more, and I've run into an issue.

It only seems to work correctly if Serial.begin() is called.

I can remove the dump_radio_status bits and everything that actually uses serial and it still works just fine, but if I take out Serial.begin the radio does not function.

It compiles just fine, but nothing comes out of the radio.

 

I looked at the library a little bit but didn't see anything obvious, no huge shock there as it compiles.

My guess is that it's something in the serial/i2c/spi hardware, but I haven't tested this.

 

It came up as I'm trying to convince the radio to run on a 2452 and am using the timer for other things, so timerserial is out. Compiled and ran it, but nothing came out of the radio. Changed boards in Energia, stuck a 2553 into the launchpad, recompiled/uploaded, and it didn't work either.

Added Serial.begin() and nothing else, and it works great.

 

I'm happy to do more testing, but I'm short on directions to investigate.

Wow weird, will have to test that later. I do know SPI.begin() needs to be called beforehand but I'm not sure what Serial.begin() would do for it.

 

Sent from my Galaxy Note II with Tapatalk 4

bobnova likes this

Share this post


Link to post
Share on other sites

OK Now I'm really confused.

I sat down to work with this some more, and the code that did not work earlier this evening without Serial.begin now works without it.

I have absolutely no idea why, or what changed.

I'm confused now.

This is what I get for posting I guess!

 

The especially confusing part is that I've run into this twice, the first time I put off more testing and posting about it, then forgot about it and didn't remember till earlier today.

 

I'll keep poking it and see if I can figure out what the deal is/was.

 

EDIT:

 

I'm a doofus. I think it was a combination of things not actually Serial.begin() related.

I have a 500ms delay after I call serial.begin to give the serial window time to open after uploading.

That delay was inadvertently solving a completely unrelated bootup problem where the MCU and the radio would come alive at different times on powerup on the specific (non-launchpad) PCB I was using earlier. It has a very intelligent, inrush limiting, boost converter. I think the MSP was kicking off before the NRF24 and was zipping past / crashing in the nrf initialization process. The delay gave the boost converter time to get vcc up to >2v so the radio was happy.

An additional factor may have been my swapping between 2553 and 2452, it turns out that Energia is totally happy to compile for a 2452 and upload it to a 2553. Whether that kills things or not I don't know, but I don't see it helping.

 

So yeah, false alarm on the Serial.begin front, sorry about that!

spirilis likes this

Share this post


Link to post
Share on other sites

Brand new to using the msp430...Spirilis, when I try to run the TX example code, I get an error reading "fatal error: avr/pgmspace.h: No such file or directory".  It seems the SPI library is attempting to call this file but isn't finding anything.  In fact, any time I try to use SPI.h, even outside of this example, nothing runs...Do you know a way around this?

 

Thanks!

Share this post


Link to post
Share on other sites

Brand new to using the msp430...Spirilis, when I try to run the TX example code, I get an error reading "fatal error: avr/pgmspace.h: No such file or directory".  It seems the SPI library is attempting to call this file but isn't finding anything.  In fact, any time I try to use SPI.h, even outside of this example, nothing runs...Do you know a way around this?

 

Thanks!

Since the error mentions "avr" I think you have set your target device to some AVR chip instead of the correct msp430 target board.

Share this post


Link to post
Share on other sites

Brand new to using the msp430...Spirilis, when I try to run the TX example code, I get an error reading "fatal error: avr/pgmspace.h: No such file or directory". It seems the SPI library is attempting to call this file but isn't finding anything. In fact, any time I try to use SPI.h, even outside of this example, nothing runs...Do you know a way around this?

 

Thanks!

That's definitely not my library doing it. This is with Energia right?

 

Sent from my Galaxy Note II with Tapatalk 4

Share this post


Link to post
Share on other sites

Yes, this is with Energia, and I have the board set to MSP430G2231 (my chip) under Tools-->Board-->MSP430G2231

It doesn't seem like your library, but SPI.h.  I was just wondering if this is an issue any of you guys have dealt with before while trying to use the nRF.

Share this post


Link to post
Share on other sites

Yes, this is with Energia, and I have the board set to MSP430G2231 (my chip) under Tools-->Board-->MSP430G2231

It doesn't seem like your library, but SPI.h.  I was just wondering if this is an issue any of you guys have dealt with before while trying to use the nRF.

Have you installed some sort of alternate SPI library?  There are no instances within Energia's codebase of "avr/pgmspace.h" anywhere (beyond some examples that had such a line commented out).

Share this post


Link to post
Share on other sites

Thanks - I think I did actually have another SPI.h in my directory...now I'm getting an error that I think means the library is to big to fit on the g2231, I will probably try switching to the g2553.

Share this post


Link to post
Share on other sites

That's better - Yeah to be quite honest I don't think Energia is useful for the G2231 et al due to its size.

 

Sent from my Galaxy Note II with Tapatalk 4

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now