RadioHead
|
Send and receive unaddressed, unreliable, datagrams by Texas Instruments CC110L and compatible transceivers and modules. More...
#include <RH_CC110.h>
Classes | |
struct | ModemConfig |
Defines register configuration values for a desired modulation. More... | |
Public Types | |
enum | ModemConfigChoice { GFSK_Rb1_2Fd5_2 = 0 , GFSK_Rb2_4Fd5_2 , GFSK_Rb4_8Fd25_4 , GFSK_Rb10Fd19 , GFSK_Rb38_4Fd20 , GFSK_Rb76_8Fd32 , GFSK_Rb100Fd47 , GFSK_Rb250Fd127 } |
enum | TransmitPower { TransmitPowerM30dBm = 0 , TransmitPowerM20dBm , TransmitPowerM15dBm , TransmitPowerM10dBm , TransmitPower0dBm , TransmitPower5dBm , TransmitPower7dBm , TransmitPower10dBm } |
Public Types inherited from RHGenericDriver | |
enum | RHMode { RHModeInitialising = 0 , RHModeSleep , RHModeIdle , RHModeTx , RHModeRx , RHModeCad } |
Defines different operating modes for the transport hardware. More... | |
Public Member Functions | |
RH_CC110 (uint8_t slaveSelectPin=SS, uint8_t interruptPin=2, bool is27MHz=false, RHGenericSPI &spi=hardware_spi) | |
virtual bool | init () |
bool | printRegisters () |
virtual bool | waitPacketSent () |
virtual bool | available () |
virtual bool | recv (uint8_t *buf, uint8_t *len) |
virtual bool | send (const uint8_t *data, uint8_t len) |
virtual uint8_t | maxMessageLength () |
void | setModeIdle () |
void | setModeRx () |
void | setModeTx () |
virtual bool | sleep () |
bool | setTxPower (TransmitPower power) |
void | setIs27MHz (bool is27MHz=true) |
bool | setFrequency (float centre) |
void | setModemRegisters (const ModemConfig *config) |
bool | setModemConfig (ModemConfigChoice index) |
void | setSyncWords (const uint8_t *syncWords, uint8_t len) |
void | setPaTable (uint8_t *patable, uint8_t patablesize) |
Public Member Functions inherited from RHNRFSPIDriver | |
RHNRFSPIDriver (uint8_t slaveSelectPin=SS, RHGenericSPI &spi=hardware_spi) | |
bool | init () |
uint8_t | spiCommand (uint8_t command) |
uint8_t | spiRead (uint8_t reg) |
uint8_t | spiWrite (uint8_t reg, uint8_t val) |
uint8_t | spiBurstRead (uint8_t reg, uint8_t *dest, uint8_t len) |
uint8_t | spiBurstWrite (uint8_t reg, const uint8_t *src, uint8_t len) |
void | setSlaveSelectPin (uint8_t slaveSelectPin) |
void | spiUsingInterrupt (uint8_t interruptNumber) |
Public Member Functions inherited from RHGenericDriver | |
RHGenericDriver () | |
Constructor. | |
virtual | ~RHGenericDriver () |
Generic destructor to prevent warnings when objects are dynamically allocated. | |
virtual void | waitAvailable (uint16_t polldelay=0) |
virtual bool | waitPacketSent (uint16_t timeout) |
virtual bool | waitAvailableTimeout (uint16_t timeout, uint16_t polldelay=0) |
virtual bool | waitCAD () |
void | setCADTimeout (unsigned long cad_timeout) |
virtual bool | isChannelActive () |
virtual void | setThisAddress (uint8_t thisAddress) |
virtual void | setHeaderTo (uint8_t to) |
virtual void | setHeaderFrom (uint8_t from) |
virtual void | setHeaderId (uint8_t id) |
virtual void | setHeaderFlags (uint8_t set, uint8_t clear=RH_FLAGS_APPLICATION_SPECIFIC) |
virtual void | setPromiscuous (bool promiscuous) |
virtual uint8_t | headerTo () |
virtual uint8_t | headerFrom () |
virtual uint8_t | headerId () |
virtual uint8_t | headerFlags () |
virtual int16_t | lastRssi () |
virtual RHMode | mode () |
virtual void | setMode (RHMode mode) |
Sets the operating mode of the transport. | |
virtual uint16_t | rxBad () |
virtual uint16_t | rxGood () |
virtual uint16_t | txGood () |
Protected Member Functions | |
void | handleInterrupt () |
uint8_t | spiReadRegister (uint8_t reg) |
uint8_t | spiBurstReadRegister (uint8_t reg) |
uint8_t | spiWriteRegister (uint8_t reg, uint8_t val) |
uint8_t | spiBurstWriteRegister (uint8_t reg, const uint8_t *src, uint8_t len) |
void | validateRxBuf () |
void | clearRxBuf () |
Clear our local receive buffer. | |
uint8_t | statusRead () |
void | handleOverFlows (uint8_t status) |
Protected Member Functions inherited from RHNRFSPIDriver | |
virtual void | beginTransaction () |
virtual void | endTransaction () |
Signal the end of an SPI transaction. | |
Additional Inherited Members | |
Static Public Member Functions inherited from RHGenericDriver | |
static void | printBuffer (const char *prompt, const uint8_t *buf, uint8_t len) |
Protected Attributes inherited from RHNRFSPIDriver | |
RHGenericSPI & | _spi |
Reference to the RHGenericSPI instance to use to trasnfer data with teh SPI device. | |
uint8_t | _slaveSelectPin |
The pin number of the Slave Select pin that is used to select the desired device. | |
Protected Attributes inherited from RHGenericDriver | |
volatile RHMode | _mode |
The current transport operating mode. | |
uint8_t | _thisAddress |
This node id. | |
bool | _promiscuous |
Whether the transport is in promiscuous mode. | |
volatile uint8_t | _rxHeaderTo |
TO header in the last received mesasge. | |
volatile uint8_t | _rxHeaderFrom |
FROM header in the last received mesasge. | |
volatile uint8_t | _rxHeaderId |
ID header in the last received mesasge. | |
volatile uint8_t | _rxHeaderFlags |
FLAGS header in the last received mesasge. | |
uint8_t | _txHeaderTo |
TO header to send in all messages. | |
uint8_t | _txHeaderFrom |
FROM header to send in all messages. | |
uint8_t | _txHeaderId |
ID header to send in all messages. | |
uint8_t | _txHeaderFlags |
FLAGS header to send in all messages. | |
volatile int16_t | _lastRssi |
The value of the last received RSSI value, in some transport specific units. | |
volatile uint16_t | _rxBad |
Count of the number of bad messages (eg bad checksum etc) received. | |
volatile uint16_t | _rxGood |
Count of the number of successfully transmitted messaged. | |
volatile uint16_t | _txGood |
Count of the number of bad messages (correct checksum etc) received. | |
volatile bool | _cad |
Channel activity detected. | |
unsigned int | _cad_timeout |
Channel activity timeout in ms. | |
Send and receive unaddressed, unreliable, datagrams by Texas Instruments CC110L and compatible transceivers and modules.
The TI CC110L is a low cost tranceiver chip capable of 300 to 928MHz and with a wide range of modulation types and speeds. The chip is typically provided on a module that also includes the antenna and coupling hardware and is therefore capable of a more restricted frequency range.
Supported modules include:
This base class provides basic functions for sending and receiving unaddressed, unreliable datagrams of arbitrary length to 59 octets per packet at a selected data rate and modulation type. Use one of the Manager classes to get addressing and acknowledgement reliability, routing, meshes etc.
Naturally, for any 2 radios to communicate that must be configured to use the same frequency and data rate, and with identical network addresses.
Several CC110L modules can be connected to an Arduino, permitting the construction of translators and frequency changers, etc.
Several GFSK modulation schemes are provided and may be selected by calling setModemConfig(). No FSK or OOK modulation schemes are provided though the implementor may configure the mnodem characteristics directly by calling setModemRegisters().
Implementation based on: http://www.ti.com/lit/ds/symlink/cc110l.pdf and https://www.anaren.com/air/cc110l-air-module-boosterpack-embedded-antenna-module-anaren
Modules based on the CC110L may contain a crystal oscillator with one of 2 possible frequencies: 26MHz or 27MHz. A number of radio configuration parameters (including carrier frequency and data rates) depend on the crystal oscillator frequency. The chip has no knowledge of the frequency, so it is up to the implementer to tell the driver the oscillator frequency by passing in the appropriate value of is27MHz to the constructor (default 26MHz) or by calling setIs27MHz() before calling init(). Failure to correctly set this flag will cause incorrect frequency and modulation characteristics to be used.
Caution: it is not easy to determine what the actual crystal frequency is on some modules. For example, the documentation for the Anaren BoosterPack indictes a 26MHz crystal, but measurements on the devices delivered here indicate a 27MHz crystal is actually installed. TI recommend 27MHz for
Warning: the CC110L is a 3.3V part, and exposing it to 5V on any pin will damage it. Ensure you are using a 3.3V MCU or use level shifters. We tested with Teensy 3.1.
The electrical connection between a CC110L module and the Arduino or other processor require 3.3V, the 3 x SPI pins (SCK, SDI, SDO), a Chip Select pin and an Interrupt pin. Examples below assume the Anaren BoosterPack. Caution: the pin numbering on the Anaren BoosterPack is a bit counter-intuitive: the direction of number on J1 is the reverse of J2. Check the pin numbers stenciled on the front of the board to be sure.
and use the default RH_CC110 constructor. You can use other pins by passing the appropriate arguments to the RH_CC110 constructor, depending on what your MCU supports.
For the Particle Photon:
and use the default RH_CC110 constructor. You can use other pins by passing the appropriate arguments to the RH_CC110 constructor, depending on what your MCU supports.
Several example programs are provided.
The radio is enabled at all times and switched between RX, TX and IDLE modes. When RX is enabled (by calling available() or setModeRx()) the radio will stay in RX mode until a valid CRC correct message addressed to thiis node is received, when it will transition to IDLE. When TX is enabled (by calling send()) it will stay in TX mode until the message has ben sent and waitPacketSent() is called when it wil transition to IDLE (this radio has no 'packet sent' interrupt that could be used, so polling with waitPacketSent() is required
The modulation schemes supported include the GFSK schemes provided by default in the TI SmartRF Suite. This software allows you to get the correct register values for diferent modulation schemes. All the modulation schemes prvided in the driver are based on the recommended register values given by SmartRF. Other schemes such a 2-FSK, 4-FSK and OOK are suported by the chip, but canned configurations are not provided with this driver. The implementer may choose to create their own modem configurations and pass them to setModemRegisters().
Choices for setModemConfig() for a selected subset of common modulation types, and data rates. If you need another configuration, use the register calculator. and call setModemRegisters() with your desired settings. These are indexes into MODEM_CONFIG_TABLE. We strongly recommend you use these symbolic definitions and not their integer equivalents: its possible that new values will be introduced in later versions (though we will try to avoid it). All configs use SYNC_MODE = RH_CC110_SYNC_MODE_16_16 (2 byte sync)
These power outputs are based on the suggested optimum values for multilayer inductors in the 915MHz frequency band. Per table 5-15. Caution: these enum values are indexes into PaPowerValues. Do not change one without changing the other. Use the symbolic names, not the integer values
RH_CC110::RH_CC110 | ( | uint8_t | slaveSelectPin = SS , |
uint8_t | interruptPin = 2 , |
||
bool | is27MHz = false , |
||
RHGenericSPI & | spi = hardware_spi |
||
) |
Constructor. You can have multiple instances, but each instance must have its own interrupt and slave select pin. After constructing, you must call init() to initialise the interface and the radio module. A maximum of 3 instances can co-exist on one processor, provided there are sufficient distinct interrupt lines, one for each instance.
[in] | slaveSelectPin | the Arduino pin number of the output to use to select the CC110L before accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega, D10 for Maple) |
[in] | interruptPin | The interrupt Pin number that is connected to the CC110L GDO0 interrupt line. Defaults to pin 2. Caution: You must specify an interrupt capable pin. On many Arduino boards, there are limitations as to which pins may be used as interrupts. On Leonardo pins 0, 1, 2 or 3. On Mega2560 pins 2, 3, 18, 19, 20, 21. On Due and Teensy, any digital pin. On other Arduinos pins 2 or 3. See http://arduino.cc/en/Reference/attachInterrupt for more details. On Chipkit Uno32, pins 38, 2, 7, 8, 35. On other boards, any digital pin may be used. |
[in] | is27MHz | Set to true if your CC110 is equipped with a 27MHz crystal oscillator. Defaults to false. |
[in] | spi | Pointer to the SPI interface object to use. Defaults to the standard Arduino hardware SPI interface |
|
virtual |
Tests whether a new message is available from the Driver. On most drivers, this will also put the Driver into RHModeRx mode until a message is actually received by the transport, when it will be returned to RHModeIdle and available() will return true. This can be called multiple times in a timeout loop
Implements RHGenericDriver.
References RHGenericDriver::_mode, RHGenericDriver::RHModeTx, and setModeRx().
Referenced by recv().
|
protected |
This is a low level function to handle the interrupts for one instance of RH_RF95. Called automatically by isr*() Should not need to be called by user code.
References RHGenericDriver::_lastRssi, RHGenericDriver::_mode, clearRxBuf(), RHGenericDriver::RHModeRx, setModeIdle(), RHNRFSPIDriver::spiBurstRead(), spiBurstReadRegister(), RHNRFSPIDriver::spiCommand(), spiReadRegister(), and validateRxBuf().
|
protected |
Handle the TX or RX overflow state of the given status
status | The status byte read from the last SPI command |
References clearRxBuf(), and RHNRFSPIDriver::spiCommand().
Referenced by setModeIdle(), and statusRead().
|
virtual |
Initialise the Driver transport hardware and software. Make sure the Driver is properly configured before calling init(). In particular, ensure you have called setIs27MHz(true) if your module has a 27MHz crystal oscillator. After init(), the following default characteristics are set: TxPower: TransmitPower5dBm Frequency: 915.0 Modulation: GFSK_Rb1_2Fd5_2 (GFSK, Data Rate: 1.2kBaud, Dev: 5.2kHz, RX BW 58kHz, optimised for sensitivity) Sync Words: 0xd3, 0x91
Reimplemented from RHGenericDriver.
References GFSK_Rb1_2Fd5_2, RHNRFSPIDriver::init(), setFrequency(), setModemConfig(), setSyncWords(), setTxPower(), RHNRFSPIDriver::spiCommand(), RHNRFSPIDriver::spiUsingInterrupt(), spiWriteRegister(), and TransmitPower5dBm.
|
virtual |
Returns the maximum message length available in this Driver.
Implements RHGenericDriver.
bool RH_CC110::printRegisters | ( | ) |
Prints the value of all chip registers to the Serial device if RH_HAVE_SERIAL is defined for the current platform For debugging purposes only.
References spiBurstReadRegister(), and spiReadRegister().
|
virtual |
Turns the receiver on if it not already on (after wiaint gor any currenly transmitting message to complete). If there is a valid message available, copy it to buf and return true else return false. If a message is copied, *len is set to the length (Caution, 0 length messages are permitted). You should be sure to call this function frequently enough to not miss any messages It is recommended that you call it in your main loop.
[in] | buf | Location to copy the received message |
[in,out] | len | Pointer to the number of octets available in buf. The number be reset to the actual number of octets copied. |
Implements RHGenericDriver.
References available(), and clearRxBuf().
|
virtual |
Waits until any previous transmit packet is finished being transmitted with waitPacketSent(). Then loads a message into the transmitter and starts the transmitter. Note that a message length of 0 is permitted.
[in] | data | Array of data to be sent |
[in] | len | Number of bytes of data to send |
Implements RHGenericDriver.
References RHGenericDriver::_txHeaderFlags, RHGenericDriver::_txHeaderFrom, RHGenericDriver::_txHeaderId, RHGenericDriver::_txHeaderTo, setModeIdle(), setModeTx(), spiBurstWriteRegister(), spiWriteRegister(), RHGenericDriver::waitCAD(), and waitPacketSent().
bool RH_CC110::setFrequency | ( | float | centre | ) |
Sets the transmitter and receiver centre frequency. Caution: permissable frequency bands will depend on you country and area: consult local authorities.
[in] | centre | Frequency in MHz. 300.0 to 928.0 |
References spiWriteRegister().
Referenced by init().
void RH_CC110::setIs27MHz | ( | bool | is27MHz = true | ) |
Indicates the presence of 27MHz crystal oscillator. You must indicate to the driver if your CC110L is equipped with a 27MHz crystal oscillator (26MHz is the default in the constructor). This should be called before calling init() if you have a 27MHz crystal. It can be called after calling init() but you must reset the frequency (with setFrequency()) and modulation (with setModemConfig()) afterwards.
[in] | is27MHz | Pass true if the CC110L has a 27MHz crystal (default is true). |
void RH_CC110::setModeIdle | ( | ) |
If current mode is Sleep, Rx or Tx changes it to Idle. If the transmitter or receiver is running, disables them.
References RHGenericDriver::_mode, handleOverFlows(), RHGenericDriver::RHModeIdle, and RHNRFSPIDriver::spiCommand().
Referenced by handleInterrupt(), and send().
bool RH_CC110::setModemConfig | ( | ModemConfigChoice | index | ) |
Select one of the predefined modem configurations. If you need a modem configuration not provided here, use setModemRegisters() with your own ModemConfig.
[in] | index | The configuration choice. |
References setModemRegisters().
Referenced by init().
void RH_CC110::setModemRegisters | ( | const ModemConfig * | config | ) |
Sets all the registers required to configure the data modem in the CC110, including the data rate, bandwidths etc. You cas use this to configure the modem with custom configuraitons if none of the canned configurations in ModemConfigChoice suit you.
[in] | config | A ModemConfig structure containing values for the modem configuration registers. |
References RH_CC110::ModemConfig::reg_0b, RH_CC110::ModemConfig::reg_0c, RH_CC110::ModemConfig::reg_10, RH_CC110::ModemConfig::reg_11, RH_CC110::ModemConfig::reg_12, RH_CC110::ModemConfig::reg_15, RH_CC110::ModemConfig::reg_19, RH_CC110::ModemConfig::reg_1a, RH_CC110::ModemConfig::reg_1b, RH_CC110::ModemConfig::reg_1c, RH_CC110::ModemConfig::reg_1d, RH_CC110::ModemConfig::reg_21, RH_CC110::ModemConfig::reg_22, RH_CC110::ModemConfig::reg_23, RH_CC110::ModemConfig::reg_24, RH_CC110::ModemConfig::reg_25, RH_CC110::ModemConfig::reg_26, RH_CC110::ModemConfig::reg_2c, RH_CC110::ModemConfig::reg_2d, RH_CC110::ModemConfig::reg_2e, and spiWriteRegister().
Referenced by setModemConfig().
void RH_CC110::setModeRx | ( | ) |
If current mode is Tx or Idle, changes it to Rx. Starts the receiver. The radio will stay in Rx mode until a CRC correct message addressed to this node is received, or the ode is changed to Tx, Idle or Sleep.
References RHGenericDriver::_mode, RHGenericDriver::RHModeRx, and RHNRFSPIDriver::spiCommand().
Referenced by available().
void RH_CC110::setModeTx | ( | ) |
If current mode is Rx or Idle, changes it to Tx. Starts the transmitter sending the current message.
References RHGenericDriver::_mode, RHGenericDriver::RHModeTx, and RHNRFSPIDriver::spiCommand().
Referenced by send().
void RH_CC110::setPaTable | ( | uint8_t * | patable, |
uint8_t | patablesize | ||
) |
Sets the PaTable registers directly. Ensure you use suitable PATABLE values per Tbale 5-15 or 5-16 You may need to do this to implement an OOK modulation scheme.
References spiBurstWriteRegister().
Referenced by setTxPower().
void RH_CC110::setSyncWords | ( | const uint8_t * | syncWords, |
uint8_t | len | ||
) |
Sets the sync words for transmit and receive in registers RH_CC110_REG_04_SYNC1 and RH_CC110_REG_05_SYNC0. Caution: SyncWords should be set to the same value on all nodes in your network. Nodes with different SyncWords set will never receive each others messages, so different SyncWords can be used to isolate different networks from each other. Default is { 0xd3, 0x91 }.
[in] | syncWords | Array of sync words, 2 octets long |
[in] | len | Number of sync words to set. MUST be 2. |
References spiWriteRegister().
Referenced by init().
bool RH_CC110::setTxPower | ( | TransmitPower | power | ) |
Set the Power Amplifier power setting. The PaTable settings are based on are based on the suggested optimum values for multilayer inductors in the 915MHz frequency band. Per table 5-15. If these values are not suitable, use setPaTable() directly. Caution: be a good neighbour and use the lowest power setting compatible with your application. Caution: Permissable power settings for your area may depend on frequency and modulation characteristics: consult local authorities. param[in] power One of TransmitPower enum values
References setPaTable().
Referenced by init().
|
virtual |
Sets the radio into low-power sleep mode. If successful, the transport will stay in sleep mode until woken by changing mode to idle, transmit or receive (eg by calling send(), recv(), available() etc) Caution: there is a time penalty as the radio takes a finite time to wake from sleep mode. Caution: waking up from sleep loses values from registers 0x29 through 0x2e
Reimplemented from RHGenericDriver.
References RHGenericDriver::_mode, RHGenericDriver::RHModeSleep, and RHNRFSPIDriver::spiCommand().
|
protected |
Reads a single register in burst mode. On the CC110L, some registers yield different data when read in burst mode as opposed to single byte mode.
[in] | reg | Register number, one of RH_CC110_REG (burst mode readable) |
References RHNRFSPIDriver::spiRead().
Referenced by handleInterrupt(), and printRegisters().
|
protected |
Write a number of bytes to a burst capable register
[in] | reg | Register number of the first register, one of RH_CC110L_REG_* |
[in] | src | Array of new register values to write. Must be at least len bytes |
[in] | len | Number of bytes to write |
References RHNRFSPIDriver::spiBurstWrite().
Referenced by send(), and setPaTable().
|
protected |
Reads a single register from the CC110L
[in] | reg | Register number, one of RH_CC110_REG |
References RHNRFSPIDriver::spiRead().
Referenced by handleInterrupt(), and printRegisters().
|
protected |
Writes to a single single register on the CC110L
[in] | reg | Register number, one of RH_CC110L_REG_* |
[in] | val | The value to write |
References RHNRFSPIDriver::spiWrite().
Referenced by init(), send(), setFrequency(), setModemRegisters(), and setSyncWords().
|
protected |
Reads and returns the status byte by issuing the SNOP strobe
References handleOverFlows(), and RHNRFSPIDriver::spiCommand().
Referenced by waitPacketSent().
|
protected |
Examine the receive buffer to determine whether the message is for this node Sets _rxBufValid.
References RHGenericDriver::_promiscuous, RHGenericDriver::_rxGood, RHGenericDriver::_rxHeaderFlags, RHGenericDriver::_rxHeaderFrom, RHGenericDriver::_rxHeaderId, RHGenericDriver::_rxHeaderTo, and RHGenericDriver::_thisAddress.
Referenced by handleInterrupt().
|
virtual |
Blocks until the current message (if any) has been transmitted
Reimplemented from RHGenericDriver.
References RHGenericDriver::_mode, RHGenericDriver::RHModeIdle, RHGenericDriver::RHModeTx, and statusRead().
Referenced by send().