NAME
Device::Chip::nRF24L01P - chip driver for a nRF24L01+
DESCRIPTION
This Device::Chip subclass provides specific communication to a Nordic
Semiconductor nRF24L01+ chip attached to a computer via an SPI adapter.
The reader is presumed to be familiar with the general operation of
this chip; the documentation here will not attempt to explain or define
chip-specific concepts or features, only the use of this module to
access them.
MOUNT PARAMETERS
ce
The name of the GPIO line on the adapter that is connected to the Chip
Enable (CE) pin. This module defaults to using the AUX line on a Bus
Pirate, or D4 on an FTDI FT232H; for other adapter types the parameter
will have to be supplied.
METHODS
The following methods documented in an await expression return Future
instances.
clear_caches
$nrf->clear_caches
The chip object stores a cache of the register values it last read or
wrote, so it can optimise updates of configuration. This method clears
these caches, ensuring a fresh SPI transfer next time the register
needs to be read.
This should not normally be necessary, other than for debugging.
latest_status
$status = $nrf->latest_status
Returns the latest cached copy of the status register from the most
recent SPI interaction. As this method does not perform any IO, it
returns its result immediately rather than via a Future.
Returns a HASH reference containing the following boolean fields
RX_DR TX_DS MAX_RT TX_FULL
Also returned is a field called RX_P_NO, which is either a pipe number
(0 to 5) or undef.
reset_interrupt
await $nrf->reset_interrupt;
Clears the interrupt flags in the STATUS register.
read_status
$status = await $nrf->read_status;
Reads and returns the current content of the status register as a HASH
reference as per latest_status.
read_config
$config = await $nrf->read_config;
change_config
await $nrf->change_config( %config );
Reads or writes the chip-wide configuration. This is an amalgamation of
all the non-pipe-specific configuration registers; CONFIG, SETUP_AW,
SETUP_RETR, RF_CH, RF_SETUP, TX_ADDR and FEATURE.
When reading, the fields are returned in a HASH reference whose names
are the original bitfield names found in the Nordic Semiconductor data
sheet. When writing, these fields are accepted as named parameters to
the change_config method directly.
Some of the fields have special processing for convenience. They are:
* CRCO
Gives the CRC length in bytes, as either 1 or 2.
* AW
Gives the full address width in bytes, between 3 and 5.
* ARD
Gives the auto retransmit delay in microseconds directly; a multiple
of 250 between 250 and 4000.
* RF_DR
Gives the RF data rate in bytes/sec; omits the RF_DR_LOW and
RF_DR_HIGH fields; as 250000, 1000000 or 2000000
* RF_PWR
Gives the RF output power in dBm directly, as -18, -12, -6 or 0.
* TX_ADDR
Gives the PTX address as a string of 5 capital hexadecimal encoded
octets, separated by colons.
Whenever the config is read it is cached within the $chip instance.
Whenever it is written, any missing fields in the passed configuration
are pre-filled by the cached config, and only those registers that need
writing will be written.
read_rx_config
$config = await $nrf->read_rx_config( $pipeno );
change_rx_config
await $nrf->change_rx_config( $pipeno, %config );
Reads or writes the per-pipe RX configuration. This is composed of the
per-pipe bits of the EN_AA and EN_RXADDR registers and its RX_ADDR_Pn
register.
Addresses are given as a string of 5 octets in capitalised hexadecimal
notation, separated by colons.
When reading an address from pipes 2 to 5, the address of pipe 1 is
used to build a complete address string to return. When writing and
address to these pipes, all but the final byte is ignored.
observe_tx_counts
$counts = await $nrf->observe_tx_counts;
Reads the OBSERVE_TX register and returns the two counts from it.
rpd
$rpd = await $nrf->rpd;
Reads the RPD register
fifo_status
$status = await $nrf->fifo_status;
Reads the FIFO_STATUS register and returns the five bit fields from it.
pwr_up
await $nrf->pwr_up( $pwr );
A convenient shortcut to setting the PWR_UP configuration bit.
chip_enable
await $nrf->chip_enable( $ce );
Controls the Chip Enable (CE) pin of the chip.
read_rx_payload_width
$len = await $nrf->read_rx_payload_width;
Returns the width of the most recently received payload, when in DPL
mode. Remember that DPL needs to be enabled (using EN_DPL) on both the
transmitter and receiver before this will work.
read_rx_payload
$data = await $nrf->read_rx_payload( $len );
Reads the most recently received RX FIFO payload buffer.
write_tx_payload
await $nrf->write_tx_payload( $data, %opts );
Writes the next TX FIFO payload buffer. Takes the following options:
no_ack => BOOL
If true, uses the W_TX_PAYLOAD_NO_ACK command, requesting that this
payload does not requre auto-ACK.
flush_rx_fifo
await $nrf->flush_rx_fifo;
flush_tx_fifo
await $nrf->flush_tx_fifo;
Flush the RX or TX FIFOs, discarding all their contents.
AUTHOR
Paul Evans <
[email protected]>