Library 17- nRF24L01+ for STM32F4

17th library is here. I will show how to basic communicate with 2 nRF24L01+ RF transceivers.

The Nordic nRF24L01+ is a highly integrated, ultra low power (ULP) 2Mbps RF transceiver IC for the 2.4GHz ISM (Industrial, Scientific and Medical) band. With peak RX/TX currents lower than 14mA, a sub μA power down mode, advanced power management, and a 1.9 to 3.6V supply range, the nRF24L01+ provides a true ULP solution enabling months to years of battery life from coin cell or AA/AAA batteries. The Enhanced ShockBurst™ hardware protocol accelerator offloads time critical protocol functions from the application microcontroller enabling the implementation of advanced and robust wireless connectivity with low cost 3rd-party microcontrollers.

The Nordic nRF24L01+ integrates a complete 2.4GHz RF transceiver, RF synthesizer, and baseband logic including the Enhanced ShockBurst™ hardware protocol accelerator supporting a high-speed SPI interface for the application controller. No external loop filter, resonators, or VCO varactor diodes are required, only a low cost ±60ppm crystal, matching circuitry, and antenna.

The nRF24L01+ is available in a compact 20-pin 4 x 4mm QFN package.

nRF24L01+ has 6 data pypes. This means, that can receive data simultaneously from 5 nRF24L01+. My library uses only 1 data pype, so 2 nRF24L01s can be connected together and communicate. Every of them has an unique 5bytes long address, which is software selectable.

For example below, i used nRF24L01+ modules from ebay (link), their pinout is belowNRF2L01+ pinout

Connect NRF24L01 to discovery board
NRF24L01+ Discovery board Description
GND GND Ground
VCC 3.3V 3.3V
CE PD8 RF activated pin
CSN PD7 SPI3 Pinspack 2 CSN pin
SCK PC10 SPI3 Pinspack 2 SCK pin
MOSI PC12 SPI3 Pinspack 2 MOSI pin
MISO PC11 SPI3 Pinspack 2 MISO pin
IRQ Not used Interrupt pin. Goes low when active

nRF24L01+ Library

Features

  • Support for nRF24L01+
  • Max 32bytes of payload size
  • User selectable Own and TX address
  • up to 15 auto retransmissions with auto ACK
  • Get transmission status (sent ok, message lost, still sending)
  • Channel selectable from 0 to 125 (2.4 to 2.525GHz)
  • Data rate selectable, 2Mbps, 1Mbps or 250kbps
  • Output power selectable, -18dBm, -12dBm, -6dBm or 0dBm
  • Interrupt pin activated on nRF24L01+

Future planing

In near future I’m planning to make a nRF24L01+ wireless network.

Library Dependencies

  • CMSIS
    • STM32F4xx
    • STM32F4xx RCC
    • STM32F4xx GPIO
    • STM32F4xx SPI
  • TM
    • TM SPI
    • TM GPIO
    • defines.h

Functions and enumerations

Example

In example, I used 2 nRF24L01+ modules to communicate. One was connected to my STM32F4 discovery, second to STM32F429.

In example below, “transmitter” sends 32bytes of data to receiver and starts counting time. If sent was successfully, data will be returned from receiver. Time needed for that is displayed on Terminal with USART.

Code has comments, so I think it will be understandable.

Bottom are use “transmitter” and “receiver”, but remember: nRF24L01+ can be both, transmitter and receiver!

Make sure, that addresses match each other. On one side “TX” address is on other side “My” address.

Transmitter code

NRF24L01+ transmitter result

NRF24L01+ transmitter result


Receiver code

Projects available on Github, download library below.

On my Github you will also found examples with interrupts for send and receive data.

tilz0R

Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...