Ke Ao Teensy Flight Software
The software on the Teensy in the Ke Ao cubesat.
Loading...
Searching...
No Matches
Artemis::Devices::RFM23 Class Reference

The satellite's RFM23 radio. More...

#include <rfm23.h>

Classes

struct  rfm23_config
 The RFM23 configuration structure. More...
 

Public Member Functions

 RFM23 (uint8_t slaveSelectPin, uint8_t interruptPin, RHGenericSPI &spi=hardware_spi1)
 Construct a new RFM23::RFM23 object.
 
int32_t reset ()
 Resets the RFM23 radio.
 
int32_t init (rfm23_config cfg, Threads::Mutex *mtx)
 Initialization of the RFM23 radio.
 
int32_t send (PacketComm &packet)
 Transmit a packet using the RFM23 radio.
 
int32_t recv (PacketComm &packet, uint16_t timeout)
 Receive a packet using the RFM23 radio.
 
int32_t set_tx_power (uint8_t power)
 Sets the transmit power of the RFM23 radio.
 
int32_t get_tsen ()
 Gets the RFM23's temperature.
 
int32_t read_rssi ()
 Gets the Received Signal Strength Indicator (RSSI).
 

Detailed Description

The satellite's RFM23 radio.

Constructor & Destructor Documentation

◆ RFM23()

Artemis::Devices::RFM23::RFM23 ( uint8_t  slaveSelectPin,
uint8_t  interruptPin,
RHGenericSPI &  spi = hardware_spi1 
)

Construct a new RFM23::RFM23 object.

Parameters
slaveSelectPinThe chip/slave select pin connecting the Teensy and RFM23 radio.
interruptPinThe interrupt pin connecting the Teensy and RFM23 radio.
spiThe SPI connection connecting the Teensy and RFM23 radio.

This constructor passes the external parameters to the internal RFM23 object stored in the RFM23 class.

Member Function Documentation

◆ get_tsen()

int32_t Artemis::Devices::RFM23::get_tsen ( )

Gets the RFM23's temperature.

Returns
int32_t The temperature of the RFM23's chip.

Polls the RFM23's built-in temperature sensor.

Todo:
What is returned? Is it in Celcius? The temperature sensor can be configured and calibrated.

◆ init()

int32_t Artemis::Devices::RFM23::init ( rfm23_config  cfg,
Threads::Mutex *  mtx 
)

Initialization of the RFM23 radio.

Parameters
cfgA rfm23_config struct, containing the configuration settings for the radio.
mtxThe mutex used to lock the SPI interface for the RFM23 channel.
Returns
int32_t Returns 0 if successful, -1 if unsuccessful.

The passed-in parameters are copied over to the internal private variables in the RFM23 class.

The SPI interface is locked for the exclusive use by the RFM23 channel. The SPI1 interface is then configured to use the pins defined in the passed-in (now local) configuration struct.

The transmit and receive enable pins are set as digital output pins.

The internal RFM23 class is initialized using the RadioHead initialization code. If, after 10 seconds, initialization does not complete, print an error message to the Teensy's serial console and return -1.

Configure the internal RFM23 class with the configuration struct passed in earlier.

Set the RFM23's modulation mode. This is hardcoded in the initialization code. These are defined as RadioHead macros. Some, but not all, possible options are:

  • FSK_Rb125Fd125: Highest FSK data rate (125kbs)
  • FSK_Rb2Fd5: Lowest FSK data rate (2kbs)
  • GFSK_Rb125Fd125: Highest GFSK data rate (125kbs)
  • GFSK_Rb2Fd5: Lowest GFSK data rate (2kbs)
  • FSK_Rb_512Fd2_5: Original FSK test modulation (0.512kbs)

See the RadioHead documentation on the ModemConfigChoice enum in the RH_RF22 class (https://www.airspayce.com/mikem/arduino/RadioHead/classRH__RF22.html) for all pre-defined modulation options.

Todo:
set this as part of the config? Does the setModemConfig() call need more time, and need timeout checking?

Print a success message to the Teensy's serial console, and put the RFM23 into sleep mode.

Todo:
clean up this code to match RFM98.

◆ read_rssi()

int32_t Artemis::Devices::RFM23::read_rssi ( )

Gets the Received Signal Strength Indicator (RSSI).

Returns
int32_t The RSSI value of the last received packet.

◆ recv()

int32_t Artemis::Devices::RFM23::recv ( PacketComm &  packet,
uint16_t  timeout 
)

Receive a packet using the RFM23 radio.

Parameters
packetA pointer to the PacketComm packet that will hold the receieved data.
timeoutThe maximum time to wait for a packet to be received, in milliseconds.
Returns
int32_t If successful, the size of the received packet. If unsuccessful, returns -1.

The RFM23 is put into receive state by setting the transmit pin low and the receive pin high.

Todo:
This is reversed. Is this a bug or is the documentation incorrect? The datasheet for the RFM22B states to set the TX_ANT pin low and RX_ANT pin high to receive. https://www.sparkfun.com/datasheets/Wireless/General/RFM22B.pdf

The SPI interface is locked for the exclusive use by the RFM23 channel. If a packet is received within the specified timeout, it is copied to the PacketComm packet. The packet is then unwrapped into a header and payload. The radio is then returned to idle mode.

◆ reset()

int32_t Artemis::Devices::RFM23::reset ( )

Resets the RFM23 radio.

Returns
int32_t Always returns 0.

The SPI interface is locked for the exclusive use by the RFM23 channel. The RadioHead reset function is called by this wrapper function.

◆ send()

int32_t Artemis::Devices::RFM23::send ( PacketComm &  packet)

Transmit a packet using the RFM23 radio.

Parameters
packetA pointer to the PacketComm packet to be transmitted.
Returns
int32_t int32_t Returns 0 if successful, -1 if unsuccessful.

The RFM23 is put into transmit state by setting the transmit pin high and the receive pin low.

Todo:
This is reversed. Is this a bug or is the documentation incorrect? The datasheet for the RFM22B states to set the TX_ANT pin high and RX_ANT pin low to transmit. https://www.sparkfun.com/datasheets/Wireless/General/RFM22B.pdf

The header and payload of the packet are merged into one.

The SPI interface is locked for the exclusive use by the RFM23 channel. The packet is then sent using the RadioHead library call. The RFM23 is then put into sleep mode.

◆ set_tx_power()

int32_t Artemis::Devices::RFM23::set_tx_power ( uint8_t  power)

Sets the transmit power of the RFM23 radio.

Parameters
powerThe desired output power (in dBm?)
Returns
int32_t Always returns 0.
Todo:
Transmit power for the RFM23 is not set directly as an integer, but rather as RadioHead macros (direct hex values). This function is not referenced or used anywhere. Delete as redundant?

The transmit power is limited to values between +20dBm and +1dBm. It is then written to the internal RFM23 configuration.


The documentation for this class was generated from the following files: