Device::Chip::CC1101 - chip driver for a CC1101
Device::Chip::CC1101
This Device::Chip subclass provides specific communication to a Texas Instruments CC1101 radio transceiver 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.
$chip = Device::Chip::CC1101->new( %ops )
Constructs a new Device::Chip::CC1101 instance. Takes the following optional named arguments:
fosc
Gives the XTAL oscillator frequency in Hz. This is used by the carrier_frequency to calculate the actual frequency from the chip config. A default of 26MHz applies if not supplied.
poll_interval
Interval in seconds to poll the chip status after transmitting. A default of 20msec applies if not supplied.
The following methods documented in an await expression return Future instances.
await
$value = await $chip->read_register( $addr );
Reads a single byte register and returns its numerical value.
$addr should be between 0 and 0x3D, giving the register address.
$addr
$config = await $chip->read_config;
Reads and returns the current chip configuration as a HASH reference.
HASH
The returned hash will contain keys with capitalized names representing all of the config register fields in the datasheet, from registers IOCFG2 to RCCTRL0. Values are returned either as integers, or converted enumeration names. Where documented by the datasheet, the enumeration values are capitalised. Where invented by this module from the description they are given in lowercase.
IOCFG2
RCCTRL0
The value of PATABLE is also returned, rendered as a human-readable hex string in the form
PATABLE
PATABLE => "01.23.45.67.89.AB.CD.EF",
The following values are also returned, derived from the actual register values as a convenience.
carrier_frequency => "800.000MHz", channel_spacing => "191.951kHz", deviation => "47.607kHz", data_rate => "115.1kbps",
await $chip->change_config( %changes );
Writes the configuration registers to apply the given changes. Any fields not specified will retain their current values. The value of PATABLE can also be set here. Values should be given using the same converted forms as the read_config returns.
read_config
The following additional lowercase-named keys are also provided as shortcuts.
band => STRING
A convenient shortcut to setting the FREQ and PATABLE configuration to one of the standard ISM bands. The names of these bands are
FREQ
433MHz 868MHz
mode => STRING
A convenient shortcut to setting the configuration state to one of the presets supplied with the module. The names of these presets are
GFSK-1.2kb GFSK-38.4kb GFSK-100kb MSK-250kb MSK-500kb
$state = await $chip->read_marcstate;
Reads the MARCSTATE register and returns the state name.
MARCSTATE
$status = await $chip->read_chipstatus_rx; $status = await $chip->read_chipstatus_tx;
Reads the chip status word and returns a reference to a hash containing the following:
STATE => string FIFO_BYTES_AVAILABLE => integer
$status = await $chip->read_pktstatus;
Reads the PKTSTATUS register and returns a reference to a hash containing boolean fields of the following names:
PKTSTATUS
CRC_OK CS PQT_REACHED CCA SFD GDO0 GDO2
await $chip->reset;
Command the chip to perform a software reset.
await $chip->flush_fifos;
Command the chip to flush the RX and TX FIFOs.
await $chip->start_rx;
Command the chip to enter RX mode.
await $chip->start_tx;
Command the chip to enter TX mode.
await $chip->idle;
Command the chip to enter IDLE mode.
$bytes = await $chip->read_rxfifo( $len );
Reads the given number of bytes from the RX FIFO.
await $chip->write_txfifo( $bytes );
Writes the given bytes into the TX FIFO.
$packet = await $chip->receive;
Retrieves a packet from the RX FIFO, returning a HASH reference.
data => STRING
This method automatically strips the RSSI, LQI and CRC_OK fields from the data and adds them to the returned hash if the chip is configured with APPEND_STATUS.
RSSI
LQI
CRC_OK
APPEND_STATUS
RSSI => NUM (in units of dBm) LQI => INT CRC_OK => BOOL
This method automatically handles prepending the packet length if the chip is configured in variable-length packet mode.
TODO: Note that, despite its name, this method does not currently wait for a packet to be available - the caller is responsible for calling "start_rx" and waiting for a packet to be received. This may be provided in a later version by polling chip status or using interrupts if Device::Chip makes them available.
Device::Chip
await $chip->transmit( $bytes );
Enters TX mode and sends a packet containing the given bytes.
Polling/interrupts to wait for RX packet
Support addressing modes in "transmit" and "receive"
Paul Evans <leonerd@leonerd.org.uk>
To install Device::Chip::CC1101, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::Chip::CC1101
CPAN shell
perl -MCPAN -e shell install Device::Chip::CC1101
For more information on module installation, please visit the detailed CPAN module installation guide.