Loading...
Searching...
No Matches
NRF24L01+ (NG) 2.4 GHz trasceiver driver

This module contains the driver for the NRF24L01+ (NG) 2.4 GHz transceiver. More...

Detailed Description

This module contains the driver for the NRF24L01+ (NG) 2.4 GHz transceiver.

Files

file  nrf24l01p_ng.h
 Public interface for NRF24L01+ (NG) devices.
 
file  gnrc_netif_nrf24l01p_ng.h
 NRF24L01+ (NG) adaptation for Network interface API.
 
file  nrf24l01p_ng_communication.h
 Functions to communicate with the NRF24L01+ (NG) transceiver via SPI.
 
file  nrf24l01p_ng_constants.h
 Constants from the datasheet of the NRF24L01+ (NG) transceiver.
 
file  nrf24l01p_ng_diagnostics.h
 Functions to print NRF24L01+ (NG) debug information.
 
file  nrf24l01p_ng_netdev.h
 Netdev driver interface for NRF24L01+ (NG) device driver.
 
file  nrf24l01p_ng_params.h
 Board specific configuration for all NRF24L01+ (NG) devices.
 
file  nrf24l01p_ng_registers.h
 Register map of NRF24L01+ (NG) devices.
 
file  nrf24l01p_ng_states.h
 Operation states of NRF24L01+ (NG) devices.
 

Data Structures

struct  nrf24l01p_ng_cfg_t
 Struct that holds all active configuration values. More...
 
struct  nrf24l01p_ng_params_t
 Struct of NRF24L01+ initialization parameters. More...
 
struct  nrf24l01p_ng
 NRF24L01+ device struct. More...
 

Macros

#define NRF24L01P_NG_MIN_ADDR_WIDTH   (3)
 Minimum width of a NRF24L01+ layer-2 address.
 
#define NRF24L01P_NG_MAX_ADDR_WIDTH   (5)
 Maximum width of a NRF24L01+ layer-2 address.
 
#define NRF24L01P_NG_ADDR_WIDTH   NRF24L01P_NG_MAX_ADDR_WIDTH
 Pass the compiler a definition of NRF24L01P_NG_ADDR_WIDTH to configure the layer-2 address width of this transceiver.
 
#define NRF24L01P_NG_BROADCAST_ADDR   { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
 Agreed layer-2 address to send broadcast frames to.
 
#define NRF24L01P_NG_ADDR_P0(dev)   ((dev)->arxaddr.rx_addr_long[NRF24L01P_NG_P0])
 Shortcut to access the address of pipe 0.
 
#define NRF24L01P_NG_ADDR_P1(dev)   ((dev)->arxaddr.rx_addr_long[NRF24L01P_NG_P1])
 Shortcut to access the address of pipe 1.
 
#define NRF24L01P_NG_ADDR_PX_LSB(dev, pipe)   ((dev)->arxaddr.rx_addr_short[(pipe) - 2])
 Shortcut to access the least significant byte of the addresses pipe 2, pipe 3, pipe 4 or pipe 5.
 

Functions

int nrf24l01p_ng_setup (nrf24l01p_ng_t *dev, const nrf24l01p_ng_params_t *params, uint8_t index)
 Setup the NRF24L01+ driver, but perform no initialization.
 
int nrf24l01p_ng_set_enable_pipe (nrf24l01p_ng_t *dev, nrf24l01p_ng_pipe_t pipe, bool enable)
 Enable or disable data pipe pipe.
 
int nrf24l01p_ng_get_enable_pipe (nrf24l01p_ng_t *dev, nrf24l01p_ng_pipe_t pipe, bool *enable)
 Query if data pipe pipe is enabled.
 
int nrf24l01p_ng_set_air_data_rate (nrf24l01p_ng_t *dev, nrf24l01p_ng_rfdr_t data_rate)
 Configure air data rate.
 
uint16_t nrf24l01p_ng_get_air_data_rate (const nrf24l01p_ng_t *dev, nrf24l01p_ng_rfdr_t *data_rate)
 Get currently configured data rate.
 
int nrf24l01p_ng_set_crc (nrf24l01p_ng_t *dev, nrf24l01p_ng_crc_t crc)
 Configure CRC length.
 
uint8_t nrf24l01p_ng_get_crc (const nrf24l01p_ng_t *dev, nrf24l01p_ng_crc_t *crc)
 Get currently configured CRC length.
 
int nrf24l01p_ng_set_tx_power (nrf24l01p_ng_t *dev, nrf24l01p_ng_tx_power_t power)
 Configure Tx trasceiver power.
 
int8_t nrf24l01p_ng_get_tx_power (const nrf24l01p_ng_t *dev, nrf24l01p_ng_tx_power_t *power)
 Get currently configured Tx transceiver power.
 
int nrf24l01p_ng_set_channel (nrf24l01p_ng_t *dev, uint8_t channel)
 Set transceiver channel.
 
uint8_t nrf24l01p_ng_get_channel (const nrf24l01p_ng_t *dev)
 Get currently configured transceiver channel.
 
int nrf24l01p_ng_set_rx_address (nrf24l01p_ng_t *dev, const uint8_t *addr, nrf24l01p_ng_pipe_t pipe)
 Set Rx address of a certain data pipe.
 
int nrf24l01p_ng_get_rx_address (const nrf24l01p_ng_t *dev, uint8_t *addr, nrf24l01p_ng_pipe_t pipe)
 Get current Rx address of a certain data pipe.
 
int nrf24l01p_ng_set_max_retransm (nrf24l01p_ng_t *dev, uint8_t max_rt)
 Configure maximum number of retransmissions for ESB.
 
uint8_t nrf24l01p_ng_get_max_retransm (const nrf24l01p_ng_t *dev)
 Get currently configured number of maximum retransmissions for ESB.
 
int nrf24l01p_ng_set_retransm_delay (nrf24l01p_ng_t *dev, nrf24l01p_ng_ard_t rt_delay)
 Set retransmission delay for ESB.
 
uint16_t nrf24l01p_ng_get_retransm_delay (const nrf24l01p_ng_t *dev, nrf24l01p_ng_ard_t *rt_delay)
 Get retransmission delay for ESB.
 
int nrf24l01p_ng_set_state (nrf24l01p_ng_t *dev, nrf24l01p_ng_state_t state)
 Put device into sleep mode(NRF24L01P_NG_STATE_POWER_DOWN), standby mode (NRF24L01P_NG_STATE_STANDBY_1), or Rx mode (NRF24L01P_NG_STATE_RX_MODE)
 
nrf24l01p_ng_state_t nrf24l01p_ng_get_state (const nrf24l01p_ng_t *dev)
 Get current device state.
 
void nrf24l01p_ng_eui_get (const netdev_t *dev, uint8_t *eui)
 Retrieve a unique layer-2 address for an nrf24l01p_ng instance.
 

Macro Definition Documentation

◆ NRF24L01P_NG_ADDR_P0

#define NRF24L01P_NG_ADDR_P0 (   dev)    ((dev)->arxaddr.rx_addr_long[NRF24L01P_NG_P0])

Shortcut to access the address of pipe 0.

Definition at line 70 of file nrf24l01p_ng.h.

◆ NRF24L01P_NG_ADDR_P1

#define NRF24L01P_NG_ADDR_P1 (   dev)    ((dev)->arxaddr.rx_addr_long[NRF24L01P_NG_P1])

Shortcut to access the address of pipe 1.

Definition at line 75 of file nrf24l01p_ng.h.

◆ NRF24L01P_NG_ADDR_PX_LSB

#define NRF24L01P_NG_ADDR_PX_LSB (   dev,
  pipe 
)    ((dev)->arxaddr.rx_addr_short[(pipe) - 2])

Shortcut to access the least significant byte of the addresses pipe 2, pipe 3, pipe 4 or pipe 5.

The other bytes are shared with the address of pipe 1

Definition at line 83 of file nrf24l01p_ng.h.

◆ NRF24L01P_NG_ADDR_WIDTH

#define NRF24L01P_NG_ADDR_WIDTH   NRF24L01P_NG_MAX_ADDR_WIDTH

Pass the compiler a definition of NRF24L01P_NG_ADDR_WIDTH to configure the layer-2 address width of this transceiver.

Definition at line 54 of file nrf24l01p_ng.h.

◆ NRF24L01P_NG_BROADCAST_ADDR

#define NRF24L01P_NG_BROADCAST_ADDR   { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }

Agreed layer-2 address to send broadcast frames to.

The broadcast address will be assigned to pipe 0.

Definition at line 65 of file nrf24l01p_ng.h.

◆ NRF24L01P_NG_MAX_ADDR_WIDTH

#define NRF24L01P_NG_MAX_ADDR_WIDTH   (5)

Maximum width of a NRF24L01+ layer-2 address.

Definition at line 47 of file nrf24l01p_ng.h.

◆ NRF24L01P_NG_MIN_ADDR_WIDTH

#define NRF24L01P_NG_MIN_ADDR_WIDTH   (3)

Minimum width of a NRF24L01+ layer-2 address.

Definition at line 42 of file nrf24l01p_ng.h.

Function Documentation

◆ nrf24l01p_ng_eui_get()

void nrf24l01p_ng_eui_get ( const netdev_t dev,
uint8_t *  eui 
)

Retrieve a unique layer-2 address for an nrf24l01p_ng instance.

Note
This function has attribute((weak)) so you can override this, e.g. to construct an address. By default luid_get_lb is used.
Parameters
[in]devThe device descriptor of the transceiver
[out]euiDestination to write the address to

◆ nrf24l01p_ng_get_air_data_rate()

uint16_t nrf24l01p_ng_get_air_data_rate ( const nrf24l01p_ng_t dev,
nrf24l01p_ng_rfdr_t data_rate 
)

Get currently configured data rate.

Parameters
[in]devNRF24L01+ device handle
[out]data_rateConfiguration data rate value (may be NULL)
Returns
Data rate in [kbit/s]

◆ nrf24l01p_ng_get_channel()

uint8_t nrf24l01p_ng_get_channel ( const nrf24l01p_ng_t dev)

Get currently configured transceiver channel.

Parameters
[in]devNRF24L01+ device handle
Returns
Transceiver channel

◆ nrf24l01p_ng_get_crc()

uint8_t nrf24l01p_ng_get_crc ( const nrf24l01p_ng_t dev,
nrf24l01p_ng_crc_t crc 
)

Get currently configured CRC length.

Parameters
[in]devNRF24L01+ device handle
[out]crcConfiguration crc value (may be NULL)
Returns
Current CRC length

◆ nrf24l01p_ng_get_enable_pipe()

int nrf24l01p_ng_get_enable_pipe ( nrf24l01p_ng_t dev,
nrf24l01p_ng_pipe_t  pipe,
bool *  enable 
)

Query if data pipe pipe is enabled.

Parameters
[in]devNRF24L01+ device handle
[in]pipePipe index
[out]enableIf pipe is enabled or disabled
Return values
0Success
-EINVALBad pipe index

◆ nrf24l01p_ng_get_max_retransm()

uint8_t nrf24l01p_ng_get_max_retransm ( const nrf24l01p_ng_t dev)

Get currently configured number of maximum retransmissions for ESB.

Parameters
[in]devNRF24L01+ device handle
Returns
Maximum number of retransmissions

◆ nrf24l01p_ng_get_retransm_delay()

uint16_t nrf24l01p_ng_get_retransm_delay ( const nrf24l01p_ng_t dev,
nrf24l01p_ng_ard_t rt_delay 
)

Get retransmission delay for ESB.

Parameters
[in]devNRF24L01+ device handle
[out]rt_delayConfiguration retransmission delay value
Returns
Retransmission delay in [us]

◆ nrf24l01p_ng_get_rx_address()

int nrf24l01p_ng_get_rx_address ( const nrf24l01p_ng_t dev,
uint8_t *  addr,
nrf24l01p_ng_pipe_t  pipe 
)

Get current Rx address of a certain data pipe.

addr must be at least NRF24L01P_NG_ADDR_WIDTH wide.

Parameters
[in]devNRF24L01+ device handle
[out]addrRx address
[in]pipePipe index
Returns
Address width
Return values
-EINVALBad pipe index

◆ nrf24l01p_ng_get_state()

nrf24l01p_ng_state_t nrf24l01p_ng_get_state ( const nrf24l01p_ng_t dev)

Get current device state.

Parameters
[in]devNRf24L01+ device handle
Returns
Device state

◆ nrf24l01p_ng_get_tx_power()

int8_t nrf24l01p_ng_get_tx_power ( const nrf24l01p_ng_t dev,
nrf24l01p_ng_tx_power_t power 
)

Get currently configured Tx transceiver power.

Parameters
[in]devNRF24L01+ device handle
[out]powerConfiguration Tx power value
Returns
Tx power in [dbm]

◆ nrf24l01p_ng_set_air_data_rate()

int nrf24l01p_ng_set_air_data_rate ( nrf24l01p_ng_t dev,
nrf24l01p_ng_rfdr_t  data_rate 
)

Configure air data rate.

Parameters
[in]devNRF24L01+ device handle
[in]data_rateData rate configuration value
Return values
0Success
-EINVALBad data rate value
-EAGAINCurrent state does not permit changing data rate

◆ nrf24l01p_ng_set_channel()

int nrf24l01p_ng_set_channel ( nrf24l01p_ng_t dev,
uint8_t  channel 
)

Set transceiver channel.

Parameters
[in]devNRF24l01+ device handle
[in]channelChannel [0; 15]
Return values
0Success
-EINVALBad channel
-EAGAINCurrent state does not permit switching channel

◆ nrf24l01p_ng_set_crc()

int nrf24l01p_ng_set_crc ( nrf24l01p_ng_t dev,
nrf24l01p_ng_crc_t  crc 
)

Configure CRC length.

Parameters
[in]devNRF24L01+ device handle
[in]crcConfiguration CRC value
Return values
0Success
-EINVALBad CRC configuration value
-ENOTSUPCRC length not supported
-EAGAINCurrent state does not permit changing CRC length

◆ nrf24l01p_ng_set_enable_pipe()

int nrf24l01p_ng_set_enable_pipe ( nrf24l01p_ng_t dev,
nrf24l01p_ng_pipe_t  pipe,
bool  enable 
)

Enable or disable data pipe pipe.

     If @p pipe should be enabled, it is advised to
     set an address in advance.
     @see nrf24l01p_ng_set_rx_addr
     For Enhanced ShockBurst, auto ACK and dynamic
     payload length are enabled
Parameters
[in]devNRF24L01+ device handle
[in]pipePipe index
[in]enableIf pipe should be enabled or disabled
Return values
0Success
-EINVALBad pipe index

◆ nrf24l01p_ng_set_max_retransm()

int nrf24l01p_ng_set_max_retransm ( nrf24l01p_ng_t dev,
uint8_t  max_rt 
)

Configure maximum number of retransmissions for ESB.

Parameters
[in]devNRF24L01+ device handle
[in]max_rtNumber of maximum retransmissions [0; 15]
Return values
0Success
-EINVALUnsupported number of retransmissions
-EAGAINCurrent state does not permit changing the maximum number of retransmissions

◆ nrf24l01p_ng_set_retransm_delay()

int nrf24l01p_ng_set_retransm_delay ( nrf24l01p_ng_t dev,
nrf24l01p_ng_ard_t  rt_delay 
)

Set retransmission delay for ESB.

Parameters
[in]devNRF24L01+ device handle
[in]rt_delayConfiguration retransmission delay value
Returns
0
-EINVAL Bad retransmission delay value
-EAGAIN Current state does not permit changing retransmission delay

◆ nrf24l01p_ng_set_rx_address()

int nrf24l01p_ng_set_rx_address ( nrf24l01p_ng_t dev,
const uint8_t *  addr,
nrf24l01p_ng_pipe_t  pipe 
)

Set Rx address of a certain data pipe.

If you want to set the address of pipe 2, 3, 4 or 5 you only set the LSB because the other bytes are equal to the address of pipe 1.

For pipe 0 and 1 NRF24L01P_NG_ADDR_WIGTH bytes are expected

Parameters
[in]devNRF24L01+ device handle
[in]addrRx address
[in]pipePipe index
Return values
0Success
-EINVALBad address length
Returns
-EAGAIN Current state does not permit changing Rx address

◆ nrf24l01p_ng_set_state()

int nrf24l01p_ng_set_state ( nrf24l01p_ng_t dev,
nrf24l01p_ng_state_t  state 
)

Put device into sleep mode(NRF24L01P_NG_STATE_POWER_DOWN), standby mode (NRF24L01P_NG_STATE_STANDBY_1), or Rx mode (NRF24L01P_NG_STATE_RX_MODE)

Parameters
[in]devNRF24L01+ device handle
[in]stateState
Returns
Old state
Return values
-EAGAINDevice is currently not permitted to change state
-ENOTSUPDevice is not permitted to change state to state

◆ nrf24l01p_ng_set_tx_power()

int nrf24l01p_ng_set_tx_power ( nrf24l01p_ng_t dev,
nrf24l01p_ng_tx_power_t  power 
)

Configure Tx trasceiver power.

Parameters
[in]devNRf24L01+ device handle
[in]powerConfiguration Tx power value
Return values
0Success
-EINVALBad Tx power configuration value
-EAGAINCurrent state does not permit changing Tx power

◆ nrf24l01p_ng_setup()

int nrf24l01p_ng_setup ( nrf24l01p_ng_t dev,
const nrf24l01p_ng_params_t params,
uint8_t  index 
)

Setup the NRF24L01+ driver, but perform no initialization.

netdev_driver_t::init can be used after this call to initialize the transceiver.

Parameters
[in]devNRF24L01+ device handle
[in]paramsParameters of the device to setup
[in]indexIndex of params in a global parameter struct array. If initialized manually, pass a unique identifier instead.
Return values
0Device successfully set up