Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Binary file not shown.
Binary file not shown.
3 changes: 1 addition & 2 deletions fsk_radio_range_test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def set_param_from_input_range(param, prompt_str, choice_range, allow_default=Fa
CS.switch_to_output(value=True)
RESET.switch_to_output(value=True)

raise ValueError("Feather: untested")
print(f"{bold}{green}Feather{normal} selected")
else: # board_str == "r"
# raspberry pi
Expand Down Expand Up @@ -155,7 +154,7 @@ def set_param_from_input_range(param, prompt_str, choice_range, allow_default=Fa
rfm9x.rx_bandwidth = 50.0
timeout = 30
rfm9x.preamble_length = 16
rfm9x.ack_wait = 10
rfm9x.ack_wait = 1.0

if param_str == "y":
rfm9x.frequency_mhz = set_param_from_input_range(rfm9x.frequency_mhz, f"Frequency (currently {rfm9x.frequency_mhz} MHz)",
Expand Down
75 changes: 67 additions & 8 deletions radio-utils/lib/adafruit_rfm9x.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RFM9x.git"

# Internal constants:
# Register names (FSK Mode even though we use LoRa instead, from table 85)
# Register names from table 85 of the HOPERF RF96/97/98 datasheet

# Shared registers
_RH_RF95_REG_00_FIFO = const(0x00)
_RH_RF95_REG_01_OP_MODE = const(0x01)
_RH_RF95_REG_06_FRF_MSB = const(0x06)
Expand All @@ -40,6 +42,66 @@
_RH_RF95_REG_0A_PA_RAMP = const(0x0A)
_RH_RF95_REG_0B_OCP = const(0x0B)
_RH_RF95_REG_0C_LNA = const(0x0C)

_RH_RF95_REG_40_DIO_MAPPING1 = const(0x40)
_RH_RF95_REG_41_DIO_MAPPING2 = const(0x41)
_RH_RF95_REG_42_VERSION = const(0x42)

# FSK / OOK registers
_BITRATE_MSB = const(0x02)
_BITRATE_LSB = const(0x03)
_FDEV_MSB = const(0x04)
_FDEB_LSB = const(0x05)
_RX_CONFIG = const(0x0D)
_RSSI_CONFIG = const(0x0E)
_RSSI_COLLISION = const(0x0F)
_RSSI_THRESH = const(0x10)
_RSSI_VALUE = const(0x11)
_RX_BW = const(0x12)
_AFC_BW = const(0x13)
_OOK_PEAK = const(0x14)
_OOK_FIX = const(0x15)
_OOK_AVG = const(0x16)
_AFC_FEI = const(0x1A)
_AFC_MSB = const(0x1B)
_AFC_LSB = const(0x1C)
_FEIL_MSB = const(0x1D)
_FEIL_LSB = const(0x1E)
_PREAMBLE_DETECT = const(0x1F)
_RX_TIMEOUT1 = const(0x20)
_RX_TIMEOUT2 = const(0x21)
_RX_TIMEOUT3 = const(0x22)
_RX_DELAY = const(0x23)
_OSC = const(0x24)
_PREAMBLE_MSB = const(0x25)
_PREAMBLE_LSB = const(0x26)
_SYNC_CONFIG = const(0x27)
_SYNC_VALUE1 = const(0x28)
_SYNC_VALUE2 = const(0x29)
_SYNC_VALUE3 = const(0x2a)
_SYNC_VALUE4 = const(0x2b)
_SYNC_VALUE5 = const(0x2c)
_SYNC_VALUE6 = const(0x2d)
_SYNC_VALUE7 = const(0x2e)
_SYNC_VALUE8 = const(0x2f)
_PACKET_CONFIG1 = const(0x30)
_PACKET_CONFIG2 = const(0x31)
_PAYLOAD_LENGTH = const(0x32)
_NODE_ADRS = const(0x33)
_BROADCAST_ADRS = const(0x34)
_FIFO_THRESH = const(0x35)
_SEQ_CONFIG1 = const(0x36)
_SEQ_CONFIG2 = const(0x37)
_TIMER_RESOL = const(0x38)
_TIMER_1_COEF = const(0x39)
_TIMER_2_COEF = const(0x3a)
_IMAGE_CAL = const(0x3b)
_TEMP = const(0x3c)
_LOW_BAT = const(0x3d)
_IRQ_FLAGS1 = const(0x3e)
_IRQ_FLAGS2 = const(0x3f)

# LoRa TM Mode (From table in section 6.4 of the datasheet)
_RH_RF95_REG_0D_FIFO_ADDR_PTR = const(0x0D)
_RH_RF95_REG_0E_FIFO_TX_BASE_ADDR = const(0x0E)
_RH_RF95_REG_0F_FIFO_RX_BASE_ADDR = const(0x0F)
Expand All @@ -66,11 +128,9 @@
_RH_RF95_REG_24_HOP_PERIOD = const(0x24)
_RH_RF95_REG_25_FIFO_RX_BYTE_ADDR = const(0x25)
_RH_RF95_REG_26_MODEM_CONFIG3 = const(0x26)
_RH_RF95_REG_44_PLL_HOP = const(0x44)

_RH_RF95_REG_40_DIO_MAPPING1 = const(0x40)
_RH_RF95_REG_41_DIO_MAPPING2 = const(0x41)
_RH_RF95_REG_42_VERSION = const(0x42)

# TODO:
_RH_RF95_REG_4B_TCXO = const(0x4B)
_RH_RF95_REG_4D_PA_DAC = const(0x4D)
_RH_RF95_REG_5B_FORMER_TEMP = const(0x5B)
Expand Down Expand Up @@ -716,7 +776,7 @@ def send(
payload[3] = flags
payload = payload + data
# Write payload.
self._write_from(_RH_RF95_REG_00_FIFO, payload)
self._write_from(_FIFO, payload)
# Write payload and header length.
self._write_u8(_RH_RF95_REG_22_PAYLOAD_LENGTH, len(payload))
# Turn on transmit mode to send out the packet.
Expand Down Expand Up @@ -830,7 +890,6 @@ def receive(
# Enter idle mode to stop receiving other packets.
self.idle()
if not timed_out:
print("Received packet")
if self.enable_crc and self.crc_error():
self.crc_error_count += 1
else:
Expand All @@ -844,7 +903,7 @@ def receive(
self._write_u8(_RH_RF95_REG_0D_FIFO_ADDR_PTR, current_addr)
packet = bytearray(fifo_length)
# Read the packet.
self._read_into(_RH_RF95_REG_00_FIFO, packet)
self._read_into(_FIFO, packet)
# Clear interrupt.
self._write_u8(_RH_RF95_REG_12_IRQ_FLAGS, 0xFF)
if fifo_length < 5:
Expand Down