BayEOS-Arduino
1.8.0_0.0.4
|
#include <RF24.h>
Public Member Functions | |
Primary public interface | |
These are the main methods you need to operate the chip | |
RF24 (uint8_t _cepin, uint8_t _cspin) | |
RF24 (uint8_t _cepin, uint8_t _cspin, uint32_t spispeed) | |
bool | begin (void) |
void | startListening (void) |
void | stopListening (void) |
bool | available (void) |
void | read (void *buf, uint8_t len) |
bool | write (const void *buf, uint8_t len) |
void | openWritingPipe (const uint8_t *address) |
void | openReadingPipe (uint8_t number, const uint8_t *address) |
Optional Configurators | |
Methods you can use to get or set the configuration of the chip. None are required. Calling begin() sets up a reasonable set of defaults. | |
void | setAddressWidth (uint8_t a_width) |
void | setRetries (uint8_t delay, uint8_t count) |
void | setChannel (uint8_t channel) |
uint8_t | getChannel (void) |
void | setPayloadSize (uint8_t size) |
uint8_t | getPayloadSize (void) |
uint8_t | getDynamicPayloadSize (void) |
void | enableAckPayload (void) |
void | enableDynamicPayloads (void) |
void | enableDynamicAck () |
bool | isPVariant (void) |
void | setAutoAck (bool enable) |
void | setAutoAck (uint8_t pipe, bool enable) |
void | setPALevel (uint8_t level) |
uint8_t | getPALevel (void) |
bool | setDataRate (rf24_datarate_e speed) |
rf24_datarate_e | getDataRate (void) |
void | setCRCLength (rf24_crclength_e length) |
rf24_crclength_e | getCRCLength (void) |
void | disableCRC (void) |
void | maskIRQ (bool tx_ok, bool tx_fail, bool rx_ready) |
Deprecated | |
Methods provided for backwards compabibility. | |
void | openReadingPipe (uint8_t number, uint64_t address) |
void | openWritingPipe (uint64_t address) |
Protected Member Functions | |
void | beginTransaction () |
void | endTransaction () |
Advanced Operation | |
bool | failureDetected |
void | printDetails (void) |
bool | available (uint8_t *pipe_num) |
bool | rxFifoFull () |
void | powerDown (void) |
void | powerUp (void) |
bool | write (const void *buf, uint8_t len, const bool multicast) |
bool | writeFast (const void *buf, uint8_t len) |
bool | writeFast (const void *buf, uint8_t len, const bool multicast) |
bool | writeBlocking (const void *buf, uint8_t len, uint32_t timeout) |
bool | txStandBy () |
bool | txStandBy (uint32_t timeout, bool startTx=0) |
void | writeAckPayload (uint8_t pipe, const void *buf, uint8_t len) |
bool | isAckPayloadAvailable (void) |
void | whatHappened (bool &tx_ok, bool &tx_fail, bool &rx_ready) |
void | startFastWrite (const void *buf, uint8_t len, const bool multicast, bool startTx=1) |
void | startWrite (const void *buf, uint8_t len, const bool multicast) |
void | reUseTX () |
uint8_t | flush_tx (void) |
bool | testCarrier (void) |
bool | testRPD (void) |
bool | isValid () |
void | closeReadingPipe (uint8_t pipe) |
RF24::RF24 | ( | uint8_t | _cepin, |
uint8_t | _cspin | ||
) |
Arduino Constructor
Creates a new instance of this driver. Before using, you create an instance and send in the unique pins that this chip is connected to.
_cepin | The pin attached to Chip Enable on the RF module |
_cspin | The pin attached to Chip Select |
RF24::RF24 | ( | uint8_t | _cepin, |
uint8_t | _cspin, | ||
uint32_t | spispeed | ||
) |
Optional Raspberry Pi Constructor
Creates a new instance of this driver. Before using, you create an instance and send in the unique pins that this chip is connected to.
_cepin | The pin attached to Chip Enable on the RF module |
_cspin | The pin attached to Chip Select |
spispeed | For RPi, the SPI speed in MHZ ie: BCM2835_SPI_SPEED_8MHZ |
bool RF24::available | ( | void | ) |
bool RF24::available | ( | uint8_t * | pipe_num | ) |
Test whether there are bytes available to be read in the FIFO buffers.
[out] | pipe_num | Which pipe has the payload available |
bool RF24::begin | ( | void | ) |
|
inlineprotected |
void RF24::closeReadingPipe | ( | uint8_t | pipe | ) |
void RF24::disableCRC | ( | void | ) |
void RF24::enableAckPayload | ( | 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 RF24::enableDynamicAck | ( | void | ) |
Enable dynamic ACKs (single write multicast or unicast) for chosen messages
void RF24::enableDynamicPayloads | ( | void | ) |
uint8_t RF24::flush_tx | ( | void | ) |
Empty the transmit buffer. This is generally not required in standard operation. May be required in specific cases after stopListening() , if operating at 250KBPS data rate.
uint8_t RF24::getChannel | ( | void | ) |
rf24_crclength_e RF24::getCRCLength | ( | void | ) |
rf24_datarate_e RF24::getDataRate | ( | void | ) |
uint8_t RF24::getDynamicPayloadSize | ( | void | ) |
Get Dynamic Payload Size
For dynamic payloads, this pulls the size of the payload off the chip
uint8_t RF24::getPALevel | ( | void | ) |
uint8_t RF24::getPayloadSize | ( | void | ) |
bool RF24::isAckPayloadAvailable | ( | void | ) |
Determine if an ack payload was received in the most recent call to write(). The regular available() can also be used.
Call read() to retrieve the ack payload.
bool RF24::isPVariant | ( | void | ) |
|
inline |
void RF24::maskIRQ | ( | bool | tx_ok, |
bool | tx_fail, | ||
bool | rx_ready | ||
) |
The radio will generate interrupt signals when a transmission is complete, a transmission fails, or a payload is received. This allows users to mask those interrupts to prevent them from generating a signal on the interrupt pin. Interrupts are enabled on the radio chip by default.
tx_ok | Mask transmission complete interrupts |
tx_fail | Mask transmit failure interrupts |
rx_ready | Mask payload received interrupts |
void RF24::openReadingPipe | ( | uint8_t | number, |
const 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().
number | Which pipe# to open, 0-5. |
address | The 24, 32 or 40 bit address of the pipe to open. |
void RF24::openReadingPipe | ( | uint8_t | number, |
uint64_t | address | ||
) |
Open a pipe for reading
number | Which pipe# to open, 0-5. |
address | The 40-bit address of the pipe to open. |
void RF24::openWritingPipe | ( | const uint8_t * | address | ) |
New: Open a pipe for writing via byte array. Old addressing format retained for compatibility.
Only one writing pipe can be open at once, but you can change the address you'll write to. Call stopListening() first.
Addresses are assigned via a byte array, default is 5 byte address length s *
address | The address of the pipe to open. Coordinate these pipe addresses amongst nodes on the network. |
void RF24::openWritingPipe | ( | uint64_t | address | ) |
Open a pipe for writing
Addresses are 40-bit hex values, e.g.:
address | The 40-bit address of the pipe to open. |
void RF24::powerDown | ( | void | ) |
Enter low-power mode
To return to normal power mode, call powerUp().
void RF24::powerUp | ( | void | ) |
Leave low-power mode - required for normal radio operation after calling powerDown()
To return to low power mode, call powerDown().
void RF24::printDetails | ( | void | ) |
void RF24::read | ( | void * | buf, |
uint8_t | len | ||
) |
Read the available payload
The size of data read is the fixed payload size, see getPayloadSize()
buf | Pointer to a buffer where the data should be written |
len | Maximum number of bytes to read into the buffer |
void RF24::reUseTX | ( | ) |
This function is mainly used internally to take advantage of the auto payload re-use functionality of the chip, but can be beneficial to users as well.
The function will instruct the radio to re-use the data in the FIFO buffers, and instructs the radio to re-send once the timeout limit has been reached. Used by writeFast and writeBlocking to initiate retries when a TX failure occurs. Retries are automatically initiated except with the standard write(). This way, data is not flushed from the buffer until switching between modes.
bool RF24::rxFifoFull | ( | ) |
void RF24::setAddressWidth | ( | uint8_t | a_width | ) |
void RF24::setAutoAck | ( | bool | enable | ) |
void RF24::setAutoAck | ( | uint8_t | pipe, |
bool | enable | ||
) |
Enable or disable auto-acknowlede packets on a per pipeline basis.
AA is enabled by default, so it's only needed if you want to turn it off/on for some reason on a per pipeline basis.
pipe | Which pipeline to modify |
enable | Whether to enable (true) or disable (false) auto-acks |
void RF24::setChannel | ( | uint8_t | channel | ) |
void RF24::setCRCLength | ( | rf24_crclength_e | length | ) |
bool RF24::setDataRate | ( | rf24_datarate_e | speed | ) |
void RF24::setPALevel | ( | uint8_t | level | ) |
Set Power Amplifier (PA) level to one of four levels: RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
The power levels correspond to the following output levels respectively: NRF24L01: -18dBm, -12dBm,-6dBM, and 0dBm
SI24R1: -6dBm, 0dBm, 3dBM, and 7dBm.
level | Desired PA level. |
void RF24::setPayloadSize | ( | uint8_t | size | ) |
Set Static Payload Size
This implementation uses a pre-stablished fixed payload size for all transmissions. If this method is never called, the driver will always transmit the maximum payload size (32 bytes), no matter how much was sent to write().
size | The number of bytes in the payload |
void RF24::setRetries | ( | uint8_t | delay, |
uint8_t | count | ||
) |
void RF24::startFastWrite | ( | const void * | buf, |
uint8_t | len, | ||
const bool | multicast, | ||
bool | startTx = 1 |
||
) |
Non-blocking write to the open writing pipe used for buffered writes
For single noAck writes see:
buf | Pointer to the data to be sent |
len | Number of bytes to be sent |
multicast | Request ACK (0) or NOACK (1) |
void RF24::startListening | ( | void | ) |
Start listening on the pipes opened for reading.
void RF24::startWrite | ( | const void * | buf, |
uint8_t | len, | ||
const bool | multicast | ||
) |
Non-blocking write to the open writing pipe
Just like write(), but it returns immediately. To find out what happened to the send, catch the IRQ and then call whatHappened().
For single noAck writes see:
buf | Pointer to the data to be sent |
len | Number of bytes to be sent |
multicast | Request ACK (0) or NOACK (1) |
void RF24::stopListening | ( | void | ) |
bool RF24::testCarrier | ( | void | ) |
bool RF24::testRPD | ( | void | ) |
Test whether a signal (carrier or otherwise) greater than or equal to -64dBm is present on the channel. Valid only on nRF24L01P (+) hardware. On nRF24L01, use testCarrier().
Useful to check for interference on the current channel and channel hopping strategies.
bool RF24::txStandBy | ( | ) |
This function should be called as soon as transmission is finished to drop the radio back to STANDBY-I mode. If not issued, the radio will remain in STANDBY-II mode which, per the data sheet, is not a recommended operating mode.
Relies on built-in auto retry functionality.
bool RF24::txStandBy | ( | uint32_t | timeout, |
bool | startTx = 0 |
||
) |
This function allows extended blocking and auto-retries per a user defined timeout
timeout | Number of milliseconds to retry failed payloads |
void RF24::whatHappened | ( | bool & | tx_ok, |
bool & | tx_fail, | ||
bool & | rx_ready | ||
) |
Call this when you get an interrupt to find out why
Tells you what caused the interrupt, and clears the state of interrupts.
[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_DS) |
bool RF24::write | ( | const void * | buf, |
uint8_t | len | ||
) |
Be sure to call openWritingPipe() first to set the destination of where to write to.
This blocks until the message is successfully acknowledged by the receiver or the timeout/retransmit maxima are reached. In the current configuration, the max delay here is 60-70ms.
The maximum size of data written is the fixed payload size, see getPayloadSize(). However, you can write less, and the remainder will just be filled with zeroes.
TX/RX/RT interrupt flags will be cleared every time write is called
buf | Pointer to the data to be sent |
len | Number of bytes to be sent |
bool RF24::write | ( | const void * | buf, |
uint8_t | len, | ||
const bool | multicast | ||
) |
Write for single NOACK writes. Optionally disables acknowledgements/autoretries for a single write.
Can be used with enableAckPayload() to request a response
buf | Pointer to the data to be sent |
len | Number of bytes to be sent |
multicast | Request ACK (0), NOACK (1) |
void RF24::writeAckPayload | ( | uint8_t | pipe, |
const void * | 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 | Which pipe# (typically 1-5) will get this response. |
buf | Pointer to data that is sent |
len | Length of the data to send, up to 32 bytes max. Not affected by the static payload set by setPayloadSize(). |
bool RF24::writeBlocking | ( | const void * | buf, |
uint8_t | len, | ||
uint32_t | timeout | ||
) |
This function extends the auto-retry mechanism to any specified duration. It will not block until the 3 FIFO buffers are filled with data. If so the library will auto retry until a new payload is written or the user specified timeout period is reached.
buf | Pointer to the data to be sent |
len | Number of bytes to be sent |
timeout | User defined timeout in milliseconds. |
bool RF24::writeFast | ( | const void * | buf, |
uint8_t | len | ||
) |
This will not block until the 3 FIFO buffers are filled with data. Once the FIFOs are full, writeFast will simply wait for success or timeout, and return 1 or 0 respectively. From a user perspective, just keep trying to send the same data. The library will keep auto retrying the current payload using the built in functionality.
buf | Pointer to the data to be sent |
len | Number of bytes to be sent |
bool RF24::writeFast | ( | const void * | buf, |
uint8_t | len, | ||
const bool | multicast | ||
) |
WriteFast for single NOACK writes. Disables acknowledgements/autoretries for a single write.
buf | Pointer to the data to be sent |
len | Number of bytes to be sent |
multicast | Request ACK (0) or NOACK (1) |
bool RF24::failureDetected |
Enable error detection by un-commenting #define FAILURE_HANDLING in RF24_config.h If a failure has been detected, it usually indicates a hardware issue. By default the library will cease operation when a failure is detected. This should allow advanced users to detect and resolve intermittent hardware issues.
In most cases, the radio must be re-enabled via radio.begin(); and the appropriate settings applied after a failure occurs, if wanting to re-enable the device immediately.
Usage: (Failure handling must be enabled per above)