|
FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
|
SPI device driver for Nordic Semiconductor nRF24L01+ support, without IRQ support. More...
#include <fastarduino/devices/nrf24l01p.h>


Classes | |
| struct | addr_t |
| Network address together with port. More... | |
| union | fifo_status_t |
| Register FIFO_STATUS data type, transmission queue status. More... | |
| union | observe_tx_t |
| Register OBSERVE_TX data type, performance statistics. More... | |
| union | status_t |
| Register STATUS data type. More... | |
Public Member Functions | |
| NRF24L01 (uint16_t net, uint8_t dev) | |
| Construct NRF transceiver with given channel and pin numbers for SPI slave select, activity enable and interrupt. | |
| uint8_t | get_channel () const |
| Get driver channel. | |
| uint16_t | get_network_address () const |
| Get driver network address. | |
| uint8_t | get_device_address () const |
| Get driver device address. | |
| void | set_address (int16_t net, uint8_t dev) |
| Set network and device address. | |
| void | set_channel (uint8_t channel) |
| Set device transmission channel. | |
| void | begin () |
| Start up the device driver. | |
| void | end () |
| Shut down the device driver. | |
| void | powerup () |
| Set power up mode. | |
| void | standby () |
| Set standby mode. | |
| void | powerdown () |
| Set power down. | |
| template<typename T , typename TREF = const T&> | |
| int | send (uint8_t dest, uint8_t port, TREF buf) |
| Send message with given object reference. | |
| int | send (uint8_t dest, uint8_t port) |
| Send an empty message. | |
| template<typename T , typename TREF = T&> | |
| int | recv (uint8_t &src, uint8_t &port, TREF buf, uint32_t ms=0L) |
| Receive message and store into given object reference. | |
| int | recv (uint8_t &src, uint8_t &port, uint32_t ms=0L) |
| Receive an empty message. | |
| void | set_output_power_level (int8_t dBm) |
| Set output power level (-30..10 dBm) | |
| uint16_t | get_trans () const |
| Return number of transmitted messages. | |
| uint16_t | get_retrans () const |
| Return number of retransmissions. | |
| uint16_t | get_drops () const |
| Return number of dropped messages. | |
| template<typename T , typename TREF = const T&> | |
| int | broadcast (uint8_t port, TREF buf) |
| Broadcast message with given object reference. | |
| bool | is_broadcast () const |
| Return true if the latest received message was a broadcast otherwise false. | |
Static Public Attributes | |
| static const uint8_t | BROADCAST = 0x00 |
| Broadcast device address. | |
| static const size_t | DEVICE_PAYLOAD_MAX = 32 |
| Maximum size of payload on device. | |
| static const size_t | PAYLOAD_MAX = DEVICE_PAYLOAD_MAX - 2 |
| Maximum size of payload. | |
Protected Types | |
| enum class | Command : uint8_t { R_REGISTER = 0x00 , W_REGISTER = 0x20 , REG_MASK = 0x1f , R_RX_PAYLOAD = 0x61 , W_TX_PAYLOAD = 0xa0 , FLUSH_TX = 0xe1 , FLUSH_RX = 0xe2 , REUSE_TX_PL = 0xe3 , R_RX_PL_WID = 0x60 , W_ACK_PAYLOAD = 0xa8 , PIPE_MASK = 0x07 , W_TX_PAYLOAD_NO_ACK = 0xb0 , NOP = 0xff } |
| SPI Commands (See chap. More... | |
| enum class | Register : uint8_t { CONFIG = 0x00 , EN_AA = 0x01 , EN_RXADDR = 0x02 , SETUP_AW = 0x03 , SETUP_RETR = 0x04 , RF_CH = 0x05 , RF_SETUP = 0x06 , STATUS = 0x07 , OBSERVE_TX = 0x08 , RPD = 0x09 , RX_ADDR_P0 = 0x0a , RX_ADDR_P1 = 0x0b , RX_ADDR_P2 = 0x0c , RX_ADDR_P3 = 0x0d , RX_ADDR_P4 = 0x0e , RX_ADDR_P5 = 0x0f , TX_ADDR = 0x10 , RX_PW_P0 = 0x11 , RX_PW_P1 = 0x12 , RX_PW_P2 = 0x13 , RX_PW_P3 = 0x14 , RX_PW_P4 = 0x15 , RX_PW_P5 = 0x16 , FIFO_STATUS = 0x17 , DYNPD = 0x1c , FEATURE = 0x1d } |
| NRF transceiver registers map (See chap. More... | |
| enum class | State : uint8_t { POWER_DOWN_STATE = 0 , STANDBY_STATE , RX_STATE , TX_STATE } |
| NRF transceiver states (See chap. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from spi::SPIDevice< CSN > | |
| SPIDevice () INLINE=default | |
Create a new SPIDevice; this sets up the CS pin for later use during transfers. | |
| void | start_transfer () |
| Start an SPI transfer to this device. | |
| void | end_transfer () INLINE |
| End the current SPI ransfer tot hsi device. | |
Protected Member Functions inherited from spi::AbstractSPIDevice | |
| AbstractSPIDevice (const AbstractSPIDevice &)=delete | |
| AbstractSPIDevice & | operator= (const AbstractSPIDevice &)=delete |
| uint8_t | transfer (uint8_t data) |
| Transfer one byte to the currently selected SPI slave device through MOSI pin, and get the byte returned by the device through MISO pin. | |
| void | transfer (uint8_t *data, uint16_t size) |
| Transfer an array of payload data to the currently selected SPI slave device through MOSI pin, and get all data bytes simultaneously received from that device through MISO pin. | |
| void | transfer (const uint8_t *data, uint16_t size) |
| Transfer an array of payload data to the currently selected SPI slave device through MOSI pin; any data bytes simultaneously received from that device through MISO pin are lost. | |
| void | transfer (uint8_t *data, uint16_t size, uint8_t sent) |
Transfer the provided byte sent several times to the currently selected SPI slave device through MOSI pin, and get all data bytes simultaneously received from that device through MISO pin. | |
| void | transfer (uint16_t size, uint8_t sent) |
Transfer the provided byte sent several times to the currently selected SPI slave device through MOSI pin; any data bytes simultaneously received from that device through MISO pin are lost. | |
SPI device driver for Nordic Semiconductor nRF24L01+ support, without IRQ support.
nRF24L01+ is a cheap 2.4GHz RX/TX chip.
It must be powered at 3.3V maximum but all its input pins are 5V tolerant, hence no level shifting is needed to operate it.
NRF24L01P
+------------+
(GND)------------—1-|GND | (3V3)------------—2-|VCC | (Dn)-------------—3-|CE | (Dn)-------------—4-|CSN | (SCK)------------—5-|SCK | (MOSI)-----------—6-|MOSI | (MISO)-----------—7-|MISO | –8-|IRQ | +---------—+ Notes:
| CSN | the board::DigitalPin connected to the CSN pin |
| CE | the board::DigitalPin connected to the CE pin |
Definition at line 85 of file nrf24l01p.h.
|
strongprotected |
SPI Commands (See chap.
8.3.1, tab. 20, pp. 51).
Definition at line 352 of file nrf24l01p.h.
|
strongprotected |
NRF transceiver registers map (See chap.
9, tab. 28, pp. 57).
Definition at line 378 of file nrf24l01p.h.
|
strongprotected |
NRF transceiver states (See chap.
6.1.1, fig. 4, pp. 22).
Definition at line 472 of file nrf24l01p.h.
| devices::rf::NRF24L01< CSN, CE >::NRF24L01 | ( | uint16_t | net, |
| uint8_t | dev | ||
| ) |
Construct NRF transceiver with given channel and pin numbers for SPI slave select, activity enable and interrupt.
Default in parenthesis (Standard/Mega Arduino/TinyX4).
| [in] | net | network address |
| [in] | dev | device address |
Definition at line 669 of file nrf24l01p.h.
|
inline |
|
inline |
|
inline |
|
inline |
Set network and device address.
Do not use the broadcast address(0). Should be used before calling begin().
| [in] | net | network address |
| [in] | dev | device address |
Definition at line 144 of file nrf24l01p.h.
|
inline |
Set device transmission channel.
Should be used before calling begin().
| [in] | channel |
Definition at line 155 of file nrf24l01p.h.
| void devices::rf::NRF24L01< CSN, CE >::begin | ( | ) |
Start up the device driver.
This must be called before any transmission or reception can take place.
Definition at line 671 of file nrf24l01p.h.
|
inline |
Shut down the device driver.
Definition at line 169 of file nrf24l01p.h.
| void devices::rf::NRF24L01< CSN, CE >::powerup | ( | ) |
Set power up mode.
Will initiate radio with necessary settings after power on reset.
Definition at line 696 of file nrf24l01p.h.
| void devices::rf::NRF24L01< CSN, CE >::standby | ( | ) |
Set standby mode.
Definition at line 713 of file nrf24l01p.h.
| void devices::rf::NRF24L01< CSN, CE >::powerdown | ( | ) |
Set power down.
Turn off radio and go into low power mode.
Definition at line 720 of file nrf24l01p.h.
|
inline |
Send message with given object reference.
| T | the type of buf (the object to transfer) |
| TREF | the type passed for buf, typically a const reference to type T |
| [in] | dest | destination network address |
| [in] | port | device port (or message type) |
| [in] | buf | reference of object to transmit |
| errors::EMSGSIZE | if len > PAYLOAD_MAX |
| errors::EIO | if a transmission failure happened |
Definition at line 208 of file nrf24l01p.h.
|
inline |
Send an empty message.
| [in] | dest | destination network address |
| [in] | port | device port (or message type) |
| errors::EMSGSIZE | if len > PAYLOAD_MAX |
| errors::EIO | if a transmission failure happened |
Definition at line 225 of file nrf24l01p.h.
|
inline |
Receive message and store into given object reference.
The source network address is returned in the parameter src.
| T | the type of buf (the object to be received) |
| TREF | the type passed for buf, typically a reference to type T |
| [out] | src | source network address |
| [out] | port | device port (or message type) |
| [out] | buf | reference to object to fill with received payload; note that no constructor will get called during this operation, it is best to use simple struct for type T. |
| [in] | ms | maximum time out period |
| errors::ETIME | if nothing was received and a timeout occurred after ms elapsed |
| errors::EMSGSIZE | if a payload error occurred from the chip (Tab. 20, pp. 51, R_RX_PL_WID) or the received payload size is bigger than the requested size |
Definition at line 255 of file nrf24l01p.h.
|
inline |
Receive an empty message.
The source network address is returned in the parameter src.
| [out] | src | source network address |
| [out] | port | device port (or message type) |
| [in] | ms | maximum time out period |
| errors::ETIME | if nothing was received and a timeout occurred after ms elapsed |
| errors::EMSGSIZE | if a payload error occurred from the chip (Tab. 20, pp. 51, R_RX_PL_WID) or the received payload size is bigger than the requested size |
Definition at line 277 of file nrf24l01p.h.
| void devices::rf::NRF24L01< CSN, CE >::set_output_power_level | ( | int8_t | dBm | ) |
|
inline |
Return number of transmitted messages.
Definition at line 292 of file nrf24l01p.h.
|
inline |
Return number of retransmissions.
Definition at line 301 of file nrf24l01p.h.
|
inline |
|
inline |
Broadcast message with given object reference.
Returns number of bytes sent if successful otherwise a negative error code.
| T | the type of buf (the object to transfer) |
| TREF | the type passed for buf, typically a const reference to type T |
| [in] | port | device port (or message type) |
| [in] | buf | reference of object to transmit |
Definition at line 329 of file nrf24l01p.h.
|
inline |
Return true if the latest received message was a broadcast otherwise false.
Definition at line 338 of file nrf24l01p.h.
|
static |
Broadcast device address.
Definition at line 89 of file nrf24l01p.h.
|
static |
Maximum size of payload on device.
Definition at line 94 of file nrf24l01p.h.
|
static |
Maximum size of payload.
The device allows 32 bytes payload. The source address one byte and port one byte as header.
Definition at line 100 of file nrf24l01p.h.