Device::Chip::nRF24L01P - chip driver for a nRF24L01+
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.
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.
The following methods documented in an await expression return Future instances.
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.
$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.
Clears the interrupt flags in the STATUS register.
$status = await $nrf->read_status;
Reads and returns the current content of the status register as a HASH reference as per latest_status.
$config = await $nrf->read_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:
Gives the CRC length in bytes, as either 1 or 2.
Gives the full address width in bytes, between 3 and 5.
Gives the auto retransmit delay in microseconds directly; a multiple of 250 between 250 and 4000.
Gives the RF data rate in bytes/sec; omits the RF_DR_LOW and RF_DR_HIGH fields; as 250000, 1000000 or 2000000
Gives the RF output power in dBm directly, as -18, -12, -6 or 0.
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.
$config = await $nrf->read_rx_config( $pipeno );
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.
$counts = await $nrf->observe_tx_counts;
Reads the OBSERVE_TX register and returns the two counts from it.
$rpd = await $nrf->rpd;
Reads the RPD register
$status = await $nrf->fifo_status;
Reads the FIFO_STATUS register and returns the five bit fields from it.
await $nrf->pwr_up( $pwr );
A convenient shortcut to setting the PWR_UP configuration bit.
await $nrf->chip_enable( $ce );
Controls the Chip Enable (CE) pin of the chip.
$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.
$data = await $nrf->read_rx_payload( $len );
Reads the most recently received RX FIFO payload buffer.
await $nrf->write_tx_payload( $data, %opts );
Writes the next TX FIFO payload buffer. Takes the following options:
If true, uses the W_TX_PAYLOAD_NO_ACK command, requesting that this payload does not requre auto-ACK.
Flush the RX or TX FIFOs, discarding all their contents.
Paul Evans <firstname.lastname@example.org>
To install Device::Chip::nRF24L01P, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.