Skip to content

Commit 7bf0b12

Browse files
committed
lower default baudrate to 1MHz - may have been causing hangs on read from FIFO - reduce _BUFFER - only needed for register access - cleanup rececive
1 parent a5e3432 commit 7bf0b12

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

adafruit_rfm9x.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class RFM9x:
266266
# at least as large as the FIFO on the chip (256 bytes)! Keep this on the
267267
# class level to ensure only one copy ever exists (with the trade-off that
268268
# this is NOT re-entrant or thread safe code by design).
269-
_BUFFER = bytearray(256)
269+
_BUFFER = bytearray(10)
270270

271271
class _RegisterBits:
272272
# Class to simplify access to the many configuration bits avaialable
@@ -334,7 +334,7 @@ def __set__(self, obj, val):
334334
rx_done = _RegisterBits(_RH_RF95_REG_12_IRQ_FLAGS, offset=6, bits=1)
335335

336336
def __init__(self, spi, cs, reset, frequency, *, preamble_length=8,
337-
high_power=True, baudrate=10000000):
337+
high_power=True, baudrate=1000000):
338338
self.high_power = high_power
339339
# Device support SPI mode 0 (polarity & phase = 0) up to a max of 10mhz.
340340
self._device = spi_device.SPIDevice(spi, cs, baudrate=baudrate,
@@ -532,7 +532,7 @@ def rssi(self):
532532
# Remember in LoRa mode the payload register changes function to RSSI!
533533
return self._read_u8(_RH_RF95_REG_1A_PKT_RSSI_VALUE) - 137
534534

535-
def send(self, data, timeout_s = 1.):
535+
def send(self, data, timeout_s=1.):
536536
"""Send a string of data using the transmitter. You can only send 252
537537
bytes at a time (limited by chip's FIFO size and appended headers). Note
538538
this appends a 4 byte header to be compatible with the RadioHead library.
@@ -605,12 +605,11 @@ def receive(self, timeout_s=0.5, keep_listening=True):
605605
# Reset the fifo read ptr to the beginning of the packet.
606606
current_addr = self._read_u8(_RH_RF95_REG_10_FIFO_RX_CURRENT_ADDR)
607607
self._write_u8(_RH_RF95_REG_0D_FIFO_ADDR_PTR, current_addr)
608-
# Read the first 4 bytes to grab the header.
609-
self._read_into(_RH_RF95_REG_00_FIFO, self._BUFFER, length=4)
610-
length -= 4
611-
# Next read the remaining data into a result packet buffer.
612608
packet = bytearray(length)
609+
# Read the packet.
613610
self._read_into(_RH_RF95_REG_00_FIFO, packet)
611+
# strip off the header
612+
packet = packet[4:]
614613
# Listen again if necessary and return the result packet.
615614
if keep_listening:
616615
self.listen()

adafruit_rfm9x.pyx renamed to adafruit_rfm9x.py.save

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,11 @@ class RFM9x:
606606
current_addr = self._read_u8(_RH_RF95_REG_10_FIFO_RX_CURRENT_ADDR)
607607
self._write_u8(_RH_RF95_REG_0D_FIFO_ADDR_PTR, current_addr)
608608
# Read the first 4 bytes to grab the header.
609-
self._read_into(_RH_RF95_REG_00_FIFO, self._BUFFER)
610-
#length -= 4
609+
self._read_into(_RH_RF95_REG_00_FIFO, self._BUFFER, length=4)
610+
length -= 4
611611
# Next read the remaining data into a result packet buffer.
612-
packet = self._BUFFER[0:length-1]
612+
packet = bytearray(length)
613+
self._read_into(_RH_RF95_REG_00_FIFO, packet)
613614
# Listen again if necessary and return the result packet.
614615
if keep_listening:
615616
self.listen()

0 commit comments

Comments
 (0)