nrf24L01
1.0
nrf24L01 library
|
Driver for Nordic NRF24L01p with Xmega. More...
Macros | |
#define | ERX_P5 5 |
#define | ERX_P4 4 |
#define | ERX_P3 3 |
#define | ERX_P2 2 |
#define | ERX_P1 1 |
#define | ERX_P0 0 |
Functions | |
void | nrfBegin (void) |
Begin operation of NRF24L01p. More... | |
uint8_t | nrfReadRegisterMulti (uint8_t reg, uint8_t *buf, uint8_t len) |
Read multiple bytes from a register. 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... | |
void | nrfWriteAckPayload (uint8_t pipe, uint8_t *buf, uint8_t len) |
Write an ack payload for the specified pipe. More... | |
uint8_t | nrfReadPayload (void *buf, uint8_t len) |
Write the receive payload. More... | |
uint8_t | nrfRead (void *buf, uint8_t len) |
Read the payload. More... | |
uint8_t | nrfFlushRx (void) |
Empty the receive fifo. More... | |
uint8_t | nrfFlushTx (void) |
Empty the transmit fifo. More... | |
void | nrfStartListening (void) |
Start listening on the pipes opened for reading. More... | |
void | nrfStopListening (void) |
Stop listening for incoming messages. 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... | |
void | nrfStartWrite (const void *buf, uint8_t len, uint8_t multicast) |
Write to open writing pipe. More... | |
void | nrfPowerDown (void) |
Enter low-power mode. More... | |
void | nrfPowerUp (void) |
Leave low-power mode - making radio more responsive. More... | |
uint8_t | nrfAvailable (uint8_t *pipe_num) |
Test whether there are bytes available to be read. 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 | nrfOpen64ReadingPipe (uint8_t child, uint64_t address) |
Open a pipe for reading. More... | |
void | nrfOpenWritingPipe (uint8_t *address) |
Open a pipe for writing. More... | |
void | nrfOpenReadingPipe (uint8_t child, uint8_t *address) |
Open a pipe for reading. More... | |
void | nrfToggleFeatures (void) |
Turn on or off the special features. More... | |
void | nrfEnableDynamicPayloads (void) |
Enable dynamically-sized payloads. More... | |
void | nrfEnableAckPayload (void) |
Enable custom payloads on the acknowledge packets. More... | |
uint8_t | nrfGetDynamicPayloadSize (void) |
Get Dynamic Payload Size. More... | |
uint8_t | nrfGetPayloadSize (void) |
Get fixed payload size. 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 | 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... | |
Variables | |
uint8_t | p_variant = 1 |
Global variables and constants. More... | |
uint8_t | fixed_payload_size = NRF_MAX_PAYLOAD_SIZE |
Size of a fixed payload. More... | |
uint8_t | dynamic_payloads_enabled = 0 |
Whether dynamic payloads are enabled. More... | |
uint8_t | pipe0_reading_address [5] = {0,0,0,0,0} |
Last address set on pipe 0 for reading. More... | |
uint8_t | addr_width = 5 |
The address width to use - 3,4 or 5 bytes. More... | |
Driver for Nordic NRF24L01p with Xmega.
This file contains the routines for interfacing a Nordic NRF24L01p 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:
#define ERX_P0 0 |
#define ERX_P1 1 |
#define ERX_P2 2 |
#define ERX_P3 3 |
#define ERX_P4 4 |
#define ERX_P5 5 |
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
[out] | pipe_num | Pointer to pipenumber, where it writes the pipenumber with a payload that is available |
void nrfBegin | ( | void | ) |
Begin operation of NRF24L01p.
This function is used at the inilialzation of NRF24L01p.
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.
uint8_t nrfFlushTx | ( | void | ) |
Empty the transmit fifo.
uint8_t nrfGetChannel | ( | void | ) |
nrf_config_crc_t nrfGetCRCLength | ( | void | ) |
Get the CRC length.
The CRC correspond to the following lengths respectively:
nrf_rf_setup_rf_dr_t nrfGetDataRate | ( | void | ) |
Get the transmission data rate.
The data rates correspond to the following speeds respectively:
uint8_t nrfGetDynamicPayloadSize | ( | void | ) |
Get Dynamic Payload Size.
For dynamic payloads, this returns the size of the 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.
nrf_rf_setup_pwr_t nrfGetPALevel | ( | void | ) |
Gets the current PA level.
The power levels correspond to the following output levels respectively:
NRF_RF_SETUP_PWR_18DBM_gc
NRF_RF_SETUP_PWR_12DBM_gc
NRF_RF_SETUP_PWR_6DBM_gc
NRF_RF_SETUP_PWR_0DBM_gc
uint8_t nrfGetPayloadSize | ( | void | ) |
Get fixed payload size.
uint8_t nrfGetStatus | ( | void | ) |
Get fixed payload size.
uint8_t nrfIsPVariant | ( | void | ) |
Determine whether the hardware is an nRF24L01+ or not.
void nrfOpen64ReadingPipe | ( | uint8_t | child, |
uint64_t | address | ||
) |
void nrfOpen64WritingPipe | ( | uint64_t | value | ) |
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().
child | Pipe number (0-5) to read from. |
address | Pointer 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.
address | Pointer 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
buf | Buffer where the data should be written to |
len | Maximum number of bytes to read into the buffer |
uint8_t nrfReadPayload | ( | void * | buf, |
uint8_t | len | ||
) |
Write the receive payload.
The size of data written is the fixed payload size, see getPayloadSize()
buf | Buffer to write the data to |
len | Maximum number of bytes to receive |
uint8_t nrfReadRegister | ( | uint8_t | reg | ) |
Read a byte from a register.
reg | Register address, see also tabel 28 of datasheet |
reg
uint8_t nrfReadRegisterMulti | ( | uint8_t | reg, |
uint8_t * | buf, | ||
uint8_t | len | ||
) |
Read multiple bytes from a register.
Prototypes of functions.
reg | Register address, see also tabel 28 of datasheet |
buf | Pointer to buffer to put data in |
len | Number of bytes to be received |
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.
enable | Whether 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.
pipe | Pipe number which you want to enable or disable |
enable | Whether 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:
uint8_t nrfSetDataRate | ( | nrf_rf_setup_rf_dr_t | speed | ) |
Set the transmission data rate.
The data rates correspond to the following speeds respectively:
speed | (is one of the group configurations) |
void nrfSetPALevel | ( | nrf_rf_setup_pwr_t | level | ) |
Set Power Amplifier (PA) level.
The power levels correspond to the following output levels respectively:
NRF_RF_SETUP_PWR_18DBM_gc
NRF_RF_SETUP_PWR_12DBM_gc
NRF_RF_SETUP_PWR_6DBM_gc
NRF_RF_SETUP_PWR_0DBM_gc
level | Desired 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.
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
buf | Pointer to the data to be sent |
len | Number 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().
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.
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
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
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.
[out] | tx_ok | The send was successful (TX_DS) |
[out] | tx_fail | The send failed, too many retries (MAX_RT) |
[out] | rx_ready | There 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
buf | Pointer to the data to be sent |
len | Number of bytes to be sent |
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.
pipe | Pipe number |
buf | Buffer to get the data from |
len | Number of bytes to be written |
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).
buf | Buffer to get the data from |
len | Number of bytes to be written |
writeType | W_TX_PAYLOAD: fixed data size W_TX_PAYLOAD_NO_ACK: variable data size (multicast) |
uint8_t nrfWriteRegister | ( | uint8_t | reg, |
uint8_t | value | ||
) |
Write a byte to a register.
reg | Register address, see also tabel 28 of datasheet |
value | The new value of the register |
uint8_t nrfWriteRegisterMulti | ( | uint8_t | reg, |
const uint8_t * | buf, | ||
uint8_t | len | ||
) |
Write multiple bytes to a register.
reg | Register address, see also tabel 28 of datasheet |
buf | Pointer to buffer with data to be sent |
len | Number of bytes to be sent |
This function is used at the inilialzation of NRF24L01p.
uint8_t addr_width = 5 |
The address width to use - 3,4 or 5 bytes.
uint8_t dynamic_payloads_enabled = 0 |
Whether dynamic payloads are enabled.
uint8_t fixed_payload_size = NRF_MAX_PAYLOAD_SIZE |
Size of a fixed payload.
uint8_t p_variant = 1 |
Global variables and constants.
1 for NRF24L01p 0 for NRF24L01
uint8_t pipe0_reading_address[5] = {0,0,0,0,0} |
Last address set on pipe 0 for reading.