Author Topic: Setting Up the nRF24L01 for Transmitting, and Receiving  (Read 678 times)

0 Members and 1 Guest are viewing this topic.

Offline Kalcifer

  • Regular Contributor
  • *
  • Posts: 69
  • Country: ca
Setting Up the nRF24L01 for Transmitting, and Receiving
« on: May 11, 2021, 06:00:48 am »
I have one of those nRF24L01 ~2.4GHz transmitter modules, as seen here:
http://www.hobbyandyou.com/content/images/thumbs/0002081_nrf24l01-24ghz-wireless-transceiver-module-for-arduino.jpeg.
I have been having some trouble getting it to work (data not being received), so I wanted to make sure that I am, at least, using the right method for configuring the device(s) for use; I want to make sure that I am understanding the datasheet correctly. So, my setup is as follows:

Receiver:
1. Enter RX mode by setting the PWR_UP bit and the PRIM_RX bit, and bringing the CE pin logic high.
2. Default receive address is used at data pipe 0: 0xE7E7E7E7E7
2. Ensure that the data pipe 0 (using the default address that is used at reset) is enabled to receive 1 byte by writing 1 to RX_PW_P0.

Transmitter:
1. Go into standby-2 mode to wait for transmit data by setting the PWR_UP bit, clearing the PRIM_RX bit, and bringing the CE pin logic high.
2. Default transmit address at reset is used: 0xE7E7E7E7E7

Transmission:
1. Write a byte of data to the transmit payload with 0b00000001 written to W_TX_PAYLOAD
2. from my understanding, this should automatically start the transmission of data
3. read the received data by reading from R_RX_PAYLOAD

Please let me know if my configuration and usage method is correct.

Thank you.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 1680
  • Country: nl
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #1 on: May 11, 2021, 07:58:30 pm »
My sincerest advise is tho throw the thing in the garbage bin and buy some better hardware.

Years ago I bought a bunch of these things and wrote a driver library from a collection of a bunch of giants before me, but mostly from reading the datasheet about 20 times.
The nRF24L01+ is another chip from the incompatible nRF24L01, and I found the whole thing just horrible.
The designer of that chip had some very distorted ideas of what is useful in such a chip and what is not. They have some "6 pipe" model, which is either not enough or too much, and either way you have to find a way to work around it. It's doing a bunch of buffering and it's very hard to determine what is buffered where and when. I've had the thing lock up, and then after a complete power cyle have it receive messages from before the power cycle. The way their internal synchronization works is very yucky.

I had a short moment to light my interest when I noticed that it had some signal strength measurement, but it's implemented so badly that it's completely useless.

And on top of that. There are some clones on the market and these have some bugs and / or incompatibilities, so you never know what you're working with.

So pay 50ct or a euro more for some other RF breakout board that has some decent hardware on it.

The HopeRF RFM95 and RFM96 are probably much better chips. But probably anything is better than the nRF24 horror.
If you're lucky you can get some "arduino" lib for it to work in 10 minutes or so, but that's because someone else has been banging their heads to the wall for days before you.
« Last Edit: May 11, 2021, 08:04:02 pm by Doctorandus_P »
 

Offline Kalcifer

  • Regular Contributor
  • *
  • Posts: 69
  • Country: ca
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #2 on: May 12, 2021, 04:23:48 am »
My sincerest advise is tho throw the thing in the garbage bin and buy some better hardware.
Perhaps something like an ESP8266 would be good. Those are decently popular it seems. Although, I have looked into it before, and I'm not entirely sure how to go about programming them.

The HopeRF RFM95 and RFM96 are probably much better chips. But probably anything is better than the nRF24 horror.
If you're lucky you can get some "arduino" lib for it to work in 10 minutes or so, but that's because someone else has been banging their heads to the wall for days before you.
I don't have HopeRF chips but I do have a couple of those Semtech SX1278 LoRa module things lying around which seem to be similar in idea to the chips that you mentioned.
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2012
  • Country: us
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #3 on: May 12, 2021, 11:22:01 am »
Here is the general flow I use.  I have the 'Plus' modules.
There is an Arduino library for the nRF24L01+ (RF24 lib)


// CHANGES TO POWER-ON DEFAULTS:
nRF_CONFIG (00h)     = nRF_CRC1|nRF_PwrDn|nRF_PRX (09h)
nRF_SETUP_RETR (04h) = (ARD=500us, ARC=3 retries) (13h)
nRF_RF_SETUP (06h)   = nRF_1Mbps|nRF_PWR0 (06h)


// RECEIVER SETUP:
nRF_RX_ADDR_P0 (0Ah) = (E7E7E7E7E7h)
nRF_RX_ADDR_P1 (0Bh) = (C2C2C2C2C2h)
nRF_TX_ADDR (10h)    = (E7E7E7E7E7h)
nRF_RX_PW_P0 (11h)   = 8
nRF_RX_PW_P1 (12h)   = 8
// Start listening: Power-up and Receive mode
nRF_CONFIG (00h) = nRF_CRC1|nRF_PwrUp|nRF_PRX (0Bh)
delay_us(130)
// Set CE high
CEpin = 1
// Read FIFO status
while ((nFIFO_STATUS & 0x03) != 1) {
   // read payload, nRF_RD_RX_PL (61h)
}


// TRANSMITER SETUP:
nRF_RX_ADDR_P0 (0Ah) = (C2C2C2C2C2h)
nRF_RX_ADDR_P1 (0Bh) = (E7E7E7E7E7h)
nRF_TX_ADDR (10h)    = (C2C2C2C2C2h)
nRF_RX_PW_P0 (11h)   = 8
nRF_RX_PW_P1 (12h)   = 8
// Write payload: Power-up and Transmit mode
nRF_CONFIG (00h) = nRF_CRC1|nRF_PwrUp|nRF_PTX (0Ah)
delay_us(150)
for (int i=0;i<8;i++) {
   // write payload, nRF_WR_TX_PL (A0h)
}
// Strobe CE
CEpin = 1
delay_us(16)
CEpin = 0
« Last Edit: May 12, 2021, 11:31:24 am by MarkF »
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 7189
  • Country: fr
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #4 on: May 12, 2021, 05:15:18 pm »
I've used the nRF24L01+ chip a few years ago, and I don't remember how close to the nRF24L01 it is, nor if your module doesn't actually contain a nRF24L01+, which I'm suspecting.

Anyway, from what I remember, what MarkF showed looks correct to me. If you have any further problem, I may have to take a closer look at my project to give possible additional info.


 

Online janoc

  • Super Contributor
  • ***
  • Posts: 3398
  • Country: fr
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #5 on: May 12, 2021, 06:01:52 pm »
nRF24L01+ is the enhanced version of the original nRF24L01. nRF24L01+ can talk to both nRF24L01+ and nRF24L01 but the nRF24L01 doesn't support some data rates that nRF24L01+ does. The original (non-plus) version hasn't been sold for years, so it is unlikely you would find one in a new module these days.

There is nothing wrong with these radios, no need to hate on them. They work, they are simple to use and widely deployed - e.g. many wireless keyboards/mice that use dongles are based on these chips, as are various cheap drones and toys needing remote control.

However, that is assuming you get the genuine one and a good quality module. The stuff from AliExpress and wherever is a lottery.

There are even fakes/clones of these Nordic radios around:
https://hackaday.com/2015/02/23/nordic-nrf24l01-real-vs-fake/

Oh and do make sure you don't accidentally damage them with 5V - there are 3.3V only (the data pins are 5V tolerant, AFAIK). I had a few of these damaged by a dodgy DC-DC converter module that was letting some voltage spikes in and then the radio was locking up, talking to the host but not transmitting and weird and wonderful stuff like that.


My sincerest advise is tho throw the thing in the garbage bin and buy some better hardware.
Perhaps something like an ESP8266 would be good. Those are decently popular it seems. Although, I have looked into it before, and I'm not entirely sure how to go about programming them.

If you don't mind the roughly 10x power consumption and the need to configure wifi ...

If you need low power (which is likely why you were looking at the nRF24L01+ in the first place), then nRF52 or nRF53 series could be a good fit - ARM Cortex core, radio that can handle Bluetooth Low Energy, Zigbee, ANT, Shockburst (the nRF24L01+ protocol) and many other things and still very low power consumption. E.g. the recently released Apple AirTags use nRF52 SoCs.

« Last Edit: May 12, 2021, 06:07:11 pm by janoc »
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 7189
  • Country: fr
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #6 on: May 12, 2021, 09:30:04 pm »
Agreed, those ICs are actually pretty good. Sure they are barebones - that's what they are meant to be. But yes they draw little power. The protocol is pretty raw. But you can implement your own protocol on top of that. I've seen a project implementing simple BLE with them. AFAIR, Nordic also provides a protocol that you can use with them: Gazell.

I don't get why anyone would suggest using WiFi instead (unless you actually want to connect to an existing network). Talk about waste.

You could otherwise consider BLE if you are after a low power solution with a more sophisticated protocol. TI chips, like the CC2640 (IIRC?) contain an ARM Cortex core and are very low power. I think you can implement something else than BLE with those as well if you're so inclined.


 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 1680
  • Country: nl
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #7 on: May 12, 2021, 10:07:33 pm »
I don't get why anyone would suggest using WiFi instead...

Nobody suggested to use WiFi.
OP asked if that could be a good alternative.

And I agree with the others. WiFi is power hungry.
A part of the power hungryness is because of encryption and key exchange, which needs relatiely much data going to and fro.
Apparerently you can get some decent battery life out of an ESP8266, if it sleeps 99.999% of it's time and does not much communicate in the time it's awake, but it will never be as low as those small radio's.
 

Offline Kalcifer

  • Regular Contributor
  • *
  • Posts: 69
  • Country: ca
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #8 on: May 12, 2021, 10:28:23 pm »
If you need low power (which is likely why you were looking at the nRF24L01+ in the first place), then nRF52 or nRF53 series could be a good fit - ARM Cortex core, radio that can handle Bluetooth Low Energy, Zigbee, ANT, Shockburst (the nRF24L01+ protocol) and many other things and still very low power consumption. E.g. the recently released Apple AirTags use nRF52 SoCs.

Correct, I need decently low power consumption, as well as a somewhat decent range. I need the modules to be able to communicate across a length of my yard (retrieving data from a sensor from about 30 or so meters away. Very little obstructions, only a very slight incline, some shrubs and a fence.). I also really don't want to go through the headache of designing my own antenna and whatnot (that bit of my schooling is a little fuzzy), so the premade module was a good fit for me. Also, I find that really cool that the air tags are using nordic semiconductor chips! I had no idea.
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2012
  • Country: us
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #9 on: May 13, 2021, 12:39:29 am »
I'm using the nRF24L01+ modules in my wireless model railroad throttles.
There is no problem across my basement at 10 meters.
My guess is you can go 20 meters, but 30+ meters is probably pushing their range for the PCB antenna.



There is a high power version with a screw-on antenna that might get you the range you want.

 

Offline Kalcifer

  • Regular Contributor
  • *
  • Posts: 69
  • Country: ca
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #10 on: May 13, 2021, 04:05:39 am »
If you need low power (which is likely why you were looking at the nRF24L01+ in the first place), then nRF52 or nRF53 series could be a good fit - ARM Cortex core, radio that can handle Bluetooth Low Energy, Zigbee, ANT, Shockburst (the nRF24L01+ protocol) and many other things and still very low power consumption. E.g. the recently released Apple AirTags use nRF52 SoCs.

Is the nRF24L01 obsolete?  I took a look on nordic's website, and in the nRF24 section, it says "not recommended for new designs" and then lists the nRF52 series chips as alternatives. Would the nRF52 series chips have improvements in range? They use Bluetooth 5.2 bluetooth low energy. Not sure how that stacks up to the performance of the nRF24 series.
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 2737
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #11 on: May 13, 2021, 09:32:17 am »
My guess is you can go 20 meters, but 30+ meters is probably pushing their range for the PCB antenna.

The PCB antenna is limited as a transmitter, but as a receiver it's pretty decent.



It's all about the antenna really you can do some very long distances if there's nothing in the way...

https://www.youtube.com/c/iforce2d/search?query=NRF24L01%2B

~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Online janoc

  • Super Contributor
  • ***
  • Posts: 3398
  • Country: fr
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #12 on: May 13, 2021, 09:56:10 am »
Is the nRF24L01 obsolete?  I took a look on nordic's website, and in the nRF24 section, it says "not recommended for new designs" and then lists the nRF52 series chips as alternatives. Would the nRF52 series chips have improvements in range? They use Bluetooth 5.2 bluetooth low energy. Not sure how that stacks up to the performance of the nRF24 series.

nRF24 is not really obsolete (as in end of life/not made anymore) but they would want you to phase it out. It is likely going to be around for a long time, though, a lot of products use these radios.

nRF52 does not use BLE. nRF52 is capable of running BLE but not only - it is a multiprotocol radio and with the exception of Bluetooth Classic and Wifi it can probably handle every common wireless protocol.

Not sure what you mean by "performance of the nRF24 series". Bitrate? That's a function of the protocol, both SoCs have 2Mbps capable radios. Shockburst on nrf24L01+ is 250kbps-2Mbps (AFAIK). That's the same on nRF52.

Power consumption? I had nRF52832 take about 6mA while running the full Bluetooth Low Energy/Bluetooth Mesh stack and actively advertising. When sleeping it is down in uA territory. nRF24L01+ takes about 12mA when transmitting. So that's comparable (the different protocol I have used prevents 1:1 comparison here).

Plus nRF52x is has an ARM core with built-in flash you can run your own programs on, nRF24L01+ requires another micro to act as a host because the SoC isn't user programmable.

« Last Edit: May 13, 2021, 10:00:43 am by janoc »
 

Online janoc

  • Super Contributor
  • ***
  • Posts: 3398
  • Country: fr
Re: Setting Up the nRF24L01 for Transmitting, and Receiving
« Reply #13 on: May 13, 2021, 10:15:44 am »
Agreed, those ICs are actually pretty good. Sure they are barebones - that's what they are meant to be. But yes they draw little power. The protocol is pretty raw. But you can implement your own protocol on top of that. I've seen a project implementing simple BLE with them. AFAIR, Nordic also provides a protocol that you can use with them: Gazell.

You can run the same Shockburst protocol even on the nRF52, it is compatible and officially supported.

nRF24 can't run BLE, the radio is "hardwired" and is unable to broadcast/receive data in the required format. It was only "abused" to send BLE advertisement packets with a bit of hackery, so it can act as e.g. the iBeacon style tag. Not much else.

nRF52 can run the following (but not all models - the ones with smaller flash can't run everything due to the size of some of the sw stacks):

- Bluetooth Low Energy
- Bluetooth Mesh (based on BLE but not compatibile with it)
- ZigBee
- Thread (IPv6 based mesh network)
- ANT (very low power protocol used mostly in fitness equipment)
- IEEE 802.15.4 (low level protocol, basis for ZigBee, Thread, 6LoWPAN, SNAP, MiWi ...)
- Shockburst and Enhanced Shockburst (same as nRF24L01+)
- Gazell (proprietary Nordic thing)
- NFC (has a separate antenna for it)

Possibly more, because there are some other protocols that are built on top of  Shockburst or IEEE 802.15.4 that can run on these SoCs. Some parts have also USB, so if you need to build a dongle to interface e.g. a mesh network to a PC, these are ideal parts for it (and, in fact, many BLE dongles contain them for this reason).

If someone wants to mess with this, I would strongly recommend looking at the Zephyr project first instead of trying to work with the Nordic SDKs. It is much easier because you don't have to deal with the Nordic RTOS blob ("softdevice"). Zephyr is completely open source so if anything goes haywire (and it will, especially when implementing complex stuff like BLE or some mesh) it is much easier to debug than getting a hard fault from the softdevice and then wondering where in that binary blob it faulted and why.

https://www.zephyrproject.org/



« Last Edit: May 13, 2021, 10:18:33 am by janoc »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf