![]() |
nrf24l01+ Library
|
Functions for simple radio use. More...
Functions | |
void | nrf_setup () |
Sets up the radio, SPI, and interrupts. Also resets all radio registers to their default values. | |
int | nrf_get_payload_width () |
Get the width of the top payload in the RX FIFO. More... | |
int | nrf_get_payload (char *buff, char len) |
Read a received payload. More... | |
int | nrf_payload_available () |
Check if a payload is available to be read. More... | |
int | nrf_get_pipe () |
Get the number of the pipe the most recent payload was received on. More... | |
int | nrf_get_width () |
Get the width of the most recently received payload. More... | |
void | nrf_state_pwr_down () |
Put the radio in the power down state. | |
void | nrf_state_standby_1 () |
Put the radio in the standby 1 state. | |
void | nrf_state_rx_mode () |
Put the radio in the rx mode state. | |
void | nrf_set_transmit_pwr (char power) |
Set power of transmitter. More... | |
void | nrf_set_transmit_rate (char rate) |
Set data rate. More... | |
void | nrf_set_arc (char arc) |
Set the auto retransmit count. More... | |
void | nrf_set_rf_ch (char ch) |
Set the RF frequency the radio will operate at. More... | |
char | nrf_received_pipe_num () |
Returns the pipe data is available in. More... | |
void | nrf_set_address_width (char width) |
Set the address width of RX and TX pipes. More... | |
void | nrf_start_cont_wave (char pwr) |
Send a constant carrier wave out at specified power. More... | |
void | nrf_stop_cont_wave () |
Stop sending the carrier wave. More... | |
char | nrf_received_pwr () |
Check the power of the signal the nrf42l01 is receiving. More... | |
void | nrf_en_aa (int pipe) |
Enable auto-acknowledge for a pipe. More... | |
void | nrf_dis_aa (int pipe) |
Disable auto-acknowledge for a pipe. More... | |
void | nrf_en_rxaddr (int pipe) |
Enable a pipe to receive packets. More... | |
void | nrf_dis_rxaddr (int pipe) |
Disable a pipe from receiving packets. More... | |
void | nrf_set_pw (char width, int pipe) |
Set the width received static payloads should be. More... | |
void | nrf_en_dpl (int pipe) |
Enable dynamic payload length for a pipe. More... | |
void | nrf_dis_dpl (int pipe) |
Disable dynamic payload length for a pipe. More... | |
int | nrf_set_rx_addr (int pipe, uint64_t address, int len) |
Set the address of a pipe. More... | |
void | nrf_set_tx_addr (uint64_t address) |
Set the address for transmitting. More... | |
void | nrf_reset () |
Resets all registers to their default values as listed on the datasheet. More... | |
int | nrf_send_payload (char *data, char len) |
Send a payload over the radio. More... | |
Functions for simple radio use.
This group contains functions intended for simple radio use. There are more advanced functions available for developers and for more advanced radio control in the nrf24l01.h.
void nrf_dis_aa | ( | int | pipe | ) |
Disable auto-acknowledge for a pipe.
pipe | The pipe to autoack will be disabled on. Pipes range from 0 to 5. |
void nrf_dis_dpl | ( | int | pipe | ) |
Disable dynamic payload length for a pipe.
If dynamic payload length is disabled the length of a packet must be set using nrf_set_pw.
pipe | Which pipe to disable dynamic payload length on. |
void nrf_dis_rxaddr | ( | int | pipe | ) |
Disable a pipe from receiving packets.
pipe | The pipe that will be disabled. Pipes range from 0 to 5. |
void nrf_en_aa | ( | int | pipe | ) |
Enable auto-acknowledge for a pipe.
This function will enable receiving on a pipe automatically in addition to enabling auto-acknowledge as if nrf_en_rxaddr was called.
pipe | The pipe autoack will be enabled on. Pipes range from 0 to 5. |
void nrf_en_dpl | ( | int | pipe | ) |
Enable dynamic payload length for a pipe.
If dynamic payload length is enabled the number of bytes in a packet does not need to be specified. For this feature to work the transmitter must have dynamic payload length enabled for pipe 0 and the receiver must have dynamic payload length enabled for the pipe it will receive from this transmitter on.
pipe | The pipe dynamic payload length will be enabled on. |
void nrf_en_rxaddr | ( | int | pipe | ) |
Enable a pipe to receive packets.
The nrf24l01+ contains six parallel pipes that can receive packets from six different transmitters. Each pipe must have a unique address.
pipe | The pipe that will be enabled. Pipes range from 0 to 5. |
int nrf_get_payload | ( | char * | buff, |
char | len | ||
) |
Read a received payload.
Read a payload into an array if one is available. If dynamic payload length is enabled the length of the payload can be found using nrf_get_width. If a payload is read, it is no longer available. This function should only be called if nrf_payload_available() returns 1.
buff | The array the payload will be read into. |
len | Length of the payload that will be read (1-32 bytes). |
int nrf_get_payload_width | ( | ) |
Get the width of the top payload in the RX FIFO.
This function is only meant for use with dynamic payload lengths.
int nrf_get_pipe | ( | ) |
Get the number of the pipe the most recent payload was received on.
int nrf_get_width | ( | ) |
Get the width of the most recently received payload.
int nrf_payload_available | ( | ) |
Check if a payload is available to be read.
This function should be used to poll for received payloads.
char nrf_received_pipe_num | ( | ) |
Returns the pipe data is available in.
If 8 is returned the FIFO is empty and no data was received.
char nrf_received_pwr | ( | ) |
Check the power of the signal the nrf42l01 is receiving.
RX mode must be enabled for at least 40 us before measurements will be accurate. 0 will be returned if power level is below -64dB and 1 will be returned if power level is above -64dB.
void nrf_reset | ( | ) |
Resets all registers to their default values as listed on the datasheet.
/**
int nrf_send_payload | ( | char * | data, |
char | len | ||
) |
Send a payload over the radio.
/**
If auto-acknowledge is disabled this function will return 1 when the packet is successfully sent and does not reflect the packet being acknowledged. This function will never return 0 if auto-acknowledge is disabled. If auto- acknowledge is enabled this function returns 1 when a packet is acknowledged after being sent and 0 if the packet is not acknowledged.
data | The payload to be sent. |
len | The length of the payload in bytes. |
void nrf_set_address_width | ( | char | width | ) |
Set the address width of RX and TX pipes.
Sets the address width of all receiving pipes and the transmitting address width.
width | The address width to be set in bytes (3-5 bytes) |
void nrf_set_arc | ( | char | arc | ) |
Set the auto retransmit count.
Set how many times the nrf24l01 should attempt to retransmit the packet after not receiving an acknowledgment packet.
arc | The amount of times the radio should attempt to retransmit. |
void nrf_set_pw | ( | char | width, |
int | pipe | ||
) |
Set the width received static payloads should be.
When using static payload widths the width of packets must be explicitly set. The receiver's width must be set to the size of the payloads being transmitted. Use this function to set the width on the receiver. This function is unnecessary for a pipe if dynamic payload length is enabled on that pipe.
width | The number of bytes the pipe will be set to receive in a static payload. (1-32 bytes) |
pipe | The pipe whose payload width will be set. |
void nrf_set_rf_ch | ( | char | ch | ) |
Set the RF frequency the radio will operate at.
The nrf24l01 can operate at frequencies ranging from 2.400GHz to 2.525 GHz. At 250 kbps or 1 Mbps the radio occupies less than a 1MHz bandwidth. At 2 Mbps the radio occupies less than a 2 MHz bandwidth. The frequency is set according to the equation, frequency = 2400 + ch (MHz). The transmitter and receiver must be set operate at the same frequency to communicate. This function will set the center frequency of the radio.
ch | The frequency the radio should transmit at. |
int nrf_set_rx_addr | ( | int | pipe, |
uint64_t | address, | ||
int | len | ||
) |
Set the address of a pipe.
The nrf24l01 has six pipes to receive on. Pipes have addresses that are 3-5 bytes long. Pipes 0 and 1 can have all 5 bytes of their addresses changed. The other four pipes can only have the LSB of their address changed. The four MSBs of the other four pipes are the MSBs of the address of pipe 1. The address width must be set using nrf_set_address_width before calling this function. If the address width set does not match the length specified in this function 0 will be returned and the address will not be written. 0 will also be returned if length is not set to 1 when writing to pipes 2-5.
pipe | The pipe whose address will be set. Pipes range from 0-5. |
address | Address pipe will be set to. |
len | The length of the address being set in bytes. (1-5 bytes) |
void nrf_set_transmit_pwr | ( | char | power | ) |
Set power of transmitter.
The possible power settings are:
0dBm: nrf24l01_RF_SETUP_RF_PWR_0
-6dBm: nrf24l01_RF_SETUP_RF_PWR_6
-12dBm: nrf24l01_RF_SETUP_RF_PWR_12
-18dBm: nrf24l01_RF_SETUP_RF_PWR_18
power | Power level the transmitter will be set to. |
void nrf_set_transmit_rate | ( | char | rate | ) |
Set data rate.
The possible rate settings are:
250 kbps: nrf24l01_DR_LOW
1 Mbps: nrf24l01_DR_MED
2 Mbps: nrf24l01_DR_HIGH
rate | Rate the transmitter will be set to. |
void nrf_set_tx_addr | ( | uint64_t | address | ) |
Set the address for transmitting.
The address of the transmitter should match the address of the receiver or packets will not be received. If auto acknowledge is enabled rx pipe 0 on the transmitter must be set to the same address as the tx address set in this function.
address | The address that will be set for transmitting. (5 bytes) |
void nrf_start_cont_wave | ( | char | pwr | ) |
Send a constant carrier wave out at specified power.
Send a continuous carrier wave for testing purposes. Wave can be stopped by calling nrf_stop_cont_wave.
pwr | Power level to set transmitter to. Possible values are: 0dBm: nrf24l01_RF_SETUP_RF_PWR_0 -6dBm: nrf24l01_RF_SETUP_RF_PWR_6 -12dBm: nrf24l01_RF_SETUP_RF_PWR_12 -18dBm: nrf24l01_RF_SETUP_RF_PWR_18 |
void nrf_stop_cont_wave | ( | ) |
Stop sending the carrier wave.
This function should only be called some time after nrf_start_cont_wave has been called.