RepositoryCGEGeorgia
HardwareLevel

HardwareLevel/stm32_hal_nrf24_library

NRF24 library for STM32 HAL projects.

58stars
8forks
2issues
2views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: stm32f103

#1 Repository of the week

2
TINIX TRENDING·Topic: stm32hal

#2 Repository of the week

2
TINIX TRENDING·Topic: stm32cubeide

#2 Repository of the week

NRF24 STM32 HAL Library

This library provides functions to interface the NRF24L01+ transceiver module using STM32 HAL (Hardware Abstraction Layer). It supports features such as dynamic payload length (DPL), automatic acknowledgment (ACK), and various data rates.

Tutorial on youtube

Features

  • Dynamic Payload Length (DPL)

  • Automatic Acknowledgment (ACK)

  • Configurable Data Rates (250 kbps, 1 Mbps, 2 Mbps)

  • CRC Configuration (1-byte or 2-byte)

  • RF signal power control (n18dbm, n12dbm, n6dbm, _0dbm)

  • RF channel selection

  • Pipes control, such as: address changing, closiing/opening pipes

  • Simple APIs for Transmitting and Receiving Data

Hardware requirements:

  • STM32 microcontroller

  • NRF24L01+ transceiver module

  • STlink programmer

Software requirements:

  • STM32CubeIDE

  • STM32CubeMX

  • STM32CubeProgrammer

Hardware Setup (NRF24L01+ module to STM32)

  • VCC to 3.3V
  • GND to GND
  • CE to GPIO_PIN_x (Configurable)
  • CSN to GPIO_PIN_x (Configurable)
  • SCK to SPI_SCK_PIN
  • MOSI to SPI_MOSI_PIN
  • MISO to SPI_MISO_PIN
  • IRQ (optional) to GPIO_PIN_x (Configurable)

Configurations

At first configure ioc file, you will need one spi and one timer, take in account you should stay in maximum 8mbps spi speed and for timer you just need to select clock source and set PSC value correctly.

WARNING:

You need TIMER which givs ticks in micro seconds(thats how delay_us() function works) so you will need to correctly configure prescaller value(PSC) which is depended on system frequency, for example if you have 64mhz you should set PSC 63 because it gives us 1mhz frequency and 1/1mhz = 1us period time. WITHOUT TIMER, CODE WON'T WORK!!!

Open NRF24_conf.h and select SPI port, CE and CS pins GPIO ports and CE and CS pins.

Getting started

Initialization:

csn_high();

HAL_Delay(5);

ce_low();

nrf24_init();

Configurations:

nrf24_auto_ack_all(auto_ack);
nrf24_en_ack_pld(disable);
nrf24_en_dyn_ack(disable);
nrf24_dpl(disable);

nrf24_set_crc(no_crc, _1byte);

nrf24_tx_pwr(_0dbm);
nrf24_data_rate(_250kbps);
nrf24_set_channel(74);
nrf24_set_addr_width(5);

nrf24_set_rx_dpl(0, disable);
nrf24_set_rx_dpl(1, disable);
nrf24_set_rx_dpl(2, disable);
nrf24_set_rx_dpl(3, disable);
nrf24_set_rx_dpl(4, disable);
nrf24_set_rx_dpl(5, disable);

nrf24_pipe_pld_size(0, PLD_S);

nrf24_auto_retr_delay(0);
nrf24_auto_retr_limit(15);

uint8_t addr[5] = { 0x53, 0x13, 0x01, 0x75, 0x82 };
nrf24_open_tx_pipe(addr);
nrf24_open_rx_pipe(0, addr);

ce_high();

WARNING:

If you want to return register in it's own default value commenting function, with which set value, and after compiling code does not solves this problem because nrf24 memorises most of register configurations even if you power off module. Therefore you must write even default values in this register.

For example if you had enabled crc with "nrf24_set_crc(en_crc, _2byte)" and you want to disable at begining of program you should write new values with "nrf24_set_crc(no_crc, _1byte)" because as i mentioned nrf24 does not returns in default values even after powering off.

Enable/disable DPL:

enable:

nrf24_dpl(enable);

nrf24_set_rx_dpl(pipe, enable);

disable:

nrf24_dpl(disable);

nrf24_set_rx_dpl(pipe, disable);

Enable/disable AUTO_ACK:

enable:

nrf24_auto_ack_all(auto_ack);

disable:

nrf24_auto_ack_all(no_auto_ack); 

Enabled/disabled auto_ack on each pipe individualy:

enable:

nrf24_auto_ack(pipe, auto_ack);

disable:

nrf24_auto_ack(pipe, no_auto_ack);

nrf24_auto_retr_delay(0);
nrf24_auto_retr_limit(15);

Enable/disable ACK with payload:

enable:

nrf24_auto_ack_all(auto_ack);
nrf24_en_ack_pld(enable);

nrf24_auto_retr_delay(0);
nrf24_auto_retr_limit(15);

disable:

nrf24_auto_ack_all(auto_ack);
nrf24_en_ack_pld(disable);

nrf24_auto_retr_delay(0);
nrf24_auto_retr_limit(15);

Enable/disable and configure CRC:

nrf24_set_crc(en_crc, _1byte);

//First argument can be set as en_crc, which enables CRC, or no_crc, which disables CRC.
//As second argument can be used _1byte or _2byte.

Set TX RF power:

nrf24_tx_pwr(_0dbm);

//Can be set used:
//    n18dbm = 0 -> MIN
//    n12dbm = 1
//    n6dbm  = 2
//    _0dbm  = 3 -> MAX

Set data rate:

nrf24_data_rate(_250kbps);

//Can be set used:
//    _1mbps   = 0
//    _2mbps   = 1
//    _250kbps = 2

Set channel:

nrf24_set_channel(90);

//Can be used from 0 to 126 which is equivalent of 2400mhz to 2525mhz.
//1 = 1mhz

Set payload size on each pipe:

nrf24_pipe_pld_size(pipe, payload_size);

//pipe can be from 0 to 5

//payload_size can be from 1 to 32

Set Delay betwen Auto-retransmissions:

nrf24_auto_retr_delay(0);

//Can be set from 0 to 15.

Set Auto-retransmissions limit:

nrf24_auto_retr_limit(15);

//Can be set from 0 to 15

Transmit:

1.Without ack payload:

uint8_t dataT[PLD_SIZE] = {"Hello"};
nrf24_transmit(dataT, sizeof(dataT));

2.With ack payload:

nrf24_auto_ack_all(auto_ack);
nrf24_en_ack_pld(enable);

//and other configurations as well

uint8_t dataT[PLD_SIZE] = {"Hello"};
uint8_t tx_ack_pld[PLD_SIZE];

uint8_t val = nrf24_transmit(dataT, sizeof(dataT));

if(val == 0){
	nrf24_receive(tx_ack_pld, sizeof(tx_ack_pld));
}

3.With NO_ACK command:

nrf24_auto_ack_all(auto_ack);
nrf24_en_ack_pld(enable);
nrf24_en_dyn_ack(enable);

//and other configurations as well

uint8_t dataT[PLD_SIZE] = {"Hello"};
nrf24_transmit_no_ack(dataT, sizeof(dataT));

4.With ACK_PLD and IRQ

nrf24_transmit(dataT, sizeof(dataT));

if(irq == 1){
uint8_t stat = nrf24_r_status();

if(stat & (1 << TX_DS)){
	nrf24_receive(tx_ack_pld, sizeof(tx_ack_pld));
}else if(stat & (1 << MAX_RT)){
	nrf24_flush_tx();
	nrf24_clear_rx_dr();
}
irq = 0;
}

Receive:

1,Without ack payload:

uint8_t dataR[PLD_SIZE];

nrf24_listen();

if(nrf24_data_available()){
   nrf24_receive(dataR, sizeof(dataR));
}

2.With transmit ack payload:

nrf24_auto_ack_all(auto_ack);
nrf24_en_ack_pld(enable);

//and other configurations as well


uint8_t dataR[PLD_SIZE];
uint8_t rx_ack_pld[PLD_SIZE] = {"OK"}

nrf24_listen();

if(nrf24_data_available()){
nrf24_receive(dataR, sizeof(dataR));
nrf24_transmit_rx_ack_pld(0, rx_ack_pld, sizeof(rx_ack_pld));
}

3.With ACK_PLD and IRQ

if(irq == 1){
uint8_t stat = nrf24_r_status();

if(stat & (1 << RX_DR)){ 
	nrf24_receive(dataR, sizeof(dataR));
	nrf24_transmit_rx_ack_pld(0, rx_ack_pld, sizeof(rx_ack_pld));
}
irq = 0;
}

Similar Projects

Discover other similar projects and AI models.

RepositoryC
mokhwasomssi/stm32_hal_nrf24l01p

nRF24L01+ library with STM32 HAL driver

122
Aug 26, 2021
RepositoryC
mokhwasomssi/stm32_hal_nrf24l01p

nRF24L01+ library with STM32 HAL driver

122
Aug 26, 2021
RepositoryC
MaJerle/stm32-cube-cmake-vscode

STM32, VSCode and CMake detailed tutorial

727
Sep 20, 2025
RepositoryC
miniwinwm/BluePillDemo

A collection of small example projects tailored for the Blue Pill board created in STM32CubeIDE. No further updates.

156
May 14, 2023
RepositoryC
decrazyo/unifying

FOSS re-implementation of the Logitech Unifying protocol

123
Nov 26, 2024
RepositoryC++
Yveaux/NRF24_Sniffer

Sniffer for Nordic NRF24L01+ modules with MySensors support

169
Feb 27, 2025
RepositoryC++
mcore1976/nrf24-bt-jammer

Bluetooth jammer based on NRF24L01 module and Arduino Raspberry Pico RP2040

57
Jul 20, 2026
RepositoryC
flipperdevices/flipperzero-firmware

Flipper Zero firmware source code

17.1k
Nov 27, 2026
RepositoryC
stlink-org/stlink

Open source STM32 MCU programming toolset

5.3k
Oct 9, 2026