
Some time ago, low-cost (from $ 6) nRF24LE1 radio modules with a built-in microcontroller were mentioned on the Habré. On these radio modules, the
COOLRF guys planned to carry out their project, but in the end “moved” to the more expensive Atmega128RFA1 chip, and nRF24LE1, as I understood, moved the other party to the second.
In the article we will consider the possibility of flashing the radio module through Raspberry PI and USBasp as well as a couple of examples of C code.
Description nRF24LE1
There are 3 variants of the chip case: QFN24 (4 × 4 mm), QFN32 (5 × 5 mm), QFN48 (7 × 7 mm). And the I2C, UART, SPI periphery of each variant are on different conclusions (see datasheet from 131 pages). Here I will review the QFN32 option and the technical specifications will apply to it.
The radio transmission part is completely analogous to the “brainless” version of the nRF24L01 +:
2.4 GHz, 125 channels. Supported speeds of 250kbps, 1Mbps and 2Mbps, etc.
')
The built-in 8051-compatible microcontroller has the following parameters:
- Clock frequency 16 MHz. Frequency can be controlled (reduced to 125 KHz) in real time.
- Available flash memory for the program 16kb.
- RAM (RAM) memory 1 kb.
- 1 Kb NVRAM (EEPROM memory)
- 7 pins support 6..12 bit ADC.
- Two eight-bit PWM (PWM) outputs.
- And also there are interfaces: I2C, UART, SPI.
- Power supply 1.9V ... 3.6V.
- Programming via slave SPI.
Programming nRF24LE1 via Raspberry PI
It is possible to flash the nRF24LE1 through a “native” programmer, which is relatively expensive - about $ 30 on Ebay. I certainly did not like the price, and on the Internet I found a version of the programmer based on Raspberry PI
github.com/derekstavis/nrf24le1-libbcm2835 . The source code of the programmer was slightly modified and Russified - it was necessary to translate from Portuguese. The modified version can be downloaded from the link at the end of the article.
To program the radio module, you must connect the SPI pins according to the table:

The PROG nRF24LE1 output must be connected to the GPIO 24 pin on the Raspberry PI. FCSN is connected similarly to CE0 (pin 8). Reset is pulled up by a plus. Do not forget to connect GND to minus and VDD to + 3.3v.
The pin numbering card of the radio module may be different (due to the different chip package and PCB layout) and usually this information can be found in the same place where the nRF24LE1 is sold, for example, when buying on Ebay, the numbering card is indicated on the product page.
To fill the firmware, use the compiled program nrf24le1 using the following commands:
- ./nrf24le1 test - displays test information nRF24LE1 (InfoPage).
- ./nrf24le1 write - flush the main.bin file located in the same folder in nRF24LE1.
- ./nrf24le1 read will create a firmware dump from nRF24LE1 under the name main-dump.bin.
Programming nRF24LE1 via USBasp
After studying the version of the firmware through Raspberry PI, its own version was developed more simple, which can be implemented by any user who program AVR microcontrollers and has a USBasp programmer in service. I
mentioned this programmer earlier, having implemented several different devices on it, including the nRF24L01-USB.
For this idea, the same source code of the programmer under Raspberry PI was used. And USBasp is reprogrammed to a USB-SPI adapter using the V-USB library.
USBasp based programmer is relatively slow — all 16kb firmware. "Poured" in 12 seconds, but this is offset by the price - yet the price of this programmer is $ 3, not $ 30.
Connect nRF24LE1 to USBasp in the following order, according to the numbering of the ten-pin connector:

By the way, is it unclear whether the nRF24LE1 pins are 5 volt tolerant and whether there are dividers on the resistors needed to match the levels between nRF24LE1 and USBasp. As a result, I did not use dividers and did not receive any negative consequences - you can also not install dividers, but at your own peril and risk. For example, nRF24L01 + pins are tolerant and allow connection to 5 volt microcontrollers.
All programming steps are similar to programming through the Raspberry PI.
We write the first programs on nRF24LE1
For writing the program, I used the free cross-platform compiler SDCC
sdcc.sourceforge.net .
The nRF24LE1 has an
SDK , where the main functions for working with a microcontroller are described. This
SDK is checked and corrected by me. It is compiled from several sources.
Here is an example of the flashing LED#include <stdint.h> #include <stdio.h> // SDK: #include "src/gpio/src/gpio_pin_configure.c" #include "src/gpio/src/gpio_pin_val_clear.c" #include "src/gpio/src/gpio_pin_val_set.c" #include "delay.h" #include "src/delay/src/delay_us.c" #include "src/delay/src/delay_s.c" #include "src/delay/src/delay_ms.c" void main() { // P0_0 gpio_pin_configure(GPIO_PIN_ID_P0_0, // GPIO_PIN_CONFIG_OPTION_DIR_OUTPUT | GPIO_PIN_CONFIG_OPTION_OUTPUT_VAL_CLEAR | GPIO_PIN_CONFIG_OPTION_PIN_MODE_OUTPUT_BUFFER_NORMAL_DRIVE_STRENGTH); while(1) { gpio_pin_val_set(GPIO_PIN_ID_P0_0); // 1 delay_ms(500); gpio_pin_val_clear(GPIO_PIN_ID_P0_0); // 0 delay_ms(500); } }
Example of LED firing with PWM output #include <stdio.h> // SDK: #include "delay.h" #include "src/delay/src/delay_us.c" #include "src/delay/src/delay_s.c" #include "src/delay/src/delay_ms.c" #include "src/pwm/src/pwm_configure.c" #include "src/pwm/src/pwm_start.c" void main() { int i=0; // 10 , 8 pwm_configure(PWM_CONFIG_OPTION_PRESCALER_VAL_10 || PWM_CONFIG_OPTION_WIDTH_8_BITS); //main program loop while(1) { pwm_start(PWM_CHANNEL_0,i); i++; delay_ms(200); if (i>255) i=0; } }
At the moment I am completing an example for working with nRF24L01-USB. Already implemented reading DHT22 sensor and load management over the air. In the future, I plan to make an approximate analogue of the Arduino RF24 library — it was necessary to finish a couple of functions.
In general, after programming on AVR microcontrollers, the programming of the nRF24LE1 seemed to me not nearly difficult.
UPD: I forgot to mention that the compiler creates a hex file, and programmers need a binary one. To convert the file, you can use the utility
hex2bin . You can write the command hex2bin -p 00 main.ihx to the make file.
What improvised pieces of iron can still be remade for programming nRF24LE1?
Any similar mini Raspberry PI computer, such as Cubieboard, will do.
You can implement a programmer on the Arduino. Maybe I'll do this option.
Any microcontroller with USB hardware support, for example STMs.
Source codes and example:
Raspberry PI ProgrammerProgrammer on USBasp (updated 5/02/14)
Sdkled_delayDatasheetMaybe I missed something and questions remained - write in the comments.