RF22 Class
- ID: rf22
- Name: ISM Band Radio Transceiver
- Other Names: RFM22B
- Category: wifi
- Manufacturer: sparkfun
- Link: https://www.sparkfun.com/products/12030
- Connection: spi
This base class provides basic functions for sending and receiving unaddressable, unreliable datagrams of arbitrary length to 255 octets per packet.
Subclasses may use this class to implement reliable, addressed datagrams and streams, mesh routers, repeaters, translators etc.
On transmission, the TO and FROM addresses default to 0x00, unless changed by a subclass. On reception the TO addressed is checked against the node address (defaults to 0x00) or the broadcast address (which is 0xff). The ID and FLAGS are set to 0, and not checked by this class. This permits use of the this base RF22 class as an unaddressable, unreliable datagram service. Subclasses are expected to change this behavior to add node address, ids, retransmission etc.
Naturally, for any 2 radios to communicate that must be configured to use the same frequency and modulation scheme.
Item Index
Methods
- RF22
- init
- reset
- spiRead
- spiWrite
- spiBurstRead
- spiBurstWrite
- statusRead
- adcRead
- temperatureRead
- wutRead
- setWutPeriod
- setFrequency
- setFHStepSize
- setFHChannel
- rssiRead
- ezmacStatusRead
- setMode
- setModeIdle
- setModeRx
- setModeTx
- mode
- setTxPower
- setModemRegisters
- setModemConfig
- available
- waitAvailable
- waitAvailableTimeout
- recv
- send
- waitPacketSent
- setPromiscuous
- headerTo
- headerFrom
- headerId
- headerFlags
- lastRssi
- setPreambleLength
- setSyncWords
Properties
- UnmodulatedCarrier
- FSK_PN9_Rb2Fd5
- FSK_Rb2Fd5
- FSK_Rb2_4Fd36
- FSK_Rb4_8Fd45
- FSK_Rb9_6Fd45
- FSK_Rb19_2Fd9_6
- FSK_Rb38_4Fd19_6
- FSK_Rb57_6Fd28_8
- FSK_Rb125Fd125
- GFSK_Rb2Fd5
- GFSK_Rb2_4Fd36
- GFSK_Rb4_8Fd45
- GFSK_Rb9_6Fd45
- GFSK_Rb19_2Fd9_6
- GFSK_Rb38_4Fd19_6
- GFSK_Rb57_6Fd28_8
- GFSK_Rb125Fd125
- OOK_Rb1_2Bw75
- OOK_Rb2_4Bw335
- OOK_Rb4_8Bw335
- OOK_Rb9_6Bw335
- OOK_Rb19_2Bw335
- OOK_Rb38_4Bw335
- OOK_Rb40Bw335
Methods
RF22
-
spiBus
-
slaveSelectPin
-
interruptPin
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 initialize the interface and the radio module
Parameters:
-
spiBus
NumberPointer to the SPI interface object to use. Default 0 or the standard Arduino hardware SPI interface
-
slaveSelectPin
Numberthe Arduino pin number of the output to use to select the RF22 before accessing it. Default is 10 or the normal SS pin for Arduino
-
interruptPin
NumberThe interrupt pin number to use. Default is 2
Returns:
init
()
Number
Initializes this instance and the radio module connected to it. The following steps are taken:
- Software reset the RF22 module
- Checks the connected RF22 module is either a RF22_DEVICE_TYPE_RX_TRX or a RF22_DEVICE_TYPE_TX
- Configures the RF22 module
- Sets the frequency to 434.0 MHz
- Sets the modem data rate to FSK_Rb2_4Fd36
Returns:
reset
()
Issues a software reset to the RF22 module. Blocks for 1ms to ensure the reset is complete.
spiRead
-
reg
Reads a single register from the RF22
Parameters:
-
reg
NumberRegister number, one of RF22_REG_*
Returns:
The value of the register
spiWrite
-
reg
-
val
Writes a single byte to the RF22
Parameters:
-
reg
NumberRegister number, one of RF22_REG_*
-
val
NumberThe value to write
spiBurstRead
-
reg
-
dest
-
len
Reads a number of consecutive registers from the RF22 using burst read mode
Parameters:
-
reg
NumberRegister number of the first register, one of RF22_REG_*
-
dest
Uint8_t *Array to write the register values to. Must be at least len bytes
-
len
NumberNumber of bytes to read
spiBurstWrite
-
reg
-
src
-
len
Write a number of consecutive registers using burst write mode
Parameters:
-
reg
NumberRegister number of the first register, one of RF22_REG_*
-
src
Const uint8_t *Array of new register values to write. Must be at least len bytes
-
len
NumberNumber of bytes to write
statusRead
()
Number
Reads and returns the device status register RF22_REG_02_DEVICE_STATUS
Returns:
The value of the device status register
adcRead
-
adcsel
-
adcref
-
adcgain
-
adcoffs
Reads a value from the on-chip analog-digital converter
Parameters:
-
adcsel
NumberSelects the ADC input to measure. One of RF22_ADCSEL_*. Defaults to the internal temperature sensor
-
adcref
NumberSpecifies the reference voltage to use. One of RF22_ADCREF_*. Defaults to the internal bandgap voltage.
-
adcgain
NumberAmplifier gain selection.
-
adcoffs
NumberAmplifier offset (0 to 15).
Returns:
The analog value. 0 to 255.
temperatureRead
-
tsrange
-
tvoffs
Reads the on-chip temperature sensor
Parameters:
-
tsrange
NumberSpecifies the temperature range to use. One of RF22_TSRANGE_*
-
tvoffs
NumberSpecifies the temperature value offset. This is actually signed value added to the measured temperature value
Returns:
The measured temperature.
wutRead
()
Number
Reads the wakeup timer value in registers RF22_REG_17_WAKEUP_TIMER_VALUE1 and RF22_REG_18_WAKEUP_TIMER_VALUE2
Returns:
The wakeup timer value
setWutPeriod
-
wtm
-
wtr
-
wtd
Sets the wakeup timer period registers RF22_REG_14_WAKEUP_TIMER_PERIOD1, RF22_REG_15_WAKEUP_TIMER_PERIOD2 and RF22_R<EG_16_WAKEUP_TIMER_PERIOD3
Parameters:
-
wtm
NumberWakeup timer mantissa value
-
wtr
NumberWakeup timer exponent R value
-
wtd
NumberWakeup timer exponent D value
setFrequency
-
center
-
afcPullInRange
Sets the transmitter and receiver center frequency
Parameters:
-
center
NumberFrequency in MHz. 240.0 to 960.0. Caution, some versions of RF22 and derivatives implemented more restricted frequency ranges.
-
afcPullInRange
NumberSets the AF Pull In Range in MHz. Defaults to 0.05MHz (50kHz). Range is 0.0 to 0.159375 for frequencies 240.0 to 480MHz, and 0.0 to 0.318750MHz for frequencies 480.0 to 960MHz,
Returns:
true if the selected frequency center + (fhch * fhs) is within range and the afcPullInRange is within range
setFHStepSize
-
fhs
Sets the frequency hopping step size.
Parameters:
-
fhs
NumberFrequency Hopping step size in 10kHz increments
Returns:
true if center + (fhch * fhs) is within limits
setFHChannel
-
fhch
Sets the frequency hopping channel. Adds fhch * fhs to center frequency
Parameters:
-
fhch
NumberThe channel number
Returns:
true if the selected frequency center + (fhch * fhs) is within range
rssiRead
()
Number
Reads and returns the current RSSI value from register RF22_REG_26_RSSI. If you want to find the RSSI of the last received message, use lastRssi() instead.
Returns:
The current RSSI value
ezmacStatusRead
()
Number
Reads and returns the current EZMAC value from register RF22_REG_31_EZMAC_STATUS
Returns:
The current EZMAC value
setMode
-
mode
Sets the parameters for the RF22 Idle mode in register RF22_REG_07_OPERATING_MODE. Idle mode is the mode the RF22 will be in when not transmitting or receiving. The default idle mode is RF22_XTON i.e. READY mode.
Parameters:
-
mode
NumberMask of mode bits, using RF22_SWRES, RF22_ENLBD, RF22_ENWT, RF22_X32KSEL, RF22_PLLON, RF22_XTON.
setModeIdle
()
If current mode is Rx or Tx changes it to Idle. If the transmitter or receiver is running, disables them.
setModeRx
()
If current mode is Tx or Idle, changes it to Rx. Starts the receiver in the RF22 .
setModeTx
()
If current mode is Rx or Idle, changes it to Rx. Starts the transmitter in the RF22 .
mode
()
Number
Returns the operating mode of the library.
Returns:
the current mode, one of RF22_MODE_*
setTxPower
-
power
Sets the transmitter power output level in register RF22_REG_6D_TX_POWER. Be a good neighbor and set the lowest power level you need. After init() , the power will be set to RF22_TXPOW_8DBM. Caution: In some countries you may only select RF22_TXPOW_17DBM if you are also using frequency hopping.
Parameters:
-
power
NumberTransmitter power level, one of RF22_TXPOW_*
setModemRegisters
-
config
Sets all the registered required to configure the data modem in the RF22 , including the data rate, bandwidths etc. You can use this to configure the modem with custom configurations if none of the canned configurations in ModemConfigChoice suit you.
Parameters:
-
config
Const ModemConfig *A ModemConfig structure containing values for the modem configuration registers.
setModemConfig
-
index
Select one of the predefined modem configurations. If you need a modem configuration not provided here, use setModemRegisters() with your own ModemConfig .
Parameters:
-
index
ModemConfigChoiceThe configuration choice.
Returns:
true if index is a valid choice.
available
()
Number
Starts the receiver and checks whether a received message is available. This can be called multiple times in a timeout loop
Returns:
true if a complete, valid message has been received and is able to be retrieved by recv()
waitAvailable
()
Starts the receiver and blocks until a valid received message is available.
waitAvailableTimeout
-
timeout
Starts the receiver and blocks until a received message is available or a timeout
Parameters:
-
timeout
NumberMaximum time to wait in milliseconds.
Returns:
true if a message is available
recv
-
buf
-
len
Turns the receiver on if it not already on. 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.
Parameters:
-
buf
Uint8_t *Location to copy the received message
-
len
Uint8_t *Pointer to available space in buf. Set to the actual number of octets copied.
Returns:
true if a valid message was copied to buf
send
-
data
-
len
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 NOT permitted.
Parameters:
-
data
Const uint8_t *Array of data to be sent
-
len
NumberNumber of bytes of data to send (> 0)
Returns:
true if the message length was valid and it was correctly queued for transmit
waitPacketSent
()
Blocks until the RF22 is not in mode RF22_MODE_TX (i.e. until the RF22 is not transmitting). This effectively waits until any previous transmit packet is finished being transmitted.
setPromiscuous
-
promiscuous
Tells the receiver to accept messages with any TO address, not just messages addressed to this node or the broadcast address
Parameters:
-
promiscuous
Numbertrue if you wish to receive messages with any TO address
headerTo
()
Number
Returns the TO header of the last received message
Returns:
The TO header
headerFrom
()
Number
Returns the FROM header of the last received message
Returns:
The FROM header
headerId
()
Number
Returns the ID header of the last received message
Returns:
The ID header
headerFlags
()
Number
Returns the FLAGS header of the last received message
Returns:
The FLAGS header
lastRssi
()
Number
Returns the RSSI (Receiver Signal Strength Indicator) of the last received message. This measurement is taken when the preamble has been received. It is a (non-linear) measure of the received signal strength.
Returns:
The RSSI
setPreambleLength
-
nibbles
Sets the length of the preamble in 4-bit nibbles. Caution: this should be set to the same value on all nodes in your network. Default is 8. Sets the message preamble length in RF22_REG_34_PREAMBLE_LENGTH
Parameters:
-
nibbles
NumberPreamble length in nibbles of 4 bits each.
setSyncWords
-
syncWords
-
len
Sets the sync words for transmit and receive in registers RF22_REG_36_SYNC_WORD3 to RF22_REG_39_SYNC_WORD0 Caution: this should be set to the same value on all nodes in your network. Default is { 0x2d, 0xd4 }
Parameters:
-
syncWords
Const uint8_t *Array of sync words
-
len
NumberNumber of sync words to set