nrf24L01  1.0
nrf24L01 library
 All Files Functions Variables Typedefs Enumerations Enumerator Macros
nrf24L01.h File Reference

Header file for driver for Nordic NRF24L01p with Xmega. More...

Go to the source code of this file.

Macros

#define NRF_R_REGISTER   0x00
 Definitions of commands, see table 20 datasheet. More...
 
#define NRF_W_REGISTER   0x20
 
#define NRF_R_RX_PAYLOAD   0x61
 
#define NRF_W_TX_PAYLOAD   0xA0
 
#define NRF_FLUSH_TX   0xE1
 
#define NRF_FLUSH_RX   0xE2
 
#define NRF_REUSE_TX_PL   0xE3
 
#define NRF_ACTIVATE   0x50
 
#define NRF_R_RX_PL_WID   0x60
 
#define NRF_W_ACK_PAYLOAD   0xA8
 
#define NRF_W_TX_PAYLOAD_NO_ACK   0xB0
 
#define NRF_NOP   0xFF
 
#define NRF_REGISTER_gm   0x1F
 
#define NRF_PIPE_gm   0x07
 
#define REG_CONFIG   0x00
 Definitions of registers, see table 28 datasheet. More...
 
#define REG_EN_AA   0x01
 Enable Auto Acknowledgment. More...
 
#define REG_EN_RXADDR   0x02
 Enabled RX addresses. More...
 
#define REG_SETUP_AW   0x03
 Setup address width. More...
 
#define REG_SETUP_RETR   0x04
 Setup Auto. Retrans. More...
 
#define REG_RF_CH   0x05
 RF channel. More...
 
#define REG_RF_SETUP   0x06
 RF setup. More...
 
#define REG_STATUS   0x07
 Status. More...
 
#define REG_OBSERVE_TX   0x08
 Observe TX. More...
 
#define REG_CD   0x09
 Carrier Detect for nRF24L01. More...
 
#define REG_RPD   0x09
 Received Power Detector for nRF24L01p. More...
 
#define REG_RX_ADDR_P0   0x0A
 RX address pipe0. More...
 
#define REG_RX_ADDR_P1   0x0B
 RX address pipe1. More...
 
#define REG_RX_ADDR_P2   0x0C
 RX address pipe2. More...
 
#define REG_RX_ADDR_P3   0x0D
 RX address pipe3. More...
 
#define REG_RX_ADDR_P4   0x0E
 RX address pipe4. More...
 
#define REG_RX_ADDR_P5   0x0F
 RX address pipe5. More...
 
#define REG_TX_ADDR   0x10
 TX address. More...
 
#define REG_RX_PW_P0   0x11
 RX payload width pipe0. More...
 
#define REG_RX_PW_P1   0x12
 RX payload width pipe1. More...
 
#define REG_RX_PW_P2   0x13
 RX payload width pipe2. More...
 
#define REG_RX_PW_P3   0x14
 RX payload width pipe3. More...
 
#define REG_RX_PW_P4   0x15
 RX payload width pipe4. More...
 
#define REG_RX_PW_P5   0x16
 RX payload width pipe5. More...
 
#define REG_FIFO_STATUS   0x17
 FIFO Status Register. More...
 
#define REG_DYNPD   0x1C
 Dynamic payload length. More...
 
#define REG_FEATURE   0x1D
 Feature register. More...
 
#define NRF_CONFIG_MASK_RX_DR_bm   (1<<6)
 
#define NRF_CONFIG_MASK_TX_DS_bm   (1<<5)
 
#define NRF_CONFIG_MASK_MAX_RT_bm   (1<<4)
 
#define NRF_CONFIG_EN_CRC_bm   (1<<3)
 
#define NRF_CONFIG_CRC0_bm   (1<<2)
 
#define NRF_CONFIG_PWR_UP_bm   (1<<1)
 
#define NRF_CONFIG_PRIM_RX_bm   (1<<0)
 
#define NRF_CONFIG_CRC_gm   ( NRF_CONFIG_EN_CRC_bm | NRF_CONFIG_CRC0_bm )
 
#define NRF_EN_AA_P5_bm   (1<<5)
 
#define NRF_EN_AA_P4_bm   (1<<4)
 
#define NRF_EN_AA_P3_bm   (1<<3)
 
#define NRF_EN_AA_P2_bm   (1<<2)
 
#define NRF_EN_AA_P1_bm   (1<<1)
 
#define NRF_EN_AA_P0_bm   (1<<0)
 
#define NRF_EN_AA_P_ALL_gm   (0x3F)
 
#define NRF_EN_RXADDR_P5_bm   (1<<5)
 
#define NRF_EN_RXADDR_P4_bm   (1<<4)
 
#define NRF_EN_RXADDR_P3_bm   (1<<3)
 
#define NRF_EN_RXADDR_P2_bm   (1<<2)
 
#define NRF_EN_RXADDR_P1_bm   (1<<1)
 
#define NRF_EN_RXADDR_P0_bm   (1<<0)
 
#define NRF_SETUP_ARD_gm   (0xF0)
 
#define NRF_SETUP_ARD_gp   4
 
#define NRF_SETUP_ARC_gm   (0x0F)
 
#define NRF_SETUP_ARC_gp   0
 
#define NRF_RF_CH_gm   0x7F
 
#define NRF_RF_CH_max   0x7F
 
#define NRF_RF_SETUP_CONT_WAVE_bm   (1<<7)
 
#define NRF_RF_SETUP_RF_DR_LOW_bm   (1<<5)
 
#define NRF_RF_SETUP_PLL_LOCK_bm   (1<<4)
 
#define NRF_RF_SETUP_RF_DR_HIGH_bm   (1<<3)
 
#define NRF_RF_SETUP_RF_DR_gm   ((1<<5)|(1<<3))
 
#define NRF_RF_SETUP_PWR_gm   (0x06)
 
#define NRF_STATUS_RX_DR_bm   (1<<6)
 
#define NRF_STATUS_TX_DS_bm   (1<<5)
 
#define NRF_STATUS_MAX_RT_bm   (1<<4)
 
#define NRF_STATUS_RX_P_NO_gp   1
 
#define NRF_STATUS_RX_P_NO_gm   (0x0E)
 
#define NRF_STATUS_TX_FULL_bm   (1<<0)
 
#define NRF_OBSERVE_TX_PLOS_CNT_gm   0xF0
 
#define NRF_OBSERVE_TX_ARC_CNT_gm   0x0F
 
#define NRF_RPD_RPD_bm   (1<<0)
 
#define NRF_CD_CD_bm   (1<<0)
 
#define NRF_RX_PW_P0_gm   (0x3F)
 
#define NRF_RX_PW_P1_gm   (0x3F)
 
#define NRF_RX_PW_P2_gm   (0x3F)
 
#define NRF_RX_PW_P3_gm   (0x3F)
 
#define NRF_RX_PW_P4_gm   (0x3F)
 
#define NRF_RX_PW_P5_gm   (0x3F)
 
#define NRF_FIFO_STATUS_TX_REUSE_bm   (1<<6)
 
#define NRF_FIFO_STATUS_TX_FULL_bm   (1<<5)
 
#define NRF_FIFO_STATUS_TX_EMPTY_bm   (1<<4)
 
#define NRF_FIFO_STATUS_RX_FULL_bm   (1<<1)
 
#define NRF_FIFO_STATUS_RX_EMPTY_bm   (1<<0)
 
#define NRF_DYNPD_DPL_P5_bm   (1<<5)
 
#define NRF_DYNPD_DPL_P4_bm   (1<<4)
 
#define NRF_DYNPD_DPL_P3_bm   (1<<3)
 
#define NRF_DYNPD_DPL_P2_bm   (1<<2)
 
#define NRF_DYNPD_DPL_P1_bm   (1<<1)
 
#define NRF_DYNPD_DPL_P0_bm   (1<<0)
 
#define NRF_DYNPD_DPL_gm   (0x3F)
 
#define NRF_FEATURE_EN_DPL_bm   (1<<2)
 
#define NRF_FEATURE_EN_ACK_PAY_bm   (1<<1)
 
#define NRF_FEATURE_EN_DYN_ACK_bm   (1<<0)
 
#define NRF_MAX_PAYLOAD_SIZE   32
 Some parameters of the NRF24L01p. More...
 
#define NRF_MAX_CHANNEL   127
 

Typedefs

typedef enum NRF_CONFIG_CRC_enum nrf_config_crc_t
 
typedef enum NRF_SETUP_AW_enum NRF_SETUP_AW_t
 
typedef enum NRF_SETUP_AW_ARD_enum NRF_SETUP_AW_ARD_t
 
typedef enum NRF_SETUP_AW_ARC_enum NRF_SETUP_AW_ARC_t
 
typedef enum
NRF_RF_SETUP_RF_DR_enum 
nrf_rf_setup_rf_dr_t
 
typedef enum NRF_RF_SETUP_PWR_enum nrf_rf_setup_pwr_t
 
typedef enum NRF_STATUS_P_NO_enum NRF_STATUS_P_NO_t
 

Enumerations

enum  NRF_CONFIG_CRC_enum { NRF_CONFIG_CRC_DISABLED_gc = ! NRF_CONFIG_EN_CRC_bm, NRF_CONFIG_CRC_8_gc = NRF_CONFIG_EN_CRC_bm | ! NRF_CONFIG_CRC0_bm, NRF_CONFIG_CRC_16_gc = NRF_CONFIG_EN_CRC_bm | NRF_CONFIG_CRC0_bm }
 
enum  NRF_SETUP_AW_enum { NRF_SETUP_AW_3BYTES_gc = (0x01<<0), NRF_SETUP_AW_4BYTES_gc = (0x02<<0), NRF_SETUP_AW_5BYTES_gc = (0x03<<0) }
 
enum  NRF_SETUP_AW_ARD_enum {
  NRF_SETUP_ARD_250US_gc = (0x00<<4), NRF_SETUP_ARD_500US_gc = (0x01<<4), NRF_SETUP_ARD_7500US_gc = (0x02<<4), NRF_SETUP_ARD_1000US_gc = (0x03<<4),
  NRF_SETUP_ARD_1250US_gc = (0x04<<4), NRF_SETUP_ARD_1500US_gc = (0x05<<4), NRF_SETUP_ARD_1750US_gc = (0x06<<4), NRF_SETUP_ARD_2000US_gc = (0x07<<4),
  NRF_SETUP_ARD_2250US_gc = (0x08<<4), NRF_SETUP_ARD_2500US_gc = (0x09<<4), NRF_SETUP_ARD_2750US_gc = (0x0A<<4), NRF_SETUP_ARD_3000US_gc = (0x0B<<4),
  NRF_SETUP_ARD_3250US_gc = (0x0C<<4), NRF_SETUP_ARD_3500US_gc = (0x0D<<4), NRF_SETUP_ARD_3750US_gc = (0x0E<<4), NRF_SETUP_ARD_4000US_gc = (0x0F<<4)
}
 
enum  NRF_SETUP_AW_ARC_enum {
  NRF_SETUP_ARC_NORETRANSMIT_gc = (0x00<<0), NRF_SETUP_ARC_1RETRANSMIT_gc = (0x01<<0), NRF_SETUP_ARC_2RETRANSMIT_gc = (0x02<<0), NRF_SETUP_ARC_3RETRANSMIT_gc = (0x03<<0),
  NRF_SETUP_ARC_4RETRANSMIT_gc = (0x04<<0), NRF_SETUP_ARC_5RETRANSMIT_gc = (0x05<<0), NRF_SETUP_ARC_6RETRANSMIT_gc = (0x06<<0), NRF_SETUP_ARC_7RETRANSMIT_gc = (0x07<<0),
  NRF_SETUP_ARC_8RETRANSMIT_gc = (0x08<<0), NRF_SETUP_ARC_9RETRANSMIT_gc = (0x09<<0), NRF_SETUP_ARC_10RETRANSMIT_gc = (0x0A<<0), NRF_SETUP_ARC_11RETRANSMIT_gc = (0x0B<<0),
  NRF_SETUP_ARC_12RETRANSMIT_gc = (0x0C<<0), NRF_SETUP_ARC_13RETRANSMIT_gc = (0x0D<<0), NRF_SETUP_ARC_14RETRANSMIT_gc = (0x0E<<0), NRF_SETUP_ARC_15RETRANSMIT_gc = (0x0F<<0)
}
 
enum  NRF_RF_SETUP_RF_DR_enum { NRF_RF_SETUP_RF_DR_1M_gc = ((0<<5)|(0<<3)), NRF_RF_SETUP_RF_DR_2M_gc = ((0<<5)|(1<<3)), NRF_RF_SETUP_RF_DR_250K_gc = ((1<<5)|(0<<3)) }
 
enum  NRF_RF_SETUP_PWR_enum { NRF_RF_SETUP_PWR_18DBM_gc = (0x00<<1), NRF_RF_SETUP_PWR_12DBM_gc = (0x01<<1), NRF_RF_SETUP_PWR_6DBM_gc = (0x02<<1), NRF_RF_SETUP_PWR_0DBM_gc = (0x03<<1) }
 
enum  NRF_STATUS_P_NO_enum {
  NRF_STATUS_RX_P_NO_0_gc = (0x00<<1), NRF_STATUS_RX_P_NO_1_gc = (0x01<<1), NRF_STATUS_RX_P_NO_2_gc = (0x02<<1), NRF_STATUS_RX_P_NO_3_gc = (0x03<<1),
  NRF_STATUS_RX_P_NO_4_gc = (0x04<<1), NRF_STATUS_RX_P_NO_5_gc = (0x05<<1), NRF_STATUS_RX_P_NO_RX_FIFO_EMPTY_gc = (0x07<<1)
}
 

Functions

uint8_t nrfReadRegisterMulti (uint8_t reg, uint8_t *buf, uint8_t len)
 Prototypes of functions. More...
 
uint8_t nrfReadRegister (uint8_t reg)
 Read a byte from a register. More...
 
uint8_t nrfWriteRegisterMulti (uint8_t reg, const uint8_t *buf, uint8_t len)
 Write multiple bytes to a register. More...
 
uint8_t nrfWriteRegister (uint8_t reg, uint8_t value)
 Write a byte to a register. More...
 
uint8_t nrfWritePayload (const void *buf, uint8_t len, const uint8_t writeType)
 Write the transmit payload. More...
 
uint8_t nrfReadPayload (void *buf, uint8_t len)
 Write the receive payload. More...
 
uint8_t nrfFlushRx (void)
 Empty the receive fifo. More...
 
uint8_t nrfFlushTx (void)
 Empty the transmit fifo. More...
 
void nrfToggleFeatures (void)
 Turn on or off the special features. More...
 
void nrfBegin (void)
 Begin operation of NRF24L01p. More...
 
void nrfStartListening (void)
 Start listening on the pipes opened for reading. More...
 
void nrfStopListening (void)
 Stop listening for incoming messages. More...
 
uint8_t nrfGetStatus (void)
 Get fixed payload size. More...
 
void nrfSetChannel (uint8_t channel)
 
uint8_t nrfGetChannel (void)
 
void nrfSetPayloadSize (uint8_t size)
 
uint8_t nrfGetPayloadSize (void)
 Get fixed payload size. More...
 
void nrfPowerDown (void)
 Enter low-power mode. More...
 
void nrfPowerUp (void)
 Leave low-power mode - making radio more responsive. More...
 
uint8_t nrfWrite (uint8_t *buf, uint8_t len)
 Write to the open writing pipe. More...
 
uint8_t nrfWaitForAck (void)
 Wait for acknowledge. More...
 
uint8_t nrfAvailable (uint8_t *pipe_num)
 Test whether there are bytes available to be read. More...
 
uint8_t nrfGetDynamicPayloadSize (void)
 Get Dynamic Payload Size. More...
 
void nrfWriteAckPayload (uint8_t pipe, uint8_t *buf, uint8_t len)
 Write an ack payload for the specified pipe. More...
 
void nrfStartWrite (const void *buf, uint8_t len, uint8_t multicast)
 Write to open writing pipe. More...
 
uint8_t nrfRead (void *buf, uint8_t len)
 Read the payload. More...
 
void nrfWhatHappened (uint8_t *tx_ok, uint8_t *tx_fail, uint8_t *rx_ready)
 Call this to find out which interrupt occured. More...
 
void nrfOpen64WritingPipe (uint64_t value)
 Open a pipe for writing. More...
 
void nrfOpenWritingPipe (uint8_t *address)
 Open a pipe for writing. More...
 
void nrfOpen64ReadingPipe (uint8_t child, uint64_t address)
 Open a pipe for reading. More...
 
void nrfOpenReadingPipe (uint8_t child, uint8_t *address)
 Open a pipe for reading. More...
 
void nrfEnableDynamicPayloads (void)
 Enable dynamically-sized payloads. More...
 
void nrfEnableAckPayload (void)
 Enable custom payloads on the acknowledge packets. More...
 
uint8_t nrfIsPVariant (void)
 Determine whether the hardware is an nRF24L01+ or not. More...
 
void nrfSetAutoAck (uint8_t enable)
 Enable or disable auto-acknowlede packets. More...
 
void nrfSetAutoAckPipe (uint8_t pipe, uint8_t enable)
 Enable or disable auto-acknowlede packets for a distinct pipe. More...
 
uint8_t nrfTestCarrier (void)
 Test whether there was a carrier on the line for the previous listening period. More...
 
uint8_t nrfTestRPD (void)
 Test whether a signal (carrier or otherwise) greater than or equal to -64dBm is present on the channel. More...
 
void nrfSetPALevel (nrf_rf_setup_pwr_t level)
 Set Power Amplifier (PA) level. More...
 
nrf_rf_setup_pwr_t nrfGetPALevel (void)
 Gets the current PA level. More...
 
uint8_t nrfSetDataRate (nrf_rf_setup_rf_dr_t speed)
 Set the transmission data rate. More...
 
nrf_rf_setup_rf_dr_t nrfGetDataRate (void)
 Get the transmission data rate. More...
 
void nrfSetCRCLength (nrf_config_crc_t length)
 Sets the CRC length. More...
 
nrf_config_crc_t nrfGetCRCLength (void)
 Get the CRC length. More...
 
void nrfDisableCRC (void)
 Disbale CRC. More...
 
void nrfSetRetries (uint8_t delay, uint8_t retries)
 Sets the number of retries and the delay between the retries. More...
 
uint16_t nrfGetMaxTimeout (void)
 Calculate the maximum timeout in us based on current configuration. More...
 
void nrfClearInterruptBits (void)
 Clear Interrupt Bits. More...
 
uint8_t nrfVerifySPIConnection (void)
 Verify SPI Interface. More...
 

Detailed Description

Header file for driver for Nordic NRF24L01p with Xmega.

Author
Wim Dolman (w.e.dolman@hva.nl)
Date
19-02-2016
Version
1.0

This file contains he definitions and prototypes for interfacing interfacing a Nordic NRF24L01+ and a Xmega. The accompanying files nrf24spiXM2.c and nrf24spiXM2.h comtains the driverroutines for the HvA Xmegaboard version 2.

This driver is based on:

Other references:

Macro Definition Documentation

#define NRF_ACTIVATE   0x50
#define NRF_CD_CD_bm   (1<<0)
#define NRF_CONFIG_CRC0_bm   (1<<2)
#define NRF_CONFIG_CRC_gm   ( NRF_CONFIG_EN_CRC_bm | NRF_CONFIG_CRC0_bm )
#define NRF_CONFIG_EN_CRC_bm   (1<<3)
#define NRF_CONFIG_MASK_MAX_RT_bm   (1<<4)
#define NRF_CONFIG_MASK_RX_DR_bm   (1<<6)
#define NRF_CONFIG_MASK_TX_DS_bm   (1<<5)
#define NRF_CONFIG_PRIM_RX_bm   (1<<0)
#define NRF_CONFIG_PWR_UP_bm   (1<<1)
#define NRF_DYNPD_DPL_gm   (0x3F)
#define NRF_DYNPD_DPL_P0_bm   (1<<0)
#define NRF_DYNPD_DPL_P1_bm   (1<<1)
#define NRF_DYNPD_DPL_P2_bm   (1<<2)
#define NRF_DYNPD_DPL_P3_bm   (1<<3)
#define NRF_DYNPD_DPL_P4_bm   (1<<4)
#define NRF_DYNPD_DPL_P5_bm   (1<<5)
#define NRF_EN_AA_P0_bm   (1<<0)
#define NRF_EN_AA_P1_bm   (1<<1)
#define NRF_EN_AA_P2_bm   (1<<2)
#define NRF_EN_AA_P3_bm   (1<<3)
#define NRF_EN_AA_P4_bm   (1<<4)
#define NRF_EN_AA_P5_bm   (1<<5)
#define NRF_EN_AA_P_ALL_gm   (0x3F)
#define NRF_EN_RXADDR_P0_bm   (1<<0)
#define NRF_EN_RXADDR_P1_bm   (1<<1)
#define NRF_EN_RXADDR_P2_bm   (1<<2)
#define NRF_EN_RXADDR_P3_bm   (1<<3)
#define NRF_EN_RXADDR_P4_bm   (1<<4)
#define NRF_EN_RXADDR_P5_bm   (1<<5)
#define NRF_FEATURE_EN_ACK_PAY_bm   (1<<1)
#define NRF_FEATURE_EN_DPL_bm   (1<<2)
#define NRF_FEATURE_EN_DYN_ACK_bm   (1<<0)
#define NRF_FIFO_STATUS_RX_EMPTY_bm   (1<<0)
#define NRF_FIFO_STATUS_RX_FULL_bm   (1<<1)
#define NRF_FIFO_STATUS_TX_EMPTY_bm   (1<<4)
#define NRF_FIFO_STATUS_TX_FULL_bm   (1<<5)
#define NRF_FIFO_STATUS_TX_REUSE_bm   (1<<6)
#define NRF_FLUSH_RX   0xE2
#define NRF_FLUSH_TX   0xE1
#define NRF_MAX_CHANNEL   127
#define NRF_MAX_PAYLOAD_SIZE   32

Some parameters of the NRF24L01p.

#define NRF_NOP   0xFF
#define NRF_OBSERVE_TX_ARC_CNT_gm   0x0F
#define NRF_OBSERVE_TX_PLOS_CNT_gm   0xF0
#define NRF_PIPE_gm   0x07
#define NRF_R_REGISTER   0x00

Definitions of commands, see table 20 datasheet.

#define NRF_R_RX_PAYLOAD   0x61
#define NRF_R_RX_PL_WID   0x60
#define NRF_REGISTER_gm   0x1F
#define NRF_REUSE_TX_PL   0xE3
#define NRF_RF_CH_gm   0x7F
#define NRF_RF_CH_max   0x7F
#define NRF_RF_SETUP_CONT_WAVE_bm   (1<<7)
#define NRF_RF_SETUP_PLL_LOCK_bm   (1<<4)
#define NRF_RF_SETUP_PWR_gm   (0x06)
#define NRF_RF_SETUP_RF_DR_gm   ((1<<5)|(1<<3))
#define NRF_RF_SETUP_RF_DR_HIGH_bm   (1<<3)
#define NRF_RF_SETUP_RF_DR_LOW_bm   (1<<5)
#define NRF_RPD_RPD_bm   (1<<0)
#define NRF_RX_PW_P0_gm   (0x3F)
#define NRF_RX_PW_P1_gm   (0x3F)
#define NRF_RX_PW_P2_gm   (0x3F)
#define NRF_RX_PW_P3_gm   (0x3F)
#define NRF_RX_PW_P4_gm   (0x3F)
#define NRF_RX_PW_P5_gm   (0x3F)
#define NRF_SETUP_ARC_gm   (0x0F)
#define NRF_SETUP_ARC_gp   0
#define NRF_SETUP_ARD_gm   (0xF0)
#define NRF_SETUP_ARD_gp   4
#define NRF_STATUS_MAX_RT_bm   (1<<4)
#define NRF_STATUS_RX_DR_bm   (1<<6)
#define NRF_STATUS_RX_P_NO_gm   (0x0E)
#define NRF_STATUS_RX_P_NO_gp   1
#define NRF_STATUS_TX_DS_bm   (1<<5)
#define NRF_STATUS_TX_FULL_bm   (1<<0)
#define NRF_W_ACK_PAYLOAD   0xA8
#define NRF_W_REGISTER   0x20
#define NRF_W_TX_PAYLOAD   0xA0
#define NRF_W_TX_PAYLOAD_NO_ACK   0xB0
#define REG_CD   0x09

Carrier Detect for nRF24L01.

#define REG_CONFIG   0x00

Definitions of registers, see table 28 datasheet.

Config

#define REG_DYNPD   0x1C

Dynamic payload length.

#define REG_EN_AA   0x01

Enable Auto Acknowledgment.

#define REG_EN_RXADDR   0x02

Enabled RX addresses.

#define REG_FEATURE   0x1D

Feature register.

#define REG_FIFO_STATUS   0x17

FIFO Status Register.

#define REG_OBSERVE_TX   0x08

Observe TX.

#define REG_RF_CH   0x05

RF channel.

#define REG_RF_SETUP   0x06

RF setup.

#define REG_RPD   0x09

Received Power Detector for nRF24L01p.

#define REG_RX_ADDR_P0   0x0A

RX address pipe0.

#define REG_RX_ADDR_P1   0x0B

RX address pipe1.

#define REG_RX_ADDR_P2   0x0C

RX address pipe2.

#define REG_RX_ADDR_P3   0x0D

RX address pipe3.

#define REG_RX_ADDR_P4   0x0E

RX address pipe4.

#define REG_RX_ADDR_P5   0x0F

RX address pipe5.

#define REG_RX_PW_P0   0x11

RX payload width pipe0.

#define REG_RX_PW_P1   0x12

RX payload width pipe1.

#define REG_RX_PW_P2   0x13

RX payload width pipe2.

#define REG_RX_PW_P3   0x14

RX payload width pipe3.

#define REG_RX_PW_P4   0x15

RX payload width pipe4.

#define REG_RX_PW_P5   0x16

RX payload width pipe5.

#define REG_SETUP_AW   0x03

Setup address width.

#define REG_SETUP_RETR   0x04

Setup Auto. Retrans.

#define REG_STATUS   0x07

Status.

#define REG_TX_ADDR   0x10

TX address.

Typedef Documentation

Enumeration Type Documentation

Enumerator
NRF_CONFIG_CRC_DISABLED_gc 
NRF_CONFIG_CRC_8_gc 
NRF_CONFIG_CRC_16_gc 
Enumerator
NRF_RF_SETUP_PWR_18DBM_gc 
NRF_RF_SETUP_PWR_12DBM_gc 
NRF_RF_SETUP_PWR_6DBM_gc 
NRF_RF_SETUP_PWR_0DBM_gc 
Enumerator
NRF_RF_SETUP_RF_DR_1M_gc 
NRF_RF_SETUP_RF_DR_2M_gc 
NRF_RF_SETUP_RF_DR_250K_gc 
Enumerator
NRF_SETUP_ARC_NORETRANSMIT_gc 
NRF_SETUP_ARC_1RETRANSMIT_gc 
NRF_SETUP_ARC_2RETRANSMIT_gc 
NRF_SETUP_ARC_3RETRANSMIT_gc 
NRF_SETUP_ARC_4RETRANSMIT_gc 
NRF_SETUP_ARC_5RETRANSMIT_gc 
NRF_SETUP_ARC_6RETRANSMIT_gc 
NRF_SETUP_ARC_7RETRANSMIT_gc 
NRF_SETUP_ARC_8RETRANSMIT_gc 
NRF_SETUP_ARC_9RETRANSMIT_gc 
NRF_SETUP_ARC_10RETRANSMIT_gc 
NRF_SETUP_ARC_11RETRANSMIT_gc 
NRF_SETUP_ARC_12RETRANSMIT_gc 
NRF_SETUP_ARC_13RETRANSMIT_gc 
NRF_SETUP_ARC_14RETRANSMIT_gc 
NRF_SETUP_ARC_15RETRANSMIT_gc 
Enumerator
NRF_SETUP_ARD_250US_gc 
NRF_SETUP_ARD_500US_gc 
NRF_SETUP_ARD_7500US_gc 
NRF_SETUP_ARD_1000US_gc 
NRF_SETUP_ARD_1250US_gc 
NRF_SETUP_ARD_1500US_gc 
NRF_SETUP_ARD_1750US_gc 
NRF_SETUP_ARD_2000US_gc 
NRF_SETUP_ARD_2250US_gc 
NRF_SETUP_ARD_2500US_gc 
NRF_SETUP_ARD_2750US_gc 
NRF_SETUP_ARD_3000US_gc 
NRF_SETUP_ARD_3250US_gc 
NRF_SETUP_ARD_3500US_gc 
NRF_SETUP_ARD_3750US_gc 
NRF_SETUP_ARD_4000US_gc 
Enumerator
NRF_SETUP_AW_3BYTES_gc 
NRF_SETUP_AW_4BYTES_gc 
NRF_SETUP_AW_5BYTES_gc 
Enumerator
NRF_STATUS_RX_P_NO_0_gc 
NRF_STATUS_RX_P_NO_1_gc 
NRF_STATUS_RX_P_NO_2_gc 
NRF_STATUS_RX_P_NO_3_gc 
NRF_STATUS_RX_P_NO_4_gc 
NRF_STATUS_RX_P_NO_5_gc 
NRF_STATUS_RX_P_NO_RX_FIFO_EMPTY_gc 

Function Documentation

uint8_t nrfAvailable ( uint8_t *  pipe_num)

Test whether there are bytes available to be read.

Call nrfAvaliable(NULL) if you're not interested in the pipe number Call nrfAvaliable(&pipe) puts the pipenumber in pipe

Parameters
[out]pipe_numPointer to pipenumber, where it writes the pipenumber with a payload that is available
Returns
64 (true) if there is a payload available, 0 (false) if none is
void nrfBegin ( void  )

Begin operation of NRF24L01p.

This function is used at the inilialzation of NRF24L01p.

Returns
void
void nrfClearInterruptBits ( void  )

Clear Interrupt Bits.

void nrfDisableCRC ( void  )

Disbale CRC.

void nrfEnableAckPayload ( void  )

Enable custom payloads on the acknowledge packets.

Ack payloads are a handy way to return data back to senders without manually changing the radio modes on both units.

void nrfEnableDynamicPayloads ( void  )

Enable dynamically-sized payloads.

This way you don't always have to send large packets. It enables dynamic payloads on ALL pipes.

uint8_t nrfFlushRx ( void  )

Empty the receive fifo.

Returns
Current value of status register
uint8_t nrfFlushTx ( void  )

Empty the transmit fifo.

Returns
Current value of status register
uint8_t nrfGetChannel ( void  )
nrf_config_crc_t nrfGetCRCLength ( void  )

Get the CRC length.

The CRC correspond to the following lengths respectively:

  • Disable CRC, use NRF_CONFIG_CRC_DISABLED_gc
  • CRC 1 byte, use NRF_CONFIG_CRC_8_gc
  • CRC 2 bytes, use NRF_CONFIG_CRC_16_gc
Returns
The CRC-configuration (is one of the group configurations)
nrf_rf_setup_rf_dr_t nrfGetDataRate ( void  )

Get the transmission data rate.

The data rates correspond to the following speeds respectively:

  • 250kbps, use NRF_RF_SETUP_RF_DR_250K_gc (only for nRF24L01+)
  • 1Mpbs, use NRF_RF_SETUP_RF_DR_1M_gc
  • 2Mpbs, use NRF_RF_SETUP_RF_DR_2M_gc
Warning
Setting RF24_250KBPS will fail for a non nRF24L01+
Returns
Speed (is one of the group configurations)
uint8_t nrfGetDynamicPayloadSize ( void  )

Get Dynamic Payload Size.

For dynamic payloads, this returns the size of the payload

Returns
Payload length of last-received dynamic payload
uint16_t nrfGetMaxTimeout ( void  )

Calculate the maximum timeout in us based on current configuration.

This depends on the number of retries en the delays betweeen them. The maximum timeout is delay * (retries+1) us. It is a value between 250 us and 64000 us.

Returns
maximum timeout in us
nrf_rf_setup_pwr_t nrfGetPALevel ( void  )

Gets the current PA level.

The power levels correspond to the following output levels respectively:

  • minimum is -18dBm, use NRF_RF_SETUP_PWR_18DBM_gc
  • low is -12dBm, use NRF_RF_SETUP_PWR_12DBM_gc
  • high is -6dBm, use NRF_RF_SETUP_PWR_6DBM_gc
  • maximum is -0dBm, use NRF_RF_SETUP_PWR_0DBM_gc
Returns
Level (is one of the group configurations)
uint8_t nrfGetPayloadSize ( void  )

Get fixed payload size.

Returns
Fixed payload size
uint8_t nrfGetStatus ( void  )

Get fixed payload size.

Returns
Fixed payload size
uint8_t nrfIsPVariant ( void  )

Determine whether the hardware is an nRF24L01+ or not.

Returns
1 (true) if the hardware is nRF24L01+ (or compatible) and 0 (false) if its not.
void nrfOpen64ReadingPipe ( uint8_t  child,
uint64_t  address 
)

Open a pipe for reading.

Obsolete, replaced by

See Also
nrfOpenWritingPipe
void nrfOpen64WritingPipe ( uint64_t  value)

Open a pipe for writing.

Obsolete, replaced by

See Also
nrfOpenWritingPipe
void nrfOpenReadingPipe ( uint8_t  child,
uint8_t *  address 
)

Open a pipe for reading.

Up to 6 pipes can be open for reading at once. Open all the required reading pipes, and then call startListening().

Parameters
childPipe number (0-5) to read from.
addressPointer to address of the pipe to open.
void nrfOpenWritingPipe ( uint8_t *  address)

Open a pipe for writing.

The address is a pointer to byte array with 3-5 bytes. Only one writing pipe can be open at once, but you can change the address you'll write to.

Parameters
addressPointer to address of the pipe to open.
void nrfPowerDown ( void  )

Enter low-power mode.

To return to normal power mode, either nrfWrite() some data or nrfStartListening(), or nrfPowerUp().

void nrfPowerUp ( void  )

Leave low-power mode - making radio more responsive.

To return to low power mode, call nrfPowerDown().

uint8_t nrfRead ( void *  buf,
uint8_t  len 
)

Read the payload.

Get the last payload received

Parameters
bufBuffer where the data should be written to
lenMaximum number of bytes to read into the buffer
Returns
1 if all data is read else 0
uint8_t nrfReadPayload ( void *  buf,
uint8_t  len 
)

Write the receive payload.

The size of data written is the fixed payload size, see getPayloadSize()

Parameters
bufBuffer to write the data to
lenMaximum number of bytes to receive
Returns
Current value of status register
uint8_t nrfReadRegister ( uint8_t  reg)

Read a byte from a register.

Parameters
regRegister address, see also tabel 28 of datasheet
Returns
Current value of register reg
uint8_t nrfReadRegisterMulti ( uint8_t  reg,
uint8_t *  buf,
uint8_t  len 
)

Prototypes of functions.

Prototypes of functions.

Parameters
regRegister address, see also tabel 28 of datasheet
bufPointer to buffer to put data in
lenNumber of bytes to be received
Returns
Current value of status register
void nrfSetAutoAck ( uint8_t  enable)

Enable or disable auto-acknowlede packets.

Auto acknowledge is enabled by default, so it's only needed if you want to turn it off for some reason.

Parameters
enableWhether to enable (true, non 0) or disable (false, 0).
void nrfSetAutoAckPipe ( uint8_t  pipe,
uint8_t  enable 
)

Enable or disable auto-acknowlede packets for a distinct pipe.

Auto acknowledge is enabled by default, so it's only needed if you want to turn it off for some reason.

Parameters
pipePipe number which you want to enable or disable
enableWhether to enable (true, non 0) or disable (false, 0).
void nrfSetChannel ( uint8_t  channel)
void nrfSetCRCLength ( nrf_config_crc_t  length)

Sets the CRC length.

The CRC correspond to the following lengths respectively:

  • Disable CRC, use NRF_CONFIG_CRC_DISABLED_gc
  • CRC 1 byte, use NRF_CONFIG_CRC_8_gc
  • CRC 2 bytes, use NRF_CONFIG_CRC_16_gc
uint8_t nrfSetDataRate ( nrf_rf_setup_rf_dr_t  speed)

Set the transmission data rate.

The data rates correspond to the following speeds respectively:

  • 250kbps, use NRF_RF_SETUP_RF_DR_250K_gc (only for nRF24L01+)
  • 1Mpbs, use NRF_RF_SETUP_RF_DR_1M_gc
  • 2Mpbs, use NRF_RF_SETUP_RF_DR_2M_gc
Warning
Setting RF24_250KBPS will fail for a non nRF24L01+
Parameters
speed(is one of the group configurations)
Returns
1 (true) if successfull, 0 (false) if not
void nrfSetPALevel ( nrf_rf_setup_pwr_t  level)

Set Power Amplifier (PA) level.

The power levels correspond to the following output levels respectively:

  • minimum is -18dBm, use NRF_RF_SETUP_PWR_18DBM_gc
  • low is -12dBm, use NRF_RF_SETUP_PWR_12DBM_gc
  • high is -6dBm, use NRF_RF_SETUP_PWR_6DBM_gc
  • maximum is -0dBm, use NRF_RF_SETUP_PWR_0DBM_gc
Parameters
levelDesired level (is one of the group configurations)
void nrfSetPayloadSize ( uint8_t  size)
void nrfSetRetries ( uint8_t  delay,
uint8_t  retries 
)

Sets the number of retries and the delay between the retries.

The number of retries is 0 to 15 The delay between the retries is 250 us to 4000 us with with a 250 us step size.

The groupsconfiguration for the retries is NRF_SETUP_ARC_::RETRANSMIT_gc where # is NO or 1 to 15.

The groupsconfiguration for the delays is NRF_SETUP_ARD_::US_gc where # is 250 to 4000 with a 250 step size.

Parameters
delay(groupsconfiguration NRF_SETUP_ARD_::US_gc for delay #)
retries(groupsconfiguration NRF_SETUP_ARC_::RETRANSMIT_gc for retries #)
void nrfStartListening ( void  )

Start listening on the pipes opened for reading.

Be sure to call openReadingPipe() first. Do not call write() while in this mode, without first calling stopListening(). Call isAvailable() to check for incoming traffic, and read() to get it.

void nrfStartWrite ( const void *  buf,
uint8_t  len,
uint8_t  multicast 
)

Write to open writing pipe.

Same as write() but doesn't wait for acknowledge

Parameters
bufPointer to the data to be sent
lenNumber of bytes to be sent
multicast?? NRF_W_TX_PAYLOAD or NRF_W_TX_PAYLOAD_NO_ACK.
void nrfStopListening ( void  )

Stop listening for incoming messages.

Do this before calling write().

uint8_t nrfTestCarrier ( void  )

Test whether there was a carrier on the line for the previous listening period.

Valid only on nRF24L01. On nRF24L01, use nrfTestRPD().

Returns
1 (true) if there was a carrier 0 (false) if not.
uint8_t nrfTestRPD ( void  )

Test whether a signal (carrier or otherwise) greater than or equal to -64dBm is present on the channel.

Valid only on nRF24L01+(p). On nRF24L01, use nrfTestCarrier(). Useful to check for interference on the current channel and channel hopping strategies.

Returns
1 (true) if signal is greater or equal to -64dBm, 0 (false) if not.
void nrfToggleFeatures ( void  )

Turn on or off the special features.

The nrf2401(+) has certain 'features' which are only available when the 'features' are enabled.

uint8_t nrfVerifySPIConnection ( void  )

Verify SPI Interface.

It sends and reads back a random value to the SETUP register It restores the original setup

Returns
1 (true) if SPI interface is correct 0 (false) if not
uint8_t nrfWaitForAck ( void  )

Wait for acknowledge.

It waits for interrupt on TX complete, maximum retransmits reached or timer expired. The time depends on the number of retries and delay time. This time calculated with nrfGetMaxTimeout();

only write with an acknowledge is implemented

Returns
32 (true) if the payload was delivered successfully 0 if not
void nrfWhatHappened ( uint8_t *  tx_ok,
uint8_t *  tx_fail,
uint8_t *  rx_ready 
)

Call this to find out which interrupt occured.

Tells you what caused the interrupt, and clears the state of interrupts. The retuend values are not equal to 0 if the interrupt occured.

Parameters
[out]tx_okThe send was successful (TX_DS)
[out]tx_failThe send failed, too many retries (MAX_RT)
[out]rx_readyThere is a message waiting to be read (RX_DR)
uint8_t nrfWrite ( uint8_t *  buf,
uint8_t  len 
)

Write to the open writing pipe.

Be sure to call openWritingPipe() first to set the destination of where to write to.

only write with an acknowledge is implemented

Parameters
bufPointer to the data to be sent
lenNumber of bytes to be sent
Returns
32 (true) if the payload was delivered successfully 0 if not
void nrfWriteAckPayload ( uint8_t  pipe,
uint8_t *  buf,
uint8_t  len 
)

Write an ack payload for the specified pipe.

The next time a message is received on pipe, the data in buf will be sent back in the acknowledgement.

Warning
Do note, multicast payloads will not trigger ack payloads.
According to the data sheet, only three of these can be pending at any time.
Parameters
pipePipe number
bufBuffer to get the data from
lenNumber of bytes to be written
Returns
Current value of status register
uint8_t nrfWritePayload ( const void *  buf,
uint8_t  len,
const uint8_t  writeType 
)

Write the transmit payload.

The size of data written has a fixed payload size or a dynamic payload size. It uses the command W_TX_PAYLOAD (fixed size) or W_TX_PAYLOAD_NO_ACK (dynamic size).

Parameters
bufBuffer to get the data from
lenNumber of bytes to be written
writeTypeW_TX_PAYLOAD: fixed data size W_TX_PAYLOAD_NO_ACK: variable data size (multicast)
Returns
Current value of status register
uint8_t nrfWriteRegister ( uint8_t  reg,
uint8_t  value 
)

Write a byte to a register.

Parameters
regRegister address, see also tabel 28 of datasheet
valueThe new value of the register
Returns
Current value of status register
uint8_t nrfWriteRegisterMulti ( uint8_t  reg,
const uint8_t *  buf,
uint8_t  len 
)

Write multiple bytes to a register.

Parameters
regRegister address, see also tabel 28 of datasheet
bufPointer to buffer with data to be sent
lenNumber of bytes to be sent

This function is used at the inilialzation of NRF24L01p.

Returns
Current value of status register