COSA
An Object-Oriented Platform for Arduino Programming
|
#include <NRF24L01P.hh>
Classes | |
union | fifo_status_t |
class | IRQPin |
union | observe_tx_t |
union | status_t |
Public Member Functions | |
NRF24L01P (uint16_t net, uint8_t dev, Board::DigitalPin csn=Board::D10, Board::DigitalPin ce=Board::D9, Board::ExternalInterruptPin irq=Board::EXT0) | |
void | powerup () |
void | standby () |
virtual void | powerdown () |
virtual bool | begin (const void *config=NULL) |
virtual bool | end () |
virtual bool | available () |
virtual int | send (uint8_t dest, uint8_t port, const iovec_t *vec) |
virtual int | send (uint8_t dest, uint8_t port, const void *buf, size_t len) |
virtual int | recv (uint8_t &src, uint8_t &port, void *buf, size_t count, uint32_t ms=0L) |
virtual void | output_power_level (int8_t dBm) |
uint16_t | trans () const |
uint16_t | retrans () const |
uint16_t | drops () const |
uint8_t | channel () const |
void | channel (uint8_t channel) |
int16_t | network_address () const |
uint8_t | device_address () const |
void | address (int16_t net, uint8_t dev) |
virtual void | wakeup_on_radio () |
virtual bool | room () |
virtual int | broadcast (uint8_t port, const iovec_t *vec) |
virtual int | broadcast (uint8_t port, const void *buf, size_t len) |
virtual bool | is_broadcast () |
virtual int | input_power_level () |
virtual int | link_quality_indicator () |
Static Public Attributes | |
static const size_t | DEVICE_PAYLOAD_MAX = 32 |
static const size_t | PAYLOAD_MAX = DEVICE_PAYLOAD_MAX - 2 |
static const uint8_t | BROADCAST = 0x00 |
Protected Types | |
enum | State { POWER_DOWN_STATE = 0, STANDBY_STATE, RX_STATE, TX_STATE } |
enum | Command { 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 } |
enum | Register { 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 } |
enum | { MASK_RX_DR = 6, MASK_TX_DS = 5, MASK_MAX_RT = 4, EN_CRC = 3, CRCO = 2, PWR_UP = 1, PRIM_RX = 0 } |
enum | { POWER_DOWN = 0, POWER_UP = _BV(PWR_UP) } |
enum | { ENAA_P5 = 5, ENAA_P4 = 4, ENAA_P3 = 3, ENAA_P2 = 2, ENAA_P1 = 1, ENAA_P0 = 0, ENAA_PA = 0x3f } |
enum | { ERX_P5 = 5, ERX_P4 = 4, ERX_P3 = 3, ERX_P2 = 2, ERX_P1 = 1, ERX_P0 = 0, ERX_PA = 0x3f } |
enum | { AW = 0, AW_3BYTES = 1, AW_4BYTES = 2, AW_5BYTES = 3 } |
enum | { ARD = 4, DEFAULT_ARD = 2, ARC = 0, DEFAULT_ARC = 15 } |
enum | { CONT_WAVE = 7, RF_DR_LOW = 5, PLL_LOCK_SIGNAL = 4, RF_DR_HIGH = 3, RF_PWR = 1 } |
enum | { RF_DR_1MBPS = 0, RF_DR_2MBPS = _BV(RF_DR_HIGH), RF_DR_250KBPS = _BV(RF_DR_LOW) } |
enum | { RF_PWR_18DBM = 0, RF_PWR_12DBM = 2, RF_PWR_6DBM = 4, RF_PWR_0DBM = 6 } |
enum | { RX_DR = 6, TX_DS = 5, MAX_RT = 4, RX_P_NO = 1, RX_P_NO_MASK = 0x0e, RX_P_NO_NONE = 0x07, TX_FIFO_FULL = 0 } |
enum | { PLOS_CNT = 4, ARC_CNT = 0 } |
enum | { TX_REUSE = 6, TX_FULL = 5, TX_EMPTY = 4, RX_FULL = 1, RX_EMPTY = 0 } |
enum | { DPL_P5 = 5, DPL_P4 = 4, DPL_P3 = 3, DPL_P2 = 2, DPL_P1 = 1, DPL_P0 = 0, DPL_PA = 0x3f } |
enum | { EN_DPL = 2, EN_ACK_PAY = 1, EN_DYN_ACK = 0 } |
enum | { AW_MAX = 5, PIPE_MAX = 6 } |
Protected Member Functions | |
uint8_t | read (Command cmd) |
void | read (Command cmd, void *buf, size_t size) |
void | write (Command cmd) |
void | write (Command cmd, uint8_t data) |
void | write (Command cmd, const void *buf, size_t size) |
uint8_t | read (Register reg) |
void | read (Register reg, void *buf, size_t size) |
void | write (Register reg, uint8_t data) |
void | write (Register reg, const void *buf, size_t size) |
status_t | read_status () |
fifo_status_t | read_fifo_status () |
observe_tx_t | read_observe_tx () |
void | transmit_mode (uint8_t dest) |
void | receiver_mode () |
void | set_clock (Clock rate) |
void | set_clock (uint32_t freq) |
Static Protected Member Functions | |
static Clock | clock (uint32_t freq) |
static Clock | cycle (uint16_t ns) |
Protected Attributes | |
OutputPin | m_ce |
Chip enable activity RX/TX select pin. More... | |
IRQPin | m_irq |
Chip interrupt pin and handler. More... | |
status_t | m_status |
Latest status. More... | |
State | m_state |
Transceiver state. More... | |
uint16_t | m_trans |
Send count. More... | |
uint16_t | m_retrans |
Retransmittion count. More... | |
uint16_t | m_drops |
Dropped messages. More... | |
Driver * | m_next |
List of drivers. More... | |
OutputPin | m_cs |
Device chip select pin. More... | |
Pulse | m_pulse |
Chip select pulse width. More... | |
uint8_t | m_spcr |
SPI/SPCR hardware control register setting. More... | |
uint8_t | m_spsr |
SPI/SPSR hardware status register. More... | |
uint8_t | m_channel |
Current channel (device dependent. More... | |
addr_t | m_addr |
Current network and device address. More... | |
volatile bool | m_avail |
Message available. May be set by ISR. More... | |
uint8_t | m_dest |
Latest message destination device address. More... | |
Static Protected Attributes | |
static const uint16_t | Tpd2stby_ms = 3 |
static const uint16_t | Tstby2a_us = 130 |
static const uint16_t | Thce_us = 10 |
Friends | |
IOStream & | operator<< (IOStream &outs, status_t status) |
IOStream & | operator<< (IOStream &outs, fifo_status_t status) |
IOStream & | operator<< (IOStream &outs, observe_tx_t observe) |
Nordic Semiconductor nRF24L01+ Single Chip 2.4GHz Transceiver device driver.
This is the pin-out for the NRF24L01+ module. NRF24L01+ is a low voltage device (3V3) and input signals are 5V tolerant.
Definition at line 56 of file NRF24L01P.hh.
|
protected |
Register CONFIG bitfields, configuration.
Enumerator | |
---|---|
MASK_RX_DR |
Mask interrupt caused by RX_DR. |
MASK_TX_DS |
Mask interrupt caused by TX_DS. |
MASK_MAX_RT |
Mask interrupt caused byt MAX_RT. |
EN_CRC |
Enable CRC. |
CRCO |
CRC encoding scheme (2/1 bytes CRC). |
PWR_UP |
Power up/down. |
PRIM_RX |
RX/TX control (PRX/PTX). |
Definition at line 323 of file NRF24L01P.hh.
|
protected |
Enumerator | |
---|---|
POWER_DOWN |
PWR_UP bit settings. |
POWER_UP |
Definition at line 333 of file NRF24L01P.hh.
|
protected |
Register EN_AA bitfields, auto acknowledgement.
Definition at line 341 of file NRF24L01P.hh.
|
protected |
Register EN_RXADDR bitfields, enable receive pipe.
Enumerator | |
---|---|
ERX_P5 |
Enable data pipe 5. |
ERX_P4 |
|
ERX_P3 |
|
ERX_P2 |
|
ERX_P1 |
|
ERX_P0 |
|
ERX_PA |
Enable all data pipes. |
Definition at line 354 of file NRF24L01P.hh.
|
protected |
Register SETUP_AW bitfields, setup address width (3..5).
Enumerator | |
---|---|
AW |
RX/TX address field width (bits 2). |
AW_3BYTES |
3 bytes. |
AW_4BYTES |
4 bytes. |
AW_5BYTES |
5 bytes. |
Definition at line 367 of file NRF24L01P.hh.
|
protected |
Register SETUP_RETR bitfields, configure retransmission.
Definition at line 377 of file NRF24L01P.hh.
|
protected |
Register RF_SETUP bitfields, radio configuration.
Definition at line 389 of file NRF24L01P.hh.
|
protected |
Transmission rates RF_DR_LOW/RF_DR_HIGH values, radio bit-rate.
Enumerator | |
---|---|
RF_DR_1MBPS |
1 Mbps. |
RF_DR_2MBPS |
2 Mbps. |
RF_DR_250KBPS |
250 Kbps. |
Definition at line 400 of file NRF24L01P.hh.
|
protected |
Output power RF_PWR values, radio power setting.
Enumerator | |
---|---|
RF_PWR_18DBM |
-18dBm. |
RF_PWR_12DBM |
-12dBm. |
RF_PWR_6DBM |
-6dBm. |
RF_PWR_0DBM |
0dBm. |
Definition at line 409 of file NRF24L01P.hh.
|
protected |
Register STATUS bitfields.
Definition at line 419 of file NRF24L01P.hh.
|
protected |
Register OBSERVE_TX bitfields, performance statistics.
Enumerator | |
---|---|
PLOS_CNT |
Count lost packets (bits 4). |
ARC_CNT |
Count retransmitted packets (bits 4). |
Definition at line 456 of file NRF24L01P.hh.
|
protected |
Register FIFO_STATUS bitfields, transmission queue status.
Enumerator | |
---|---|
TX_REUSE |
Reuse last transmitted data packat. |
TX_FULL |
TX FIFO full flag. |
TX_EMPTY |
TX FIFO empty flag. |
RX_FULL |
RX FIFO full flag. |
RX_EMPTY |
RX FIFO empty flag. |
Definition at line 485 of file NRF24L01P.hh.
|
protected |
Register DYNPD bitfields.
Definition at line 521 of file NRF24L01P.hh.
|
protected |
Register FEATURE bitfields.
Enumerator | |
---|---|
EN_DPL |
Enable dynamic payload length. |
EN_ACK_PAY |
Enable payload with ACK. |
EN_DYN_ACK |
Enable the W_TX_PAYLOAD_NOACK command. |
Definition at line 534 of file NRF24L01P.hh.
|
protected |
Configuration max values.
Enumerator | |
---|---|
AW_MAX |
Max address width in bytes. |
PIPE_MAX |
Max number of pipes. |
Definition at line 599 of file NRF24L01P.hh.
|
protected |
SPI Commands (See chap. 8.3.1, tab. 20, pp. 51).
Definition at line 236 of file NRF24L01P.hh.
|
protected |
NRF transceiver registers map (See chap. 9, tab. 28, pp. 57).
Definition at line 291 of file NRF24L01P.hh.
|
protected |
NRF transceiver states (See chap. 6.1.1, fig. 4, pp. 22).
Enumerator | |
---|---|
POWER_DOWN_STATE | |
STANDBY_STATE | |
RX_STATE | |
TX_STATE |
Definition at line 226 of file NRF24L01P.hh.
NRF24L01P::NRF24L01P | ( | uint16_t | net, |
uint8_t | dev, | ||
Board::DigitalPin | csn = Board::D10 , |
||
Board::DigitalPin | ce = Board::D9 , |
||
Board::ExternalInterruptPin | irq = Board::EXT0 |
||
) |
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. |
[in] | csn | spi slave select pin number (default D10/D53/D2). |
[in] | ce | chip enable activates pin number (default D9/D48/D3). |
[in] | irq | interrupt pin number (default EXT0/EXT4/EXT0). |
Definition at line 28 of file NRF24L01P.cpp.
|
inlineinherited |
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 106 of file Wireless.hh.
|
virtual |
Return true(1) if the data to receive on the device otherwise false(0).
Reimplemented from Wireless::Driver.
Definition at line 280 of file NRF24L01P.cpp.
|
virtual |
Start up the device driver. Return true(1) if successful otherwise false(0).
[in] | config | device configuration (default NULL). |
Implements Wireless::Driver.
Definition at line 178 of file NRF24L01P.cpp.
|
inlinevirtualinherited |
Broadcast message in given null terminated io vector. Returns number of bytes sent if successful otherwise a negative error code.
[in] | port | device port (or message type). |
[in] | vec | null termianted io vector. |
Definition at line 220 of file Wireless.hh.
|
inlinevirtualinherited |
Boardcast message in given buffer, with given number of bytes. Returns number of bytes sent if successful otherwise a negative error code.
[in] | port | device port (or message type). |
[in] | buf | buffer to transmit. |
[in] | len | number of bytes in buffer. |
Definition at line 235 of file Wireless.hh.
|
inlineinherited |
|
inlineinherited |
Set device transmission channel. Should be used before calling begin().
[in] | channel. |
Definition at line 117 of file Wireless.hh.
|
inlinestaticinherited |
|
inlinestaticinherited |
|
inlineinherited |
|
inline |
|
inlinevirtual |
Shut down the device driver. Return true(1) if successful otherwise false(0).
Reimplemented from Wireless::Driver.
Definition at line 128 of file NRF24L01P.hh.
|
inlinevirtualinherited |
Return estimated input power level (dBm). Default zero(0).
Reimplemented in CC1101, and RFM69.
Definition at line 282 of file Wireless.hh.
|
inlinevirtualinherited |
Return true(1) if the latest received message was a broadcast otherwise false(0).
Definition at line 262 of file Wireless.hh.
|
inlinevirtualinherited |
Return link quality indicator. Default zero(0).
Reimplemented in VWI, and CC1101.
Definition at line 292 of file Wireless.hh.
|
inlineinherited |
|
virtual |
Set output power level (-30..10 dBm)
[in] | dBm. |
Reimplemented from Wireless::Driver.
Definition at line 328 of file NRF24L01P.cpp.
|
virtual |
Set power down. Turn off radio and go into low power mode.
Reimplemented from Wireless::Driver.
Definition at line 169 of file NRF24L01P.cpp.
|
virtual |
Set power up mode. Will initiate radio with necessary settings after power on reset.
Reimplemented from Wireless::Driver.
Definition at line 112 of file NRF24L01P.cpp.
|
protected |
Issue read command register.
[in] | cmd | command. |
Definition at line 46 of file NRF24L01P.cpp.
|
protected |
Read command values into given buffer.
[in] | cmd | command. |
[in] | buf | buffer for read data. |
[in] | size | number of bytes to read. |
Definition at line 58 of file NRF24L01P.cpp.
|
inlineprotected |
Read register value. Issue R_REGISTER command with given register and read value.
[in] | reg | register address. |
Definition at line 547 of file NRF24L01P.hh.
|
inlineprotected |
Read register values. Issue R_REGISTER command with given register and write given buffer.
[in] | reg | register address. |
[in] | buf | buffer for read data. |
[in] | size | number of bytes to read. |
Definition at line 559 of file NRF24L01P.hh.
|
inlineprotected |
Read FIFO status. Issue FIFO_STATUS command to read status.
Definition at line 639 of file NRF24L01P.hh.
|
inlineprotected |
Read transmission status. Issue OBSERVE_TX command to read status.
Definition at line 649 of file NRF24L01P.hh.
|
protected |
Read status. Issue NOP command to read status.
Definition at line 101 of file NRF24L01P.cpp.
|
protected |
Set receive mode.
Definition at line 129 of file NRF24L01P.cpp.
|
virtual |
Receive message and store into given buffer with given maximum size. The source network address is returned in the parameter src. Returns error code(-2) if no message is available and/or a timeout occured. Returns error code(-1) if the buffer size if to small for incoming message or if the receiver fifo has overflowed. Otherwise the actual number of received bytes is returned
[out] | src | source network address. |
[out] | port | device port (or message type). |
[in] | buf | buffer to store incoming message. |
[in] | count | maximum number of bytes to receive. |
[in] | ms | maximum time out period. |
Implements Wireless::Driver.
Definition at line 292 of file NRF24L01P.cpp.
|
inline |
Return number of retransmissions.
Definition at line 208 of file NRF24L01P.hh.
|
inlinevirtualinherited |
Return true(1) if there is room to send on the device otherwise false(0).
Definition at line 176 of file Wireless.hh.
|
virtual |
Send message in given null terminated io vector. Returns number of bytes sent. Returns error code(-1) if number of bytes is greater than PAYLOAD_MAX. Return error code(-2) if fails to set transmit mode.
[in] | dest | destination network address. |
[in] | port | device port (or message type). |
[in] | vec | null termianted io vector. |
Implements Wireless::Driver.
Definition at line 211 of file NRF24L01P.cpp.
|
virtual |
Send message in given buffer, with given number of bytes. Returns number of bytes sent. Returns error code(-1) if number of bytes is greater than PAYLOAD_MAX. Return error code(-2) if fails to set transmit mode. Note that port numbers (128 and higher are reserved for system protocols).
[in] | dest | destination network address. |
[in] | port | device port (or message type). |
[in] | buf | buffer to transmit. |
[in] | len | number of bytes in buffer. |
Reimplemented from Wireless::Driver.
Definition at line 270 of file NRF24L01P.cpp.
|
inherited |
|
inlineinherited |
void NRF24L01P::standby | ( | ) |
Set standby mode.
Definition at line 161 of file NRF24L01P.cpp.
|
inline |
Return number of transmitted messages.
Definition at line 199 of file NRF24L01P.hh.
|
protected |
Set transmit mode and given destination device address.
Definition at line 142 of file NRF24L01P.cpp.
|
inlinevirtualinherited |
Set device in wakeup on radio mode.
Reimplemented in CC1101, and RFM69.
Definition at line 158 of file Wireless.hh.
|
protected |
|
protected |
Write command and value.
[in] | cmd | command. |
[in] | data | new setting. |
Definition at line 79 of file NRF24L01P.cpp.
|
protected |
Write command and values from given buffer.
[in] | cmd | command. |
[in] | buf | buffer with data to write. |
[in] | size | number of bytes to write. |
Definition at line 90 of file NRF24L01P.cpp.
|
inlineprotected |
Write command and value. Issue W_REGISTER command with register and write data.
[in] | reg | register address. |
[in] | data | new setting. |
Definition at line 571 of file NRF24L01P.hh.
|
inlineprotected |
Write command and values. Issue W_REGISTER command with register and write data from given buffer.
[in] | reg | register address. |
[in] | buf | buffer with data to write. |
[in] | size | number of bytes to write. |
Definition at line 584 of file NRF24L01P.hh.
Output operator for status field print out.
[in] | outs | output stream. |
[in] | status | value to print. |
Definition at line 338 of file NRF24L01P.cpp.
|
friend |
Output operator for transmitter queue status field print out.
[in] | outs | output stream. |
[in] | status | value to print. |
Definition at line 355 of file NRF24L01P.cpp.
|
friend |
Output operator for observe statistics field print out.
[in] | outs | output stream. |
[in] | observe | value to print. |
Definition at line 348 of file NRF24L01P.cpp.
|
staticinherited |
Broadcast device address.
Definition at line 58 of file Wireless.hh.
|
static |
Maximum size of payload on device.
Definition at line 61 of file NRF24L01P.hh.
|
protectedinherited |
Current network and device address.
Definition at line 299 of file Wireless.hh.
|
protectedinherited |
Message available. May be set by ISR.
Definition at line 300 of file Wireless.hh.
|
protected |
Chip enable activity RX/TX select pin.
Definition at line 620 of file NRF24L01P.hh.
|
protectedinherited |
Current channel (device dependent.
Definition at line 298 of file Wireless.hh.
|
protectedinherited |
|
protectedinherited |
Latest message destination device address.
Definition at line 301 of file Wireless.hh.
|
protected |
Dropped messages.
Definition at line 627 of file NRF24L01P.hh.
|
protected |
Chip interrupt pin and handler.
Definition at line 621 of file NRF24L01P.hh.
|
protectedinherited |
|
protectedinherited |
|
protected |
Retransmittion count.
Definition at line 626 of file NRF24L01P.hh.
|
protectedinherited |
|
protectedinherited |
|
protected |
Transceiver state.
Definition at line 623 of file NRF24L01P.hh.
|
protected |
Latest status.
Definition at line 622 of file NRF24L01P.hh.
|
protected |
Send count.
Definition at line 625 of file NRF24L01P.hh.
|
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 67 of file NRF24L01P.hh.
|
staticprotected |
Definition at line 594 of file NRF24L01P.hh.
|
staticprotected |
Timing information (ch. 6.1.7, tab. 16, pp. 24).
Definition at line 592 of file NRF24L01P.hh.
|
staticprotected |
Definition at line 593 of file NRF24L01P.hh.