upm
1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
|
API for the RF22 Transceiver Module. More...
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.
RF22 Sensor image provided by SparkFun* under CC BY 2.0.
Data Structures | |
struct | ModemConfig |
Defines register values for a set of modem configuration registers. More... | |
Public Member Functions | |
RF22 (int spiBus=0, int slaveSelectPin=10, int interruptPin=2) | |
virtual | ~RF22 () |
uint8_t | init () |
void | reset () |
uint8_t | spiRead (uint8_t reg) |
void | spiWrite (uint8_t reg, uint8_t val) |
void | spiBurstRead (uint8_t reg, uint8_t *dest, uint8_t len) |
void | spiBurstWrite (uint8_t reg, const uint8_t *src, uint8_t len) |
uint8_t | statusRead () |
uint8_t | adcRead (uint8_t adcsel=RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR, uint8_t adcref=RF22_ADCREF_BANDGAP_VOLTAGE, uint8_t adcgain=0, uint8_t adcoffs=0) |
uint8_t | temperatureRead (uint8_t tsrange=RF22_TSRANGE_M64_64C, uint8_t tvoffs=0) |
uint16_t | wutRead () |
void | setWutPeriod (uint16_t wtm, uint8_t wtr=0, uint8_t wtd=0) |
uint8_t | setFrequency (float center, float afcPullInRange=0.05) |
uint8_t | setFHStepSize (uint8_t fhs) |
uint8_t | setFHChannel (uint8_t fhch) |
uint8_t | rssiRead () |
uint8_t | ezmacStatusRead () |
void | setMode (uint8_t mode) |
void | setModeIdle () |
void | setModeRx () |
void | setModeTx () |
uint8_t | mode () |
void | setTxPower (uint8_t power) |
void | setModemRegisters (const ModemConfig *config) |
uint8_t | setModemConfig (ModemConfigChoice index) |
uint8_t | available () |
void | waitAvailable () |
bool | waitAvailableTimeout (unsigned long timeout) |
uint8_t | recv (uint8_t *buf, uint8_t *len) |
uint8_t | send (const uint8_t *data, uint8_t len) |
void | waitPacketSent () |
void | setPromiscuous (uint8_t promiscuous) |
uint8_t | headerTo () |
uint8_t | headerFrom () |
uint8_t | headerId () |
uint8_t | headerFlags () |
uint8_t | lastRssi () |
void | setPreambleLength (uint8_t nibbles) |
void | setSyncWords (const uint8_t *syncWords, uint8_t len) |
Static Public Member Functions | |
static void | printBuffer (const char *prompt, const uint8_t *buf, uint8_t len) |
Protected Member Functions | |
void | handleInterrupt () |
void | clearRxBuf () |
void | clearTxBuf () |
uint8_t | fillTxBuf (const uint8_t *data, uint8_t len) |
uint8_t | appendTxBuf (const uint8_t *data, uint8_t len) |
void | sendNextFragment () |
void | readNextFragment () |
void | resetFifos () |
void | resetRxFifo () |
void | resetTxFifo () |
virtual void | handleExternalInterrupt () |
virtual void | handleWakeupTimerInterrupt () |
void | setHeaderTo (uint8_t to) |
void | setHeaderFrom (uint8_t from) |
void | setHeaderId (uint8_t id) |
void | setHeaderFlags (uint8_t flags) |
void | startTransmit () |
void | restartTransmit () |
uint64_t | getTimestamp () |
enum ModemConfigChoice |
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 _modemConfig
RF22 | ( | int | spiBus = 0 , |
int | slaveSelectPin = 10 , |
||
int | interruptPin = 2 |
||
) |
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
[in] | spiBus | Pointer to the SPI interface object to use. Default 0 or the standard Arduino hardware SPI interface |
[in] | slaveSelectPin | the 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 |
[in] | interruptPin | The interrupt pin number to use. Default is 2 |
|
virtual |
Destructor.
uint8_t init | ( | ) |
Initializes this instance and the radio module connected to it. The following steps are taken:
void reset | ( | ) |
Issues a software reset to the RF22 module. Blocks for 1ms to ensure the reset is complete.
uint8_t spiRead | ( | uint8_t | reg | ) |
Reads a single register from the RF22
[in] | reg | Register number, one of RF22_REG_* |
void spiWrite | ( | uint8_t | reg, |
uint8_t | val | ||
) |
Writes a single byte to the RF22
[in] | reg | Register number, one of RF22_REG_* |
[in] | val | The value to write |
void spiBurstRead | ( | uint8_t | reg, |
uint8_t * | dest, | ||
uint8_t | len | ||
) |
Reads a number of consecutive registers from the RF22 using burst read mode
[in] | reg | Register number of the first register, one of RF22_REG_* |
[in] | dest | Array to write the register values to. Must be at least len bytes |
[in] | len | Number of bytes to read |
void spiBurstWrite | ( | uint8_t | reg, |
const uint8_t * | src, | ||
uint8_t | len | ||
) |
Write a number of consecutive registers using burst write mode
[in] | reg | Register number of the first register, one of RF22_REG_* |
[in] | src | Array of new register values to write. Must be at least len bytes |
[in] | len | Number of bytes to write |
uint8_t statusRead | ( | ) |
Reads and returns the device status register RF22_REG_02_DEVICE_STATUS
uint8_t adcRead | ( | uint8_t | adcsel = RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR , |
uint8_t | adcref = RF22_ADCREF_BANDGAP_VOLTAGE , |
||
uint8_t | adcgain = 0 , |
||
uint8_t | adcoffs = 0 |
||
) |
Reads a value from the on-chip analog-digital converter
[in] | adcsel | Selects the ADC input to measure. One of RF22_ADCSEL_*. Defaults to the internal temperature sensor |
[in] | adcref | Specifies the reference voltage to use. One of RF22_ADCREF_*. Defaults to the internal bandgap voltage. |
[in] | adcgain | Amplifier gain selection. |
[in] | adcoffs | Amplifier offset (0 to 15). |
uint8_t temperatureRead | ( | uint8_t | tsrange = RF22_TSRANGE_M64_64C , |
uint8_t | tvoffs = 0 |
||
) |
Reads the on-chip temperature sensor
[in] | tsrange | Specifies the temperature range to use. One of RF22_TSRANGE_* |
[in] | tvoffs | Specifies the temperature value offset. This is actually signed value added to the measured temperature value |
uint16_t wutRead | ( | ) |
Reads the wakeup timer value in registers RF22_REG_17_WAKEUP_TIMER_VALUE1 and RF22_REG_18_WAKEUP_TIMER_VALUE2
void setWutPeriod | ( | uint16_t | wtm, |
uint8_t | wtr = 0 , |
||
uint8_t | wtd = 0 |
||
) |
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
[in] | wtm | Wakeup timer mantissa value |
[in] | wtr | Wakeup timer exponent R value |
[in] | wtd | Wakeup timer exponent D value |
uint8_t setFrequency | ( | float | center, |
float | afcPullInRange = 0.05 |
||
) |
Sets the transmitter and receiver center frequency
[in] | center | Frequency in MHz. 240.0 to 960.0. Caution, some versions of RF22 and derivatives implemented more restricted frequency ranges. |
[in] | afcPullInRange | Sets 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, |
uint8_t setFHStepSize | ( | uint8_t | fhs | ) |
Sets the frequency hopping step size.
[in] | fhs | Frequency Hopping step size in 10kHz increments |
uint8_t setFHChannel | ( | uint8_t | fhch | ) |
Sets the frequency hopping channel. Adds fhch * fhs to center frequency
[in] | fhch | The channel number |
uint8_t rssiRead | ( | ) |
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.
uint8_t ezmacStatusRead | ( | ) |
Reads and returns the current EZMAC value from register RF22_REG_31_EZMAC_STATUS
void setMode | ( | uint8_t | 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.
[in] | mode | Mask of mode bits, using RF22_SWRES, RF22_ENLBD, RF22_ENWT, RF22_X32KSEL, RF22_PLLON, RF22_XTON. |
void setModeIdle | ( | ) |
If current mode is Rx or Tx changes it to Idle. If the transmitter or receiver is running, disables them.
void setModeRx | ( | ) |
If current mode is Tx or Idle, changes it to Rx. Starts the receiver in the RF22.
void setModeTx | ( | ) |
If current mode is Rx or Idle, changes it to Rx. Starts the transmitter in the RF22.
uint8_t mode | ( | ) |
Returns the operating mode of the library.
void setTxPower | ( | uint8_t | 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.
[in] | power | Transmitter power level, one of RF22_TXPOW_* |
void setModemRegisters | ( | const ModemConfig * | 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.
[in] | config | A ModemConfig structure containing values for the modem configuration registers. |
uint8_t 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. |
uint8_t available | ( | ) |
Starts the receiver and checks whether a received message is available. This can be called multiple times in a timeout loop
void waitAvailable | ( | ) |
Starts the receiver and blocks until a valid received message is available.
bool waitAvailableTimeout | ( | unsigned long | timeout | ) |
Starts the receiver and blocks until a received message is available or a timeout
[in] | timeout | Maximum time to wait in milliseconds. |
uint8_t recv | ( | uint8_t * | buf, |
uint8_t * | 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.
[in] | buf | Location to copy the received message |
[in,out] | len | Pointer to available space in buf. Set to the actual number of octets copied. |
uint8_t send | ( | const uint8_t * | data, |
uint8_t | 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.
[in] | data | Array of data to be sent |
[in] | len | Number of bytes of data to send (> 0) |
void waitPacketSent | ( | ) |
void setPromiscuous | ( | uint8_t | promiscuous | ) |
Tells the receiver to accept messages with any TO address, not just messages addressed to this node or the broadcast address
[in] | promiscuous | true if you wish to receive messages with any TO address |
uint8_t headerTo | ( | ) |
Returns the TO header of the last received message
uint8_t headerFrom | ( | ) |
Returns the FROM header of the last received message
uint8_t headerId | ( | ) |
Returns the ID header of the last received message
uint8_t headerFlags | ( | ) |
Returns the FLAGS header of the last received message
uint8_t lastRssi | ( | ) |
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.
|
static |
Prints a data buffer in HEX. For diagnostic use
[in] | prompt | string to preface the print |
[in] | buf | Location of the buffer to print |
[in] | len | Length of the buffer in octets. |
void setPreambleLength | ( | uint8_t | 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
[in] | nibbles | Preamble length in nibbles of 4 bits each. |
void setSyncWords | ( | const uint8_t * | syncWords, |
uint8_t | 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 }
[in] | syncWords | Array of sync words |
[in] | len | Number of sync words to set |
|
protected |
This is a low level function to handle the interrupts for one instance of RF22. Called automatically when interrupt pin goes low, should not need to be called by user.
|
protected |
Clears the receiver buffer. Internal use only
|
protected |
Clears the transmitter buffer Internal use only
|
protected |
Fills the transmitter buffer with the data of a message to be sent
[in] | data | Array of data bytes to be sent (1 to 255) |
[in] | len | Number of data bytes in data (> 0) |
|
protected |
Appends the transmitter buffer with the data of a message to be sent
[in] | data | Array of data bytes to be sent (0 to 255) |
[in] | len | Number of data bytes in data |
|
protected |
Internal function to load the next fragment of the current message into the transmitter FIFO Internal use only
|
protected |
Function to copy the next fragment from the receiver FIFO into the receiver buffer
|
protected |
Clears the RF22 Rx and Tx FIFOs Internal use only
|
protected |
Clears the RF22 Rx FIFO Internal use only
|
protected |
|
protectedvirtual |
This function will be called by handleInterrupt() if an RF22 external interrupt occurs. This can only happen if external interrupts are enabled in the RF22 (which they are not by default). Subclasses may override this function to get control when an RF22 external interrupt occurs.
|
protectedvirtual |
This function will be called by handleInterrupt() if an RF22 wakeup timer interrupt occurs. This can only happen if wakeup timer interrupts are enabled in the RF22 (which they are not by default). Subclasses may override this function to get control when an RF22 wakeup timer interrupt occurs.
|
protected |
Sets the TO header to be sent in all subsequent messages
[in] | to | The new TO header value |
|
protected |
Sets the FROM header to be sent in all subsequent messages
[in] | from | The new FROM header value |
|
protected |
Sets the ID header to be sent in all subsequent messages
[in] | id | The new ID header value |
|
protected |
Sets the FLAGS header to be sent in all subsequent messages
[in] | flags | The new FLAGS header value |
|
protected |
Start the transmission of the contents of the Tx buffer
|
protected |
ReStart the transmission of the contents of the Tx buffer after a transmission failure